fix: AppUpdater popover not able to be closed (#4555)

This commit is contained in:
Nico Domino 2024-07-31 11:51:04 +02:00 committed by GitHub
parent 3ba4297f1b
commit ad92566cb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import { showToast } from '$lib/notifications/toasts';
import { getVersion } from '@tauri-apps/api/app';
import { relaunch } from '@tauri-apps/api/process';
import {
checkUpdate,
@ -10,7 +11,7 @@ import {
import posthog from 'posthog-js';
import { derived, writable, type Readable } from 'svelte/store';
// TOOD: Investigate why 'DOWNLOADED' is not in the type provided by Tauri.
// TODO: Investigate why 'DOWNLOADED' is not in the type provided by Tauri.
export type Update =
| { version?: string; status?: UpdateStatus | 'DOWNLOADED'; body?: string }
| undefined;
@ -33,6 +34,7 @@ export class UpdaterService {
undefined
);
currentVersion = writable<string | undefined>(undefined);
readonly version = derived(this.update, (update) => update?.version);
prev: Update | undefined;
@ -42,6 +44,8 @@ export class UpdaterService {
constructor() {}
private async start() {
const currentVersion = await getVersion();
this.currentVersion.set(currentVersion);
await this.checkForUpdate();
setInterval(async () => await this.checkForUpdate(), 3600000); // hourly
this.unlistenFn = await onUpdaterEvent((status) => {

View File

@ -8,10 +8,13 @@
const updaterService = getContext(UpdaterService);
const update = updaterService.update;
const version = updaterService.version;
const currentVersion = updaterService.currentVersion;
let dismissed = $state(false);
$effect(() => {
if (version && dismissed) dismissed = false;
if ($version !== $currentVersion && dismissed) {
dismissed = false;
}
});
</script>
@ -120,9 +123,8 @@
Release notes
</Button>
<div class="status-section">
<div class="sliding-gradient"></div>
{#if !$update.status}
<div class="sliding-gradient"></div>
<div class="cta-btn" transition:fade={{ duration: 100 }}>
<Button
wide
@ -136,6 +138,7 @@
</Button>
</div>
{:else if $update.status === 'DONE'}
<div class="sliding-gradient"></div>
<div class="cta-btn" transition:fade={{ duration: 100 }}>
<Button style="pop" kind="solid" wide on:click={() => updaterService.relaunchApp()}
>Restart</Button
@ -190,7 +193,6 @@
flex-direction: column;
align-items: center;
height: var(--size-button);
width: 100%;
border-radius: var(--radius-m);