Release 1.0.2: take a file picked again, refuse a dropped folder

Chromium fires no change event when the picker returns the file its input
already holds. The page kept the old one then, though the file may have
changed on disk, which makes the old one unreadable, or another file was
dropped in between, which the input never saw. The input is now emptied as
soon as its file is taken, so every pick fires. Its title names the file
taken, the browser's own tooltip would say no file is chosen.

A dropped folder came as a file of 0 B that can't be read and failed only
once the receiver downloaded it. It is refused with a note now, the file
picked before stays.

Both are covered for Chromium, whose protocol is the only one that reaches
the real picker and a drag from the file manager.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Fable 5.2 committed 2026-11-13 13:00:35 +01:00
1 parent 1b2696b6b4
commit 3c47047ddd
4 files changed
+105 -5

No files matched your search

+24 -3
View File
@@ -242,15 +242,35 @@ async function attempt<T>(signal: AbortSignal, step: Promise<T>) {
}
}
// The name of a dropped folder, until a file takes its place.
const folder = ref('');
function take(picked: File) {
file.value = picked;
folder.value = '';
}
// The input is emptied right away: Chromium fires no change event for the file its input already
// holds, though that file may have changed on disk, or another one was dropped since, which the
// input never saw. An event without a file has nothing to take. Empty, the input's own tooltip says no
// file is chosen, so its title names the one taken.
function onPick(event: Event) {
file.value = (event.target as HTMLInputElement).files?.[0];
const input = event.target as HTMLInputElement;
const picked = input.files?.[0];
input.value = '';
if (picked) take(picked);
}
const dragging = ref(false);
// A folder comes as a file too, one that can't be read: refused here, it would fail only once the
// receiver downloads it. The file picked before stays.
function onDrop(event: DragEvent) {
dragging.value = false;
file.value = event.dataTransfer?.files[0] ?? file.value;
const dropped = event.dataTransfer?.files[0];
const entry = [...(event.dataTransfer?.items ?? [])].find((item) => item.kind === 'file')?.webkitGetAsEntry();
if (entry?.isDirectory) folder.value = entry.name;
else if (dropped) take(dropped);
}
function formatSize(bytes: number) {
@@ -432,12 +452,13 @@ document.addEventListener('visibilitychange', holdWakeLock);
@dragleave="dragging = false"
@drop.prevent="onDrop"
>
<input type="file" @change="onPick" />
<input type="file" :title="file?.name" @change="onPick" />
<template v-if="file">
<strong>{{ file.name }}</strong>
{{ formatSize(file.size) }}
</template>
<template v-else>Drop a file or click to choose</template>
<span v-if="folder" id="not-a-file" role="alert">{{ folder }} is a folder, only a single file can be sent</span>
</label>
<div v-if="side === 'send' && phase" :data-phase="phase">
<p v-if="shared !== file" id="send-file">{{ shared!.name }}</p>