better sharing

This commit is contained in:
Klemek
2025-03-17 15:01:43 +01:00
parent 7c54cdd612
commit 7365e76d2e
3 changed files with 22 additions and 13 deletions
+4 -4
View File
@@ -10,10 +10,10 @@
## Roadmap ## Roadmap
* [ ] Clean project * [x] Clean project
* [ ] Better data upload by chunks and ensure consistancy * [x] Better data upload by chunks and ensure consistancy
* [ ] Link sharing and better workflow * [x] Link sharing and better workflow
* [ ] QRCode
* [ ] Multiple peers * [ ] Multiple peers
* [ ] QRCode
* [ ] DaisyUI redesign * [ ] DaisyUI redesign
* [ ] Multiple files * [ ] Multiple files
+1 -1
View File
@@ -35,7 +35,7 @@
<br> <br>
<template v-if="serverIsReady"> <template v-if="serverIsReady">
<input disabled :value="server.url" /> <input disabled :value="server.url" />
<input type="submit" @click.prevent="onCopy" value="Share / Copy" /> <input type="submit" @click.prevent="onShare" :value="shareText" />
<br> <br>
<br> <br>
</template> </template>
+17 -8
View File
@@ -12,9 +12,6 @@ const utils = {
}, },
}); });
}, },
copyToClipboard(str) {
navigator.clipboard.writeText(str);
},
}; };
const MESSAGE_TYPE = { const MESSAGE_TYPE = {
@@ -39,11 +36,11 @@ const app = createApp({
remoteId: null, remoteId: null,
connection: null, // TODO multiple connections connection: null, // TODO multiple connections
// TODO separate vars
isServer: true, isServer: true,
server: { server: {
url: null, url: null,
data: null, // TODO multiple files data: null, // TODO multiple files
copied: false,
}, },
client: { client: {
remoteId: null, remoteId: null,
@@ -76,6 +73,15 @@ const app = createApp({
downloadTotal() { downloadTotal() {
return this.fileSize ?? 0; return this.fileSize ?? 0;
}, },
shareText() {
if (navigator.canShare && navigator.canShare()) {
return "Share link";
}
if (this.server.copied) {
return "Copied to clipboard";
}
return "Copy link";
},
}, },
watch: {}, watch: {},
updated() { updated() {
@@ -318,13 +324,16 @@ const app = createApp({
this.client.downloadStart = new Date(); this.client.downloadStart = new Date();
this.sendClientSeek(); this.sendClientSeek();
}, },
onCopy() { onShare() {
try { if (navigator.canShare && navigator.canShare()) {
navigator.share({ navigator.share({
url: this.server.url, url: this.server.url,
title: window.title,
}) })
} catch { } else {
utils.copyToClipboard(this.server.url); navigator.clipboard.writeText(this.server.url);
this.server.copied = true;
setTimeout(() => {this.server.copied = false;}, 5000);
} }
} }
}, },