Merge branch 'v1.5.0' into feature/playlists/107

This commit is contained in:
MathieuG-P
2024-02-26 15:33:13 +01:00
23 changed files with 398 additions and 23 deletions
+71 -2
View File
@@ -1,8 +1,21 @@
import { Observable, lastValueFrom } from "rxjs";
import { map } from "rxjs/operators";
import { IpcService } from "./ipc.service";
import { ProgressBarService } from "./progress-bar.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;
}
export interface ChangelogVersion {
htmlBody: string;
title: string;
timestamp : number;
version: string;
}
export class AutoUpdaterService {
private static instance: AutoUpdaterService;
@@ -11,6 +24,12 @@ export class AutoUpdaterService {
private downloadProgress$: Observable<number>;
private modal: ModalService;
private configurationService: ConfigurationService;
private cacheChangelog: Changelog;
public static getInstance(): AutoUpdaterService {
if (!AutoUpdaterService.instance) {
AutoUpdaterService.instance = new AutoUpdaterService();
@@ -21,6 +40,8 @@ export class AutoUpdaterService {
private constructor() {
this.progressService = ProgressBarService.getInstance();
this.ipcService = IpcService.getInstance();
this.modal = ModalService.getInstance();
this.configurationService = ConfigurationService.getInstance();
this.downloadProgress$ = this.ipcService.watch<number>("update-download-progress").pipe(map(res => (res.success ? res.data : 0)));
}
@@ -35,11 +56,59 @@ export class AutoUpdaterService {
});
this.progressService.show(this.downloadProgress$, true);
return promise;
}
public quitAndInstall() {
this.ipcService.sendLazy("install-update");
}
public getLastAppVersion(): string {
return this.configurationService.get("last-app-version");
}
public setLastAppVersion(value : string){
this.configurationService.set("last-app-version", value);
}
private async getChangelog(): Promise<Changelog> {
if (this.cacheChangelog) {
return this.cacheChangelog;
}
const path = `https://raw.githubusercontent.com/Zagrios/bs-manager/master/assets/jsons/changelogs.json`
const response = await fetch(path);
if (!response.ok) {
throw new Error(`Failed to fetch changelogs (${response.status})`);
}
const data = await response.json();
if (!data) {
throw new Error(`Failed to parse changelogs`);
}
this.cacheChangelog = data;
return data;
}
private async getChangelogVersion(version:string): Promise<ChangelogVersion> {
const changelogs = await this.getChangelog();
const changelogVersion = changelogs[version];
if (!changelogVersion) {
throw new Error(`No changelog found for this version (${version})`);
}
return changelogVersion;
}
public getAppVersion() : Observable<string> {
return this.ipcService.sendV2<string>("current-version");
}
public async showChangelog(version:string): Promise<void>{
const changelog = await this.getChangelogVersion(version);
this.modal.openModal(ChangelogModal, changelog);
}
}