node-share: copy on native
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/653/merge
parent
18c567bc0e
commit
89ffdc56a8
|
@ -24,7 +24,7 @@
|
||||||
:bold="false"
|
:bold="false"
|
||||||
:href="share.url"
|
:href="share.url"
|
||||||
:compact="true"
|
:compact="true"
|
||||||
@click.prevent="copy(share.url)"
|
@click.prevent="shareOrCopy(share.url)"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<LinkIcon class="avatar" :size="20" />
|
<LinkIcon class="avatar" :size="20" />
|
||||||
|
@ -141,21 +141,23 @@ export default defineComponent({
|
||||||
// If an existing share is found, just share it directly if it's
|
// If an existing share is found, just share it directly if it's
|
||||||
// not password protected. Otherwise create a new share.
|
// not password protected. Otherwise create a new share.
|
||||||
if (immediate) {
|
if (immediate) {
|
||||||
let share =
|
// create a new share if none exists
|
||||||
this.shares.find((s) => !s.hasPassword) || (this.shares.length === 0 ? await this.createLink(false) : null);
|
if (this.shares.length === 0) {
|
||||||
|
await this.createLink();
|
||||||
if (share) {
|
|
||||||
if (nativex.has()) {
|
|
||||||
nativex.shareUrl(share.url);
|
|
||||||
} else if ('share' in window.navigator) {
|
|
||||||
window.navigator.share({
|
|
||||||
title: this.filename,
|
|
||||||
url: share.url,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this.copy(share.url);
|
// find share with no password
|
||||||
|
const share = this.shares.find((s) => !s.hasPassword);
|
||||||
|
if (share) this.shareOrCopy(share.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
shareOrCopy(url: string) {
|
||||||
|
if (nativex.has()) {
|
||||||
|
nativex.shareUrl(url);
|
||||||
|
} else if ('share' in window.navigator) {
|
||||||
|
window.navigator.share({ title: this.filename, url: url });
|
||||||
|
this.copy(url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -197,7 +199,7 @@ export default defineComponent({
|
||||||
return this.t('memories', 'Read only');
|
return this.t('memories', 'Read only');
|
||||||
},
|
},
|
||||||
|
|
||||||
async createLink(copy = true): Promise<IShare> {
|
async createLink(): Promise<IShare> {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
const res = await axios.post<IShare>(API.SHARE_NODE(), {
|
const res = await axios.post<IShare>(API.SHARE_NODE(), {
|
||||||
|
@ -206,11 +208,7 @@ export default defineComponent({
|
||||||
const share = res.data;
|
const share = res.data;
|
||||||
this.shares.push(share);
|
this.shares.push(share);
|
||||||
this.refreshSidebar();
|
this.refreshSidebar();
|
||||||
|
this.shareOrCopy(share.url);
|
||||||
if (copy) {
|
|
||||||
this.copy(share.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return share;
|
return share;
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
Loading…
Reference in New Issue