Ask before downloading and show transfer progress
Tracker codes now use 8 of [0-9a-zA-Z] instead of 8 digits. After both security checks the receiver sees the offered file and starts the download itself, the sender waits for it. Both sides show a progress bar of what the download manager has read. Copy buttons for the tracker code, offer and answer; the manual exchange is folded away below the tracker on both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
85ccdbfc03
commit
bacc15baaf
4 files changed
+321
-72
No files matched your search
+106
-29
@@ -10,6 +10,8 @@ import {
|
||||
settings as coreSettings,
|
||||
type Check,
|
||||
type Events,
|
||||
type Incoming,
|
||||
type ReceiveEvents,
|
||||
} from './main';
|
||||
|
||||
const SETTINGS_KEY = 'hellcon:settings';
|
||||
@@ -87,7 +89,8 @@ const check = ref<Check>();
|
||||
const confirmed = ref(false);
|
||||
const log = ref<string[]>([]);
|
||||
|
||||
const events: Events = {
|
||||
// Shared by both sides, each adds its own progress.
|
||||
const events: Omit<Events, 'progress'> = {
|
||||
log: (message) => log.value.push(`${new Date().toISOString().slice(11, 23)} ${message}`),
|
||||
check: (result) => {
|
||||
check.value = result;
|
||||
@@ -95,12 +98,47 @@ const events: Events = {
|
||||
},
|
||||
};
|
||||
|
||||
// Of the file in transfer, which on the sender isn't necessarily the one picked now. Undefined until
|
||||
// a transfer starts.
|
||||
type Progress = { read: number; size: number };
|
||||
|
||||
const sent = ref<Progress>();
|
||||
const sendEvents: Events = { ...events, progress: (read, size) => (sent.value = { read, size }) };
|
||||
|
||||
const incoming = ref<Incoming>();
|
||||
const received = ref<Progress>();
|
||||
const receiveEvents: ReceiveEvents = {
|
||||
...events,
|
||||
progress: (read, size) => (received.value = { read, size }),
|
||||
incoming: (file) => {
|
||||
incoming.value = file;
|
||||
received.value = undefined;
|
||||
},
|
||||
};
|
||||
|
||||
const percent = ({ read, size }: Progress) => (size ? Math.floor((read / size) * 100) : 100);
|
||||
|
||||
function onConfirm() {
|
||||
confirmed.value = true;
|
||||
check.value?.confirm();
|
||||
}
|
||||
|
||||
let acceptAnswer: ((answer: string) => Promise<void>) | undefined;
|
||||
// The text copied last, its button says so for a moment.
|
||||
const copied = ref('');
|
||||
let copiedTimer: number | undefined;
|
||||
|
||||
async function onCopy(text: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
return events.log('copy failed, the browser blocked the clipboard');
|
||||
}
|
||||
copied.value = text;
|
||||
clearTimeout(copiedTimer);
|
||||
copiedTimer = window.setTimeout(() => (copied.value = ''), 2000);
|
||||
}
|
||||
|
||||
let acceptAnswer:((answer: string) => Promise<void>) | undefined;
|
||||
|
||||
function onPick(event: Event) {
|
||||
file.value = (event.target as HTMLInputElement).files?.[0];
|
||||
@@ -124,7 +162,8 @@ function formatSize(bytes: number) {
|
||||
}
|
||||
|
||||
async function onCreateOffer() {
|
||||
const result = await createOffer(file.value!, events);
|
||||
sent.value = undefined;
|
||||
const result = await createOffer(file.value!, sendEvents);
|
||||
offer.value = result.offer;
|
||||
acceptAnswer = result.accept;
|
||||
}
|
||||
@@ -134,15 +173,16 @@ function onAcceptAnswer() {
|
||||
}
|
||||
|
||||
async function onCreateAnswer() {
|
||||
answer.value = await answerOffer(offerInput.value, events);
|
||||
answer.value = await answerOffer(offerInput.value, receiveEvents);
|
||||
}
|
||||
|
||||
async function onShare() {
|
||||
sendCode.value = await sendViaTracker(file.value!, events);
|
||||
sent.value = undefined;
|
||||
sendCode.value = await sendViaTracker(file.value!, sendEvents);
|
||||
}
|
||||
|
||||
function onReceive() {
|
||||
receiveViaTracker(receiveCode.value, events);
|
||||
receiveViaTracker(receiveCode.value, receiveEvents);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -189,46 +229,83 @@ function onReceive() {
|
||||
</template>
|
||||
<template v-else>Drop a file or click to choose</template>
|
||||
</label>
|
||||
|
||||
<section>
|
||||
<h3>Manual</h3>
|
||||
<button id="create-offer" :disabled="!file" @click="onCreateOffer">Create offer</button>
|
||||
<template v-if="offer">
|
||||
<label for="offer">Offer, send this to the receiver:</label>
|
||||
<textarea id="offer" readonly :value="offer"></textarea>
|
||||
<label for="answer-input">Answer from the receiver:</label>
|
||||
<textarea id="answer-input" v-model="answerInput"></textarea>
|
||||
<button id="accept-answer" @click="onAcceptAnswer">Connect</button>
|
||||
</template>
|
||||
</section>
|
||||
<p v-if="sent">
|
||||
<progress id="send-progress" max="100" :value="percent(sent)"></progress>
|
||||
{{ percent(sent) }} %
|
||||
</p>
|
||||
|
||||
<section>
|
||||
<h3>Tracker</h3>
|
||||
<button id="share" :disabled="!file || !settings.trackers.length" @click="onShare">Share via tracker</button>
|
||||
<p v-if="sendCode">Code: <output id="send-code">{{ sendCode }}</output></p>
|
||||
<template v-if="sendCode">
|
||||
<label for="send-code">Code, give this to the receiver:</label>
|
||||
<div role="group">
|
||||
<output id="send-code">{{ sendCode }}</output>
|
||||
<button id="copy-send-code" @click="onCopy(sendCode)">{{ copied === sendCode ? 'Copied' : 'Copy' }}</button>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<details id="send-manual">
|
||||
<summary>Manual</summary>
|
||||
<section>
|
||||
<button id="create-offer" :disabled="!file" @click="onCreateOffer">Create offer</button>
|
||||
<template v-if="offer">
|
||||
<label for="offer">Offer, send this to the receiver:</label>
|
||||
<textarea id="offer" readonly :value="offer"></textarea>
|
||||
<button id="copy-offer" data-copy @click="onCopy(offer)">{{ copied === offer ? 'Copied' : 'Copy' }}</button>
|
||||
<label for="answer-input">Answer from the receiver:</label>
|
||||
<textarea id="answer-input" v-model="answerInput"></textarea>
|
||||
<button id="accept-answer" @click="onAcceptAnswer">Connect</button>
|
||||
</template>
|
||||
</section>
|
||||
</details>
|
||||
</article>
|
||||
|
||||
<article>
|
||||
<h2>Receive</h2>
|
||||
|
||||
<section>
|
||||
<h3>Manual</h3>
|
||||
<textarea id="offer-input" v-model="offerInput" placeholder="Paste the offer"></textarea>
|
||||
<button id="create-answer" @click="onCreateAnswer">Create answer</button>
|
||||
<template v-if="answer">
|
||||
<label for="answer">Answer, send this back to the sender:</label>
|
||||
<textarea id="answer" readonly :value="answer"></textarea>
|
||||
<div id="incoming">
|
||||
<template v-if="incoming">
|
||||
<strong>{{ incoming.name }}</strong>
|
||||
{{ formatSize(incoming.size) }}
|
||||
<button v-if="!received" id="download" @click="incoming.download()">Download</button>
|
||||
</template>
|
||||
</section>
|
||||
<template v-else>The sender's file shows up here after the security check</template>
|
||||
</div>
|
||||
<p v-if="received">
|
||||
<progress id="receive-progress" max="100" :value="percent(received)"></progress>
|
||||
{{ percent(received) }} %
|
||||
</p>
|
||||
|
||||
<section>
|
||||
<h3>Tracker</h3>
|
||||
<label for="receive-code">Code from the sender:</label>
|
||||
<div role="group">
|
||||
<input id="receive-code" v-model="receiveCode" placeholder="Code" />
|
||||
<input
|
||||
id="receive-code"
|
||||
v-model="receiveCode"
|
||||
autocapitalize="off"
|
||||
autocomplete="off"
|
||||
autocorrect="off"
|
||||
spellcheck="false"
|
||||
/>
|
||||
<button id="receive" :disabled="!settings.trackers.length" @click="onReceive">Receive</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<details id="receive-manual">
|
||||
<summary>Manual</summary>
|
||||
<section>
|
||||
<label for="offer-input">Offer from the sender:</label>
|
||||
<textarea id="offer-input" v-model="offerInput"></textarea>
|
||||
<button id="create-answer" @click="onCreateAnswer">Create answer</button>
|
||||
<template v-if="answer">
|
||||
<label for="answer">Answer, send this back to the sender:</label>
|
||||
<textarea id="answer" readonly :value="answer"></textarea>
|
||||
<button id="copy-answer" data-copy @click="onCopy(answer)">{{ copied === answer ? 'Copied' : 'Copy' }}</button>
|
||||
</template>
|
||||
</section>
|
||||
</details>
|
||||
</article>
|
||||
|
||||
<details id="servers">
|
||||
|
||||
Reference in new issue
Block a user