From 1c64cfc8feb2aee5d622a50f2f4878281b9dcc05 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Thu, 9 Apr 2026 21:04:28 +0900 Subject: add download button. reoganize buttons --- src/App.svelte | 66 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 6f6ef6d..641bfa1 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -146,6 +146,38 @@ newImagePaths = updated; } + let saving = $state(false); + + async function saveToDevice() { + if (selectedFile === undefined) return; + saving = true; + try { + // Try cache first + const cached = await imageCache.get('full', selectedFile.path); + let blob: Blob; + if (cached !== undefined) { + blob = cached.blob; + } else { + const url = flashair.fileUrl(selectedFile.path); + const res = await fetch(url); + if (!res.ok) throw new Error(`${res.status} ${res.statusText}`); + blob = await res.blob(); + } + const blobUrl = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = blobUrl; + a.download = selectedFile.filename; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(blobUrl); + } catch (e) { + error = `Save failed: ${e instanceof Error ? e.message : String(e)}`; + } finally { + saving = false; + } + } + async function clearAllCache() { autoCacheService.stop(); await imageCache.clear(); @@ -206,18 +238,6 @@
- - + + + +