update banner via gitea releases

This commit is contained in:
2026-05-12 00:20:49 +03:00
parent 5a916d2ad2
commit 297f307588
5 changed files with 209 additions and 0 deletions
+3
View File
@@ -6,6 +6,7 @@
import FirstRun from "./lib/FirstRun.svelte"
import Main from "./lib/Main.svelte"
import Settings from "./lib/Settings.svelte"
import UpdateBanner from "./lib/UpdateBanner.svelte"
type View = "loading" | "bootstrap" | "first-run" | "main" | "settings"
@@ -29,6 +30,8 @@
onMount(refresh)
</script>
<UpdateBanner />
{#if view === "loading"}
<Loading />
{:else if view === "bootstrap"}
+109
View File
@@ -0,0 +1,109 @@
<script lang="ts">
import { onMount } from "svelte"
import { api, type UpdateInfo } from "./api"
let info: UpdateInfo | null = $state(null)
onMount(() => {
const unlistenPromise = api.onUpdateAvailable((i) => {
info = i
})
return () => {
unlistenPromise.then((fn) => fn())
}
})
function dismiss() {
info = null
}
function viewRelease() {
if (info) {
void api.openUrl(info.release_url)
}
}
let bodyPreview = $derived.by(() => {
const i = info
if (!i) return ""
return i.body.split("\n").slice(0, 3).join(" ").slice(0, 140)
})
</script>
{#if info}
<div class="banner">
<div class="text">
<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}
</div>
<div class="actions">
<button class="primary" onclick={viewRelease}>view release</button>
<button onclick={dismiss}>dismiss</button>
</div>
</div>
{/if}
<style>
.banner {
background: linear-gradient(180deg, #1f2e2a, #1a2522);
border-bottom: 1px solid #4a8;
padding: 0.75rem 1.25rem;
display: flex;
gap: 1rem;
align-items: center;
justify-content: space-between;
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;
flex-shrink: 0;
}
button {
font: inherit;
padding: 0.4rem 0.8rem;
border: 1px solid #2a3a35;
background: transparent;
color: #d8eee5;
cursor: pointer;
border-radius: 4px;
font-size: 0.85rem;
}
button:hover {
border-color: #4a8;
}
button.primary {
background: #4a8;
border-color: #4a8;
color: #0e1a16;
}
button.primary:hover {
background: #5b9;
border-color: #5b9;
}
</style>
+10
View File
@@ -51,6 +51,13 @@ export type DownloadProgress = {
total: number | null
}
export type UpdateInfo = {
version: string
current_version: string
release_url: string
body: string
}
export type CaptureRect = {
x: number
y: number
@@ -104,6 +111,9 @@ export const api = {
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
extractThumbnails: (fps: number) =>
invoke<string[]>("extract_thumbnails", { fps }),
openUrl: (url: string) => invoke<void>("open_url", { url }),
onUpdateAvailable: (handler: (info: UpdateInfo) => void): Promise<UnlistenFn> =>
listen<UpdateInfo>("update-available", (e) => handler(e.payload)),
}
export function formatBytes(n: number): string {