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
+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>