From 2dad3f25932c9d8f011a071b39ab887b740ed6e9 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Mon, 18 Dec 2023 20:05:01 +0100 Subject: [PATCH] chore: update interval for checking updates to every 6 hours instead of every 12 hours --- packages/ui/src/routes/updater.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/ui/src/routes/updater.ts b/packages/ui/src/routes/updater.ts index 9dcdd0eac..380ced9b6 100644 --- a/packages/ui/src/routes/updater.ts +++ b/packages/ui/src/routes/updater.ts @@ -1,5 +1,17 @@ import { checkUpdate, installUpdate } from '@tauri-apps/api/updater'; -import { BehaviorSubject, switchMap, type Observable, from, map, shareReplay } from 'rxjs'; +import { + BehaviorSubject, + switchMap, + Observable, + from, + map, + shareReplay, + interval, + timeout, + catchError, + of, + startWith +} from 'rxjs'; export type Update = { enabled: boolean; shouldUpdate?: boolean; body?: string; version?: string }; @@ -8,7 +20,13 @@ export class UpdaterService { private reload$ = new BehaviorSubject(undefined); constructor() { this.update$ = this.reload$.pipe( - switchMap(() => from(checkUpdate())), + switchMap(() => interval(6 * 60 * 60 * 1000).pipe(startWith(0))), + switchMap(() => + from(checkUpdate()).pipe( + timeout(30000), // In dev mode the promise hangs indefinitely. + catchError(() => of({ shouldUpdate: false, manifest: undefined })) + ) + ), map((update) => { if (update === undefined) { return { enabled: false }; @@ -25,11 +43,6 @@ export class UpdaterService { }), shareReplay(1) ); - - // Check for updates every 12h - setInterval(() => { - this.reload$.next(); - }, 43200 * 1000); } }