current state before improvement pass
This commit is contained in:
+100
-148
@@ -2,8 +2,7 @@
|
||||
import { onMount } from "svelte"
|
||||
import { api, formatBytes, type UpdateInfo, type UpdateDownloadProgress } from "./api"
|
||||
|
||||
type Phase = "info" | "downloading" | "ready-to-apply" | "error"
|
||||
|
||||
type Phase = "info" | "downloading" | "ready" | "error"
|
||||
let info: UpdateInfo | null = $state(null)
|
||||
let phase: Phase = $state("info")
|
||||
let progress: UpdateDownloadProgress | null = $state(null)
|
||||
@@ -11,113 +10,72 @@
|
||||
|
||||
onMount(() => {
|
||||
let unlistenInfo: (() => void) | null = null
|
||||
let unlistenProgress: (() => void) | null = null
|
||||
let unlistenProg: (() => void) | null = null
|
||||
void (async () => {
|
||||
unlistenInfo = await api.onUpdateAvailable((i) => {
|
||||
info = i
|
||||
phase = "info"
|
||||
})
|
||||
unlistenProgress = await api.onUpdateDownloadProgress((p) => {
|
||||
progress = p
|
||||
})
|
||||
if (await api.pendingUpdate()) {
|
||||
phase = "ready-to-apply"
|
||||
}
|
||||
unlistenInfo = await api.onUpdateAvailable((i) => { info = i; phase = "info" })
|
||||
unlistenProg = await api.onUpdateDownloadProgress((p) => { progress = p })
|
||||
if (await api.pendingUpdate()) phase = "ready"
|
||||
})()
|
||||
return () => {
|
||||
unlistenInfo?.()
|
||||
unlistenProgress?.()
|
||||
}
|
||||
return () => { unlistenInfo?.(); unlistenProg?.() }
|
||||
})
|
||||
|
||||
function dismiss() {
|
||||
info = null
|
||||
phase = "info"
|
||||
errMsg = null
|
||||
}
|
||||
|
||||
function viewRelease() {
|
||||
if (info) void api.openUrl(info.release_url)
|
||||
}
|
||||
function dismiss() { info = null; errMsg = null; phase = "info" }
|
||||
function viewRelease() { if (info) void api.openUrl(info.release_url) }
|
||||
|
||||
async function download() {
|
||||
if (!info?.download_url) {
|
||||
errMsg = "this release has no downloadable exe asset"
|
||||
phase = "error"
|
||||
return
|
||||
}
|
||||
phase = "downloading"
|
||||
progress = null
|
||||
errMsg = null
|
||||
try {
|
||||
await api.downloadUpdate(info.download_url)
|
||||
phase = "ready-to-apply"
|
||||
} catch (e) {
|
||||
errMsg = String(e)
|
||||
phase = "error"
|
||||
}
|
||||
if (!info?.download_url) { errMsg = "no downloadable exe in this release"; phase = "error"; return }
|
||||
phase = "downloading"; progress = null; errMsg = null
|
||||
try { await api.downloadUpdate(info.download_url); phase = "ready" }
|
||||
catch (e) { errMsg = String(e); phase = "error" }
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
try {
|
||||
await api.applyUpdate()
|
||||
} catch (e) {
|
||||
errMsg = String(e)
|
||||
phase = "error"
|
||||
}
|
||||
}
|
||||
|
||||
let bodyPreview = $derived.by(() => {
|
||||
const i = info
|
||||
if (!i) return ""
|
||||
return i.body.split("\n").slice(0, 3).join(" ").slice(0, 140)
|
||||
})
|
||||
async function apply() { try { await api.applyUpdate() } catch (e) { errMsg = String(e); phase = "error" } }
|
||||
</script>
|
||||
|
||||
{#if info || phase === "ready-to-apply"}
|
||||
<div class="banner">
|
||||
<div class="text">
|
||||
{#if phase === "ready-to-apply"}
|
||||
<strong>update ready to apply</strong>
|
||||
{#if info}
|
||||
{#if info || phase === "ready"}
|
||||
<div class="banner" role="status" aria-live="polite">
|
||||
<div class="banner-main">
|
||||
{#if phase === "ready"}
|
||||
<span class="dot" style="background:var(--recording)"></span>
|
||||
<span class="banner-text">
|
||||
<span class="banner-label">Update ready</span>
|
||||
{#if info}<span class="ver">v{info.version}</span>{/if}
|
||||
</span>
|
||||
<button class="btn" onclick={apply}>Apply</button>
|
||||
<button class="btn ghost" onclick={dismiss}>Dismiss</button>
|
||||
|
||||
{:else if phase === "downloading"}
|
||||
<span class="dot pulse"></span>
|
||||
<span class="banner-text">
|
||||
<span class="banner-label">Downloading</span>
|
||||
{#if info}<span class="ver">v{info.version}</span>{/if}
|
||||
{#if progress}
|
||||
<span class="banner-hint">
|
||||
{formatBytes(progress.downloaded)}{progress.total ? ` / ${formatBytes(progress.total)}` : ""}
|
||||
</span>
|
||||
{/if}
|
||||
</span>
|
||||
|
||||
{:else if phase === "error"}
|
||||
<span class="dot" style="background:var(--err)"></span>
|
||||
<span class="banner-text">
|
||||
<span class="banner-label">Update error</span>
|
||||
{#if errMsg}<span class="banner-hint">{errMsg}</span>{/if}
|
||||
</span>
|
||||
<button class="btn ghost" onclick={dismiss}>Dismiss</button>
|
||||
|
||||
{:else if info}
|
||||
<span class="dot pulse"></span>
|
||||
<span class="banner-text">
|
||||
<span class="banner-label">Update available</span>
|
||||
<span class="ver">v{info.version}</span>
|
||||
{/if}
|
||||
<p class="body">click apply to swap and restart, or dismiss to keep the current version.</p>
|
||||
{:else if phase === "downloading"}
|
||||
<strong>downloading update...</strong>
|
||||
{#if info}<span class="ver">v{info.version}</span>{/if}
|
||||
{#if progress}
|
||||
<p class="body">
|
||||
{formatBytes(progress.downloaded)}
|
||||
{#if progress.total} / {formatBytes(progress.total)}{/if}
|
||||
</p>
|
||||
{/if}
|
||||
{:else if phase === "error"}
|
||||
<strong>update error</strong>
|
||||
<p class="body">{errMsg}</p>
|
||||
{:else if info}
|
||||
<strong>update available</strong>
|
||||
<span class="ver">v{info.version}</span>
|
||||
<span class="from">(you have v{info.current_version})</span>
|
||||
{#if bodyPreview}
|
||||
<p class="body">{bodyPreview}{info.body.length > 140 ? "..." : ""}</p>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
<div class="actions">
|
||||
{#if phase === "ready-to-apply"}
|
||||
<button class="primary" onclick={apply}>apply now</button>
|
||||
<button onclick={dismiss}>dismiss</button>
|
||||
{:else if phase === "downloading"}
|
||||
<span class="muted">working...</span>
|
||||
{:else if phase === "error"}
|
||||
<button onclick={dismiss}>dismiss</button>
|
||||
{:else if info}
|
||||
<span class="from">v{info.current_version}</span>
|
||||
</span>
|
||||
{#if info.download_url}
|
||||
<button class="primary" onclick={download}>download</button>
|
||||
<button class="btn" onclick={download}>Download</button>
|
||||
{/if}
|
||||
<button onclick={viewRelease}>view release</button>
|
||||
<button onclick={dismiss}>dismiss</button>
|
||||
<button class="btn ghost" onclick={viewRelease}>Notes</button>
|
||||
<button class="btn ghost" onclick={dismiss}>Dismiss</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -125,66 +83,60 @@
|
||||
|
||||
<style>
|
||||
.banner {
|
||||
background: linear-gradient(180deg, #1f2e2a, #1a2522);
|
||||
border-bottom: 1px solid #4a8;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: var(--bg-2);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.banner-main {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 8px 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.text {
|
||||
flex: 1;
|
||||
min-width: 240px;
|
||||
color: #d8eee5;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.ver {
|
||||
color: #4a8;
|
||||
font-weight: 600;
|
||||
margin: 0 0.4rem;
|
||||
}
|
||||
.from {
|
||||
color: #7a8e88;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.body {
|
||||
margin: 0.3rem 0 0;
|
||||
color: #9eb3ac;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
|
||||
.dot {
|
||||
width: 6px; height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.pulse { animation: blink 2s ease-in-out infinite; }
|
||||
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }
|
||||
|
||||
.banner-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
color: var(--text-2);
|
||||
flex: 1;
|
||||
min-width: 160px;
|
||||
}
|
||||
.muted {
|
||||
color: #7a8e88;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
button {
|
||||
font: inherit;
|
||||
padding: 0.4rem 0.8rem;
|
||||
border: 1px solid #2a3a35;
|
||||
background: transparent;
|
||||
color: #d8eee5;
|
||||
|
||||
.banner-label { font-weight: 500; color: var(--text); }
|
||||
.ver { font-family: var(--mono); font-size: 11px; color: var(--accent); }
|
||||
.from { font-size: 11px; color: var(--text-3); }
|
||||
.banner-hint { font-size: 11px; color: var(--text-3); }
|
||||
|
||||
.btn {
|
||||
padding: 4px 12px;
|
||||
border-radius: var(--r-sm);
|
||||
font-family: var(--sans);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85rem;
|
||||
transition: all 80ms;
|
||||
white-space: nowrap;
|
||||
border: 1px solid transparent;
|
||||
background: var(--accent);
|
||||
color: var(--accent-text);
|
||||
}
|
||||
button:hover {
|
||||
border-color: #4a8;
|
||||
}
|
||||
button.primary {
|
||||
background: #4a8;
|
||||
border-color: #4a8;
|
||||
color: #0e1a16;
|
||||
}
|
||||
button.primary:hover {
|
||||
background: #5b9;
|
||||
border-color: #5b9;
|
||||
.btn:hover { background: var(--accent-hover); }
|
||||
.btn.ghost {
|
||||
background: transparent;
|
||||
border-color: var(--border-2);
|
||||
color: var(--text-2);
|
||||
}
|
||||
.btn.ghost:hover { border-color: var(--border-3); color: var(--text); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user