constructor()

in desktop/src/@batch-flask/electron/auto-update/auto-update-main.service.ts [34:87]


    constructor() {
        super();
        this.status = this._status.pipe(
            map((status) => {
                if (this.disabled) {
                    return UpdateStatus.NotAvailable;
                } else {
                    return status;
                }
            }),
        );
        this.updateInfo = null;
        this.downloadProgress = this._downloadProgress.asObservable();

        this._autoCheckSub = interval(AUTO_UPDATE_CHECK_INTERVAL).subscribe(async () => {
            try {
                await autoUpdater.checkForUpdates();
            } catch (e) {
                log.error("Failed to check for updates", e);
            }
        });

        this.updateReady = this._status.pipe(map(x => x === UpdateStatus.Ready));

        autoUpdater.on("checking-for-update", () => {
            this._status.next(UpdateStatus.Checking);
        });

        autoUpdater.on("update-available", (info) => {
            this._downloadProgress.next({
                bytesPerSecond: 0,
                delta: 0,
                total: 0,
                transferred: 0,
                percent: 0,
            });
            this._status.next(UpdateStatus.Downloading);
            this.updateInfo = info;
        });

        autoUpdater.on("download-progress", (progress) => {
            this._downloadProgress.next(progress);
            this._status.next(UpdateStatus.Downloading);
        });

        autoUpdater.on("update-downloaded", (info) => {
            this._status.next(UpdateStatus.Ready);
        });

        autoUpdater.on("update-not-available", (info) => {
            this._downloadProgress.next(null);
            this._status.next(UpdateStatus.NotAvailable);
        });
    }