node-share: await clipboard writes

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/653/merge
Varun Patil 2023-11-13 14:15:50 -08:00
parent fa644b1b70
commit 29458546b0
1 changed files with 10 additions and 6 deletions

View File

@ -62,7 +62,7 @@
import { defineComponent } from 'vue';
import axios from '@nextcloud/axios';
import { showSuccess } from '@nextcloud/dialogs';
import { showError, showSuccess } from '@nextcloud/dialogs';
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
const NcListItem = () => import('@nextcloud/vue/dist/Components/NcListItem');
@ -152,12 +152,12 @@ export default defineComponent({
}
},
shareOrCopy(url: string) {
async shareOrCopy(url: string) {
if (nativex.has()) {
nativex.shareUrl(url);
} else if ('share' in window.navigator) {
await this.copy(url);
window.navigator.share({ title: this.filename, url: url });
this.copy(url);
}
},
@ -226,9 +226,13 @@ export default defineComponent({
this.refreshSidebar();
},
copy(url: string) {
window.navigator.clipboard.writeText(url);
async copy(url: string) {
try {
await window.navigator.clipboard.writeText(url);
showSuccess(this.t('memories', 'Link copied to clipboard'));
} catch (e) {
showError(this.t('memories', 'Failed to copy link to clipboard'));
}
},
refreshSidebar() {