diff options
Diffstat (limited to 'public/app.js')
| -rw-r--r-- | public/app.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/public/app.js b/public/app.js index 6e2b36e..993b40b 100644 --- a/public/app.js +++ b/public/app.js @@ -11,6 +11,8 @@ const toastEl = $("#toast") const progressEl = $("#progress") const progressFill = $("#progress-fill") const progressText = $("#progress-text") +const splash = $("#splash") +const startBtn = $("#start") addEventListener("error", (e) => { toast(`error: ${e.message || "script failed"}`, true) @@ -674,18 +676,50 @@ async function beginWalk() { } catch { /* ignore */ } } +let hasPhotos = false + ;(async () => { try { const r = await fetch("/api/paths") const data = await r.json() - if (data.total) await beginWalk() - else showImportState() - } catch { + hasPhotos = !!data.total + } catch { /* assume empty library */ } + if (!hasPhotos) { + splash.hidden = true showImportState() } initDirectHint() })() +const MIN_READ = 1500 +const splashShownAt = Date.now() +let splashTimer = 0 + +function launch() { + if (started) return + clearTimeout(splashTimer) + splash.classList.add("hide") + if (hasPhotos) beginWalk() + else { started = true; showImportState() } +} + +function noteActivity() { + if (started) return + const left = MIN_READ - (Date.now() - splashShownAt) + if (left <= 0) launch() + else { + clearTimeout(splashTimer) + splashTimer = setTimeout(launch, left) + } +} + +startBtn.addEventListener("click", launch) +addEventListener("pointermove", noteActivity) +addEventListener("pointerdown", noteActivity) +addEventListener("keydown", noteActivity) +addEventListener("wheel", noteActivity) +addEventListener("touchstart", noteActivity) + let toastTimer = 0 function toast(msg, isError = false) { |
