Skip to content

Commit 2483d7e

Browse files
committed
Fix mobile share sheet not opening on download tap
Two iOS Safari issues prevented the share sheet from appearing: - canShare() was probed with an empty placeholder File, which reports false on iOS, so the share path was skipped and it silently fell back to a hidden download. Now test canShare against the real fetched file. - The /versions fetch before the file fetch consumed the user activation iOS requires for navigator.share(). On mobile, skip the version menu and share the primary file directly within the tap gesture.
1 parent ed33950 commit 2483d7e

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/lib/components/download/DownloadVersionPicker.svelte

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@
5454
5555
async function triggerDownload(id: string) {
5656
// On mobile, open the native share sheet so users can "Save to Photos"
57-
// instead of dumping the file into Files/Downloads. Falls back to a plain
58-
// download on desktop or when the Share API is unavailable.
59-
const canShareFiles =
60-
isMobileDevice() && navigator.canShare?.({ files: [new File([], 'test')] });
61-
if (canShareFiles) {
57+
// instead of dumping the file into Files/Downloads. canShare must be tested
58+
// against the *real* file — an empty placeholder File reports false on iOS
59+
// Safari, which would silently skip the share sheet.
60+
if (isMobileDevice()) {
6261
try {
6362
const res = await fetch(fileUrl(id));
6463
if (!res.ok) throw new Error('fetch failed');
6564
const blob = await res.blob();
6665
const name = filenameFromResponse(res) || 'download';
6766
const file = new File([blob], name, { type: blob.type });
68-
await navigator.share({ files: [file] });
69-
return;
67+
if (navigator.canShare?.({ files: [file] })) {
68+
await navigator.share({ files: [file] });
69+
return;
70+
}
7071
} catch (e: any) {
7172
if (e.name === 'AbortError') return; // user dismissed the share sheet
7273
console.warn('Share unavailable, falling back to download:', e);
@@ -112,6 +113,13 @@
112113
open = false;
113114
return;
114115
}
116+
// On mobile, share the primary file directly within this tap gesture.
117+
// Fetching the versions list first would consume the user activation that
118+
// iOS requires for navigator.share(), so we skip the version menu there.
119+
if (isMobileDevice()) {
120+
triggerDownload(downloadId);
121+
return;
122+
}
115123
open = true;
116124
loaded = false;
117125
loadVersions();

0 commit comments

Comments
 (0)