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:
@@ -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