feat #14740: check for updates from the settings
Adds a "Nach Updates suchen" button to the settings' new Updates section, next to the app's own version. It runs check_for_update_now, the very same feed check the background loop uses (one implementation, shared via UpdateSchedule), so a manual check counts as an attempt for the same scheduler: success resets the 6 h interval and the failure count, a failure advances the backoff by one step, and a manual and a background check never run at the same time (serialized). An available update leaves the same state the background check does, so the main window's banner still shows it; the settings also show it inline with the existing "Installieren & neu starten" button and busy guard/hint. "None" and "error" results are shown inline (unlike the background check, which never surfaces its errors). On Linux (can_self_update) the button still asks the feed but offers no install, since Debian builds never self-update. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
onRecordingState,
|
||||
onUpdateAvailable,
|
||||
onUpdateProgress,
|
||||
updateProgressText,
|
||||
UPDATE_BUSY_HINT,
|
||||
type UpdateInfo,
|
||||
type UpdateProgress,
|
||||
} from './api'
|
||||
@@ -62,16 +64,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function megabytes(bytes: number): string {
|
||||
return (bytes / 1024 / 1024).toLocaleString('de-DE', { maximumFractionDigits: 1 }) + ' MB'
|
||||
}
|
||||
|
||||
let progressText = $derived.by(() => {
|
||||
if (!progress) return 'Update wird heruntergeladen…'
|
||||
if (progress.total === null) return `Update wird heruntergeladen… ${megabytes(progress.downloaded)}`
|
||||
if (progress.downloaded >= progress.total) return 'Update wird installiert…'
|
||||
return `Update wird heruntergeladen… ${Math.floor((progress.downloaded * 100) / progress.total)} %`
|
||||
})
|
||||
let progressText = $derived(updateProgressText(progress))
|
||||
</script>
|
||||
|
||||
{#if update}
|
||||
@@ -84,7 +77,7 @@
|
||||
Installieren & neu starten
|
||||
</button>
|
||||
{#if !update.can_install}
|
||||
<span class="hint">Nach der laufenden Aufnahme/Verarbeitung möglich</span>
|
||||
<span class="hint">{UPDATE_BUSY_HINT}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if error}
|
||||
|
||||
@@ -137,6 +137,15 @@ export interface UpdateProgress {
|
||||
total: number | null
|
||||
}
|
||||
|
||||
/** Why the install button is disabled, shown next to it as a hint. */
|
||||
export const UPDATE_BUSY_HINT = 'Nach der laufenden Aufnahme/Verarbeitung möglich'
|
||||
|
||||
/** What a check (background or manual) found. */
|
||||
export type UpdateCheckResult =
|
||||
| { status: 'none' }
|
||||
| { status: 'available'; version: string }
|
||||
| { status: 'error'; message: string }
|
||||
|
||||
export interface Levels {
|
||||
mic: number
|
||||
out: number
|
||||
@@ -185,6 +194,14 @@ export const uploadTranscript = (id: CallId) => invoke<void>('upload_transcript'
|
||||
export const getUpdate = () => invoke<UpdateInfo | null>('get_update')
|
||||
/** Resolves only on failure: on success the app restarts. */
|
||||
export const installUpdate = () => invoke<void>('install_update')
|
||||
/** This build's own version, for the settings' "Updates" section. */
|
||||
export const getAppVersion = () => invoke<string>('get_app_version')
|
||||
/** Whether this build can install an update itself (Windows only). */
|
||||
export const canSelfUpdate = () => invoke<boolean>('can_self_update')
|
||||
/** "Nach Updates suchen": runs the same check as the background loop,
|
||||
* immediately. An `available` result leaves the same state `getUpdate`
|
||||
* reads, so the main window's banner shows it too. */
|
||||
export const checkForUpdateNow = () => invoke<UpdateCheckResult>('check_for_update_now')
|
||||
|
||||
export const onRecordingState = (handler: (state: RecordingState) => void): Promise<UnlistenFn> =>
|
||||
listen<RecordingState>('recording-state', (event) => handler(event.payload))
|
||||
@@ -218,6 +235,19 @@ export function meterFill(level: number): number {
|
||||
return Math.min(1, Math.max(0, (db + 60) / 60))
|
||||
}
|
||||
|
||||
function megabytes(bytes: number): string {
|
||||
return (bytes / 1024 / 1024).toLocaleString('de-DE', { maximumFractionDigits: 1 }) + ' MB'
|
||||
}
|
||||
|
||||
/** Text shown while an update installs (the banner and the settings'
|
||||
* Updates section share this). */
|
||||
export function updateProgressText(progress: UpdateProgress | null): string {
|
||||
if (!progress) return 'Update wird heruntergeladen…'
|
||||
if (progress.total === null) return `Update wird heruntergeladen… ${megabytes(progress.downloaded)}`
|
||||
if (progress.downloaded >= progress.total) return 'Update wird installiert…'
|
||||
return `Update wird heruntergeladen… ${Math.floor((progress.downloaded * 100) / progress.total)} %`
|
||||
}
|
||||
|
||||
/** Error text of a rejected command. */
|
||||
export function errorText(err: unknown): string {
|
||||
return typeof err === 'string' ? err : err instanceof Error ? err.message : String(err)
|
||||
|
||||
@@ -6,17 +6,26 @@
|
||||
backendLogout,
|
||||
backendServer,
|
||||
backendStatus,
|
||||
canSelfUpdate,
|
||||
checkForUpdateNow,
|
||||
errorText,
|
||||
getAppVersion,
|
||||
getSettings,
|
||||
getUpdate,
|
||||
hasApiKey,
|
||||
installUpdate,
|
||||
listDevices,
|
||||
meterFill,
|
||||
onBackendChanged,
|
||||
onBackendLoginError,
|
||||
onUpdateAvailable,
|
||||
onUpdateProgress,
|
||||
openBackendKeysPage,
|
||||
saveSettings,
|
||||
setApiKey,
|
||||
testDevices,
|
||||
updateProgressText,
|
||||
UPDATE_BUSY_HINT,
|
||||
type BackendServer,
|
||||
type BackendStatus,
|
||||
type DeviceInfo,
|
||||
@@ -24,6 +33,9 @@
|
||||
type Devices,
|
||||
type Service,
|
||||
type Settings,
|
||||
type UpdateCheckResult,
|
||||
type UpdateInfo,
|
||||
type UpdateProgress,
|
||||
} from '../lib/api'
|
||||
|
||||
const services: { id: Service; name: string }[] = [
|
||||
@@ -48,19 +60,84 @@
|
||||
// Status answers can arrive out of order; only the newest is applied.
|
||||
let statusRequest = 0
|
||||
|
||||
let appVersion = $state('')
|
||||
/** `null` until known: whether this build can install an update itself
|
||||
* (Windows only); avoids guessing wrong for an instant. */
|
||||
let selfUpdateCapable = $state<boolean | null>(null)
|
||||
let checking = $state(false)
|
||||
let checkResult = $state<UpdateCheckResult | null>(null)
|
||||
let pendingUpdate = $state<UpdateInfo | null>(null)
|
||||
let installing = $state(false)
|
||||
let installProgress = $state<UpdateProgress | null>(null)
|
||||
let installError = $state('')
|
||||
|
||||
onMount(() => {
|
||||
load()
|
||||
backendServer()
|
||||
.then((s) => (server = s))
|
||||
.catch((err) => (backendError = errorText(err)))
|
||||
refreshBackend()
|
||||
getAppVersion()
|
||||
.then((v) => (appVersion = v))
|
||||
.catch(() => {})
|
||||
canSelfUpdate()
|
||||
.then((v) => (selfUpdateCapable = v))
|
||||
.catch(() => {})
|
||||
getUpdate()
|
||||
.then((u) => (pendingUpdate = u))
|
||||
.catch(() => {})
|
||||
const unlisten = [
|
||||
onBackendChanged(refreshBackend),
|
||||
onBackendLoginError((msg) => (backendError = msg)),
|
||||
onUpdateAvailable((info) => (pendingUpdate = info)),
|
||||
onUpdateProgress((progress) => (installProgress = progress)),
|
||||
]
|
||||
return () => unlisten.forEach((u) => u.then((off) => off()))
|
||||
})
|
||||
|
||||
/** "Nach Updates suchen": runs the same check as the background loop,
|
||||
* immediately. An available update also arrives via `update-available`
|
||||
* (so the main window's banner shows it too), but is applied here as
|
||||
* well in case that event is missed. */
|
||||
async function checkUpdateNow() {
|
||||
checking = true
|
||||
checkResult = null
|
||||
try {
|
||||
const result = await checkForUpdateNow()
|
||||
checkResult = result
|
||||
if (result.status === 'available') pendingUpdate = await getUpdate()
|
||||
} catch (err) {
|
||||
checkResult = { status: 'error', message: errorText(err) }
|
||||
} finally {
|
||||
checking = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshPendingUpdate() {
|
||||
try {
|
||||
pendingUpdate = await getUpdate()
|
||||
} catch {
|
||||
// Optional refresh; the next event or check tries again.
|
||||
}
|
||||
}
|
||||
|
||||
/** "Installieren & neu starten" for the update found above; reuses the
|
||||
* install command and guard the main window's banner uses. */
|
||||
async function installUpdateNow() {
|
||||
installing = true
|
||||
installProgress = null
|
||||
installError = ''
|
||||
try {
|
||||
// Returns only on failure: on success the app restarts.
|
||||
await installUpdate()
|
||||
} catch (err) {
|
||||
installError = errorText(err)
|
||||
refreshPendingUpdate()
|
||||
} finally {
|
||||
installing = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks the stored key with the backend. */
|
||||
async function refreshBackend() {
|
||||
const request = ++statusRequest
|
||||
@@ -377,6 +454,48 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Updates</h2>
|
||||
<div class="grid">
|
||||
<span>Version</span>
|
||||
<span>{appVersion || '…'}</span>
|
||||
</div>
|
||||
<div class="update-check">
|
||||
<button class="btn" disabled={checking} onclick={checkUpdateNow}>
|
||||
{checking ? 'Suche…' : 'Nach Updates suchen'}
|
||||
</button>
|
||||
{#if checkResult?.status === 'none'}
|
||||
<span class="muted">Keine neue Version verfügbar (aktuell: {appVersion})</span>
|
||||
{:else if checkResult?.status === 'error'}
|
||||
<span class="error">{checkResult.message}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if pendingUpdate && selfUpdateCapable !== null}
|
||||
<div class="update-available">
|
||||
<span>Update verfügbar (v{pendingUpdate.version})</span>
|
||||
{#if selfUpdateCapable}
|
||||
{#if installing}
|
||||
<span>{updateProgressText(installProgress)}</span>
|
||||
{:else}
|
||||
<button class="btn primary small" disabled={!pendingUpdate.can_install} onclick={installUpdateNow}>
|
||||
Installieren & neu starten
|
||||
</button>
|
||||
{#if !pendingUpdate.can_install}
|
||||
<span class="muted">{UPDATE_BUSY_HINT}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if installError}
|
||||
<span class="error">{installError}</span>
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="muted">
|
||||
Updates gibt es unter Windows automatisch; unter Linux bitte das .deb neu installieren.
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<div class="footer">
|
||||
<button class="btn primary" onclick={() => run(persist, 'Einstellungen gespeichert ✓')}>
|
||||
Speichern
|
||||
@@ -503,6 +622,15 @@
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.update-check,
|
||||
.update-available {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user