import { BehaviorSubject, Subject } from 'rxjs'; import type { MainEventRegister } from '../type'; export interface UpdateMeta { version: string; allowAutoUpdate: boolean; } export const updaterSubjects = { // means it is ready for restart and install the new version updateAvailable$: new Subject(), updateReady$: new Subject(), downloadProgress$: new BehaviorSubject(0), }; export const updaterEvents = { onUpdateAvailable: (fn: (versionMeta: UpdateMeta) => void) => { const sub = updaterSubjects.updateAvailable$.subscribe(fn); return () => { sub.unsubscribe(); }; }, onUpdateReady: (fn: (versionMeta: UpdateMeta) => void) => { const sub = updaterSubjects.updateReady$.subscribe(fn); return () => { sub.unsubscribe(); }; }, onDownloadProgress: (fn: (progress: number) => void) => { const sub = updaterSubjects.downloadProgress$.subscribe(fn); return () => { sub.unsubscribe(); }; }, } satisfies Record;