WIP VI improve UX [snapshot task 2]
This commit is contained in:
1 parent
a73b3075b6
commit
8665d04f2c
6 files changed
+95
-66
No files matched your search
@@ -73,9 +73,15 @@ const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||
const defaultStun = import.meta.env.VITE_STUN_URL || '';
|
||||
const settings = ref<NetworkSettingsModel>({ stunChoice: defaultStun ? 'custom' : 'pagequit', customStun: defaultStun, allowTurn: false, managedTurn: !!iceEndpoint, turnUrl: '', username: '', credential: '' });
|
||||
const managedCredentials = ref<IceOptions | null>(null);
|
||||
const canSaveToDisk = typeof window.showSaveFilePicker === 'function';
|
||||
const canStreamDownload = supportsStreamingDownload();
|
||||
const streamedDownload = ref(false);
|
||||
// Every size is received the same way: streamed to Downloads where supported, otherwise
|
||||
// through the native save picker, otherwise buffered in memory (capped) and saved on completion.
|
||||
const receiveMethod = computed(() => {
|
||||
if (!incoming.value) return null;
|
||||
if (supportsStreamingDownload()) return 'download';
|
||||
if (typeof window.showSaveFilePicker === 'function') return 'disk';
|
||||
return incoming.value.size <= MEMORY_LIMIT ? 'memory' : null;
|
||||
});
|
||||
const savedToDisk = ref(false);
|
||||
let active: Session | null = null;
|
||||
let copyTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const busy = computed(() => !['idle', 'closed', 'done', 'session-ready'].includes(step.value));
|
||||
@@ -87,10 +93,10 @@ const status = computed(() => ({
|
||||
'answer-ready': 'Send your answer back, then compare both full fingerprints.',
|
||||
verification: verified.value ? 'Waiting for the connection and your peer’s verification…' : 'Compare both full fingerprints before confirming.',
|
||||
'waiting-accept': 'Waiting for the receiver to accept the file…',
|
||||
'choose-storage': 'Choose how to receive this file.',
|
||||
'choose-storage': 'Accept or decline this file.',
|
||||
sending: 'Sending…', receiving: 'Receiving…', saving: 'Saving file…',
|
||||
'awaiting-receipt': 'Waiting for the receiver to confirm the complete file…',
|
||||
done: lastDirection.value === 'send' ? 'The receiver confirmed the complete file.' : (downloadUrl.value ? 'File received. Save it below.' : streamedDownload.value ? 'File handed to your browser. Check Downloads for the final save result.' : 'File saved to disk.'),
|
||||
done: lastDirection.value === 'send' ? 'The receiver confirmed the complete file.' : (savedToDisk.value ? 'File saved to disk.' : 'File handed to your browser. Check Downloads for the final save result.'),
|
||||
closed: props.sending
|
||||
? 'Create a new code, then ask the receiver for a new answer. Previous codes cannot reopen a closed connection.'
|
||||
: 'Ask the sender for a new code and paste it above. Previous codes cannot reopen a closed connection.',
|
||||
@@ -100,6 +106,11 @@ function revokeDownload() {
|
||||
if (downloadUrl.value) URL.revokeObjectURL(downloadUrl.value);
|
||||
downloadUrl.value = ''; downloadName.value = '';
|
||||
}
|
||||
function saveDownload() {
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadUrl.value; link.download = downloadName.value;
|
||||
document.body.append(link); link.click(); link.remove();
|
||||
}
|
||||
function dispose() {
|
||||
const old = active;
|
||||
if (old) {
|
||||
@@ -128,7 +139,7 @@ function reset(keepNetwork = false) {
|
||||
identityStatus.value = ''; pairing.value = ''; rememberPeer.value = false;
|
||||
fps.value = incoming.value = null;
|
||||
verified.value = copied.value = choosing.value = false;
|
||||
progress.value = 0; receiveProgress.value = 0; step.value = 'idle'; streamedDownload.value = false;
|
||||
progress.value = 0; receiveProgress.value = 0; step.value = 'idle'; savedToDisk.value = false;
|
||||
sendState.value = receiveState.value = null; outgoing.value = null;
|
||||
}
|
||||
function fail(session: Session, err: unknown) {
|
||||
@@ -194,7 +205,7 @@ function attach(session: Session, channel: RTCDataChannel) {
|
||||
session.diagnostics.record(`transfer ${direction} ${state}`);
|
||||
if (state === 'done') session.diagnostics.record('transfer done');
|
||||
if (direction === 'send') { sendState.value = state; outgoing.value = meta; if (state === 'waiting-accept') progress.value = 0; }
|
||||
else { receiveState.value = state; if (state === 'choose-storage' && meta.name) { incoming.value = meta; receiveProgress.value = 0; streamedDownload.value = false; } }
|
||||
else { receiveState.value = state; if (state === 'choose-storage' && meta.name) { incoming.value = meta; receiveProgress.value = 0; savedToDisk.value = false; } }
|
||||
},
|
||||
onProgress: (direction, bytes, size) => {
|
||||
if (active !== session) return;
|
||||
@@ -206,7 +217,7 @@ function attach(session: Session, channel: RTCDataChannel) {
|
||||
if (direction === 'send') progress.value = 100; else receiveProgress.value = 100;
|
||||
remember(direction, meta, 'complete');
|
||||
void session.diagnostics.capture();
|
||||
if (blob) { revokeDownload(); downloadUrl.value = URL.createObjectURL(blob); downloadName.value = meta.name; }
|
||||
if (blob) { revokeDownload(); downloadUrl.value = URL.createObjectURL(blob); downloadName.value = meta.name; saveDownload(); }
|
||||
},
|
||||
onDecline: (direction, meta) => {
|
||||
if (active !== session) return;
|
||||
@@ -357,9 +368,9 @@ function verify() {
|
||||
session.timer = setTimeout(() => { if (active === session && !session.transfer) fail(session, new Error('Connection timed out.')); }, 60000);
|
||||
session.transfer?.verify();
|
||||
}
|
||||
async function acceptFile(destination: 'disk' | 'memory' | 'download') {
|
||||
const session = active;
|
||||
if (!session?.transfer || !incoming.value || choosing.value || receiveState.value !== 'choose-storage') return;
|
||||
async function acceptFile() {
|
||||
const session = active, destination = receiveMethod.value;
|
||||
if (!session?.transfer || !incoming.value || !destination || choosing.value || receiveState.value !== 'choose-storage') return;
|
||||
choosing.value = true; error.value = '';
|
||||
let writable: FileDestination | undefined;
|
||||
try {
|
||||
@@ -374,7 +385,7 @@ async function acceptFile(destination: 'disk' | 'memory' | 'download') {
|
||||
if (active !== session) { await writable.abort(); return; }
|
||||
}
|
||||
revokeDownload();
|
||||
streamedDownload.value = destination === 'download';
|
||||
savedToDisk.value = destination === 'disk';
|
||||
session.diagnostics.record(`storage ${destination}`);
|
||||
session.transfer.accept(writable);
|
||||
} catch (err) {
|
||||
@@ -392,7 +403,7 @@ async function copy() {
|
||||
} catch { if (active === session) error.value = 'Clipboard unavailable. Select and copy the code manually.'; }
|
||||
}
|
||||
function stateLabel(state: TransferState | null) {
|
||||
return state ? ({ verification: 'Connecting', 'waiting-accept': 'Waiting for acceptance', 'choose-storage': 'Choose where to save', sending: 'Sending', receiving: 'Receiving', saving: 'Saving', 'awaiting-receipt': 'Waiting for receipt', done: 'Complete', closed: 'Cancelled' })[state] : 'Declined';
|
||||
return state ? ({ verification: 'Connecting', 'waiting-accept': 'Waiting for acceptance', 'choose-storage': 'Awaiting acceptance', sending: 'Sending', receiving: 'Receiving', saving: 'Saving', 'awaiting-receipt': 'Waiting for receipt', done: 'Complete', closed: 'Cancelled' })[state] : 'Declined';
|
||||
}
|
||||
function formatBytes(bytes: number) {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
@@ -457,16 +468,14 @@ onBeforeUnmount(() => { dispose(); revokeDownload(); clearTimeout(copyTimer); })
|
||||
<button :disabled="choosing" @click="declineFile">Decline file</button>
|
||||
<p>{{ incoming.name }} — {{ formatBytes(incoming.size) }}</p>
|
||||
<p class="status">Only accept files you expect. Encryption does not make their contents safe to open.</p>
|
||||
<button v-if="canStreamDownload" class="primary" :disabled="choosing" @click="acceptFile('download')">Receive as download ({{ formatBytes(incoming.size) }})</button>
|
||||
<p v-if="canStreamDownload" class="status">Allow the browser download and keep this page open until the transfer finishes. Check Downloads for the final save result.</p>
|
||||
<button v-if="canSaveToDisk" class="primary" :disabled="choosing" @click="acceptFile('disk')">Choose destination & receive to disk</button>
|
||||
<button :disabled="choosing || incoming.size > MEMORY_LIMIT" @click="acceptFile('memory')">Receive in memory (up to 64 MiB)</button>
|
||||
<p v-if="incoming.size > MEMORY_LIMIT && !canSaveToDisk && !canStreamDownload" class="error">This browser cannot save directly to disk. Use a browser with file-system saving support or send a smaller file.</p>
|
||||
<button v-if="receiveMethod" class="primary" :disabled="choosing" @click="acceptFile">Accept file</button>
|
||||
<p v-if="receiveMethod === 'disk'" class="status">Your browser asks where to save this file. Keep this page open until the transfer finishes.</p>
|
||||
<p v-else-if="receiveMethod" class="status">Your browser downloads this file. Allow the download and keep this page open until the transfer finishes.</p>
|
||||
<p v-else class="error">This browser cannot receive files over 64 MiB. Use a browser with streaming-download or file-system saving support, or send a smaller file.</p>
|
||||
</div>
|
||||
<p v-if="incoming && receiveState !== 'choose-storage'" class="status">Receiving: {{ incoming.name }} — {{ stateLabel(receiveState) }} ({{ receiveProgress }}%)</p>
|
||||
<div v-if="incoming" class="progress" role="progressbar" :aria-valuenow="receiveProgress" aria-valuemin="0" aria-valuemax="100" aria-label="Receiving progress"><div :style="{ width: receiveProgress + '%' }"></div></div>
|
||||
<div v-if="downloadUrl" class="file-chip"><span>{{ downloadName }}</span><a class="download" :href="downloadUrl" :download="downloadName">Save file</a></div>
|
||||
<p v-if="downloadUrl && receiveState === 'choose-storage'" class="status">Save the previous file before accepting this one. Accepting replaces its memory download.</p>
|
||||
<div v-if="downloadUrl" class="file-chip"><span>{{ downloadName }}</span><a class="download" :href="downloadUrl" :download="downloadName">Save again</a></div>
|
||||
</section>
|
||||
<p class="status" role="status">{{ status }}</p>
|
||||
<p v-if="error" class="error" role="alert">{{ error }}</p>
|
||||
|
||||
Reference in new issue
Block a user