From 834dad0cc01022055929a97d440df5a27beb9a23 Mon Sep 17 00:00:00 2001 From: Shidorien Date: Thu, 21 Dec 2023 02:59:13 +0100 Subject: [PATCH] Refactor AutoUpdaterService imports and add error handling for getChangelog() and isChangelogAvailable() --- src/renderer/services/auto-updater.service.ts | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/renderer/services/auto-updater.service.ts b/src/renderer/services/auto-updater.service.ts index f9e42dd0..3a0d9739 100644 --- a/src/renderer/services/auto-updater.service.ts +++ b/src/renderer/services/auto-updater.service.ts @@ -1,4 +1,3 @@ -import { BehaviorSubject, Observable, lastValueFrom } from "rxjs"; import { map } from "rxjs/operators"; import { IpcService } from "./ipc.service"; import { ProgressBarService } from "./progress-bar.service"; @@ -6,6 +5,7 @@ import { I18nService } from "./i18n.service"; import { ModalService } from "renderer/services/modale.service"; import { ChangelogModal } from "renderer/components/modal/modal-types/chabgelog-modal/changelog-modal.component"; import { ConfigurationService } from "./configuration.service"; +import { Observable, lastValueFrom } from "rxjs"; export interface Changelog { [version: string]: ChangelogVersion; @@ -44,7 +44,6 @@ export class AutoUpdaterService { this.modal = ModalService.getInstance(); this.configurationService = ConfigurationService.getInstance(); - this.downloadProgress$ = this.ipcService.watch("update-download-progress").pipe(map(res => (res.success ? res.data : 0))); } @@ -74,6 +73,7 @@ export class AutoUpdaterService { } private async getChangelog(): Promise { + try { const path = `https://raw.githubusercontent.com/Zagrios/bs-manager/feature/add-changelog-modal/178/assets/jsons/changelogs/${this.i18nService.currentLanguage.split("-")[0]}.json` const response = await fetch(path); if (!response.ok) { @@ -85,6 +85,11 @@ export class AutoUpdaterService { return undefined; } return data; + } + catch(error){ + this.ipcService.sendLazy("log-error", {args: error}); + return undefined; + } } private async getChangelogVersion(version:string): Promise { @@ -105,11 +110,15 @@ export class AutoUpdaterService { return this.ipcService.sendV2("current-version"); } - public async showChangelog(): Promise{ + public async showChangelog(version:string = undefined): Promise{ try{ + + if (!version) { + version = await lastValueFrom(this.getAppVersion()) + } + if(this.getHaveBeenUpdated()){ - const currentVersion = await lastValueFrom(this.getAppVersion()); - const changelog = await this.getChangelogVersion(currentVersion); + const changelog = await this.getChangelogVersion(version); this.modal.openModal(ChangelogModal, changelog); } @@ -118,4 +127,20 @@ export class AutoUpdaterService { this.ipcService.sendLazy("log-error", {args: error}); } } + + public async isChangelogAvailable(version:string = undefined): Promise{ + try { + if (!version) { + version = await lastValueFrom(this.getAppVersion()) + } + + const changelog = await this.getChangelogVersion(version); + + return !!changelog; + } + catch(error){ + this.ipcService.sendLazy("log-error", {args: error}); + return false; + } + } }