diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index 55bb9e2..794be23 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -206,6 +206,8 @@ export class DaemonService { } } + this.version = undefined; + const db = await this.openDbPromise; await db.put(this.storeName, { id: 1, ...settings }); @@ -332,6 +334,8 @@ export class DaemonService { return; } + this.version = undefined; + this.starting = true; console.log("Starting daemon"); @@ -682,7 +686,13 @@ export class DaemonService { return SyncInfo.parse(response.result); } - public async getLatestVersion(): Promise { + private mLatestVersion?: DaemonVersion; + + public async getLatestVersion(force: boolean = false): Promise { + if (!force && this.mLatestVersion) { + return this.mLatestVersion; + } + const response = await this.get(this.versionApiUrl); if (typeof response.tag_name != 'string') { @@ -701,15 +711,20 @@ export class DaemonService { const name = nameComponents[0]; - return new DaemonVersion(0, true, `Monero '${name}' (${response.tag_name}-release)`); + this.mLatestVersion = new DaemonVersion(0, true, `Monero '${name}' (${response.tag_name}-release)`); + + return this.mLatestVersion; } + public version?: DaemonVersion; + public async getVersion(dontUseRpc: boolean = false): Promise { if(!dontUseRpc && this.daemonRunning) { const response = await this.callRpc(new GetVersionRequest()); return DaemonVersion.parse(response.result); } + else if (this.version) return this.version; else if (dontUseRpc) { const monerodPath: string = (await this.getSettings()).monerodPath; @@ -732,7 +747,8 @@ export class DaemonService { window.electronAPI.getMoneroVersion(monerodPath); - return await promise; + this.version = await promise; + return this.version; } throw new Error("Daemon not running"); diff --git a/src/app/pages/version/version.component.html b/src/app/pages/version/version.component.html index fcc9d22..0eaf58b 100644 --- a/src/app/pages/version/version.component.html +++ b/src/app/pages/version/version.component.html @@ -57,10 +57,15 @@
- + + + diff --git a/src/app/pages/version/version.component.ts b/src/app/pages/version/version.component.ts index 1ceaad9..3b4d611 100644 --- a/src/app/pages/version/version.component.ts +++ b/src/app/pages/version/version.component.ts @@ -18,6 +18,10 @@ export class VersionComponent implements AfterViewInit { public latestVersion?: DaemonVersion; public settings: DaemonSettings = new DaemonSettings(); + public get configured(): boolean { + return this.settings.monerodPath != ''; + } + public get buttonDisabled(): boolean { const title = this.buttonTitle; @@ -48,7 +52,7 @@ export class VersionComponent implements AfterViewInit { return 'Install'; } - return 'Upgrade'; + return 'Check Updates'; } constructor(private daemonData: DaemonDataService, private daemonService: DaemonService, private electronService: ElectronService, private moneroInstaller: MoneroInstallerService, private ngZone: NgZone) { @@ -97,9 +101,9 @@ export class VersionComponent implements AfterViewInit { } } - private async refreshLatestVersion(): Promise { + private async refreshLatestVersion(force: boolean = false): Promise { try { - this.latestVersion = await this.daemonService.getLatestVersion(); + this.latestVersion = await this.daemonService.getLatestVersion(force); } catch(error: any) { console.error(error); @@ -107,6 +111,15 @@ export class VersionComponent implements AfterViewInit { } } + private refreshCards(error: boolean = false): void { + if (error) { + this.cards = this.createErrorCards(); + return; + } + + this.cards = this.createCards(); + } + public async load(): Promise { await this.ngZone.run(async () => { this.loading = true; @@ -125,6 +138,17 @@ export class VersionComponent implements AfterViewInit { }); } + public checkingLatestVersion: boolean = false; + + public async checkLatestVersion(): Promise { + if (this.checkingLatestVersion) return; + + this.checkingLatestVersion = true; + await this.refreshLatestVersion(true); + + setTimeout(() => { this.checkingLatestVersion = false; this.refreshCards() }, 500); + } + public get upgrading(): boolean { return this.moneroInstaller.upgrading; }