mirror of
https://github.com/everoddandeven/monerod-gui.git
synced 2025-01-09 04:20:08 +00:00
Optimize get version
This commit is contained in:
parent
44677c3666
commit
f617af9c31
3 changed files with 52 additions and 7 deletions
|
@ -206,6 +206,8 @@ export class DaemonService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.version = undefined;
|
||||||
|
|
||||||
const db = await this.openDbPromise;
|
const db = await this.openDbPromise;
|
||||||
await db.put(this.storeName, { id: 1, ...settings });
|
await db.put(this.storeName, { id: 1, ...settings });
|
||||||
|
|
||||||
|
@ -332,6 +334,8 @@ export class DaemonService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.version = undefined;
|
||||||
|
|
||||||
this.starting = true;
|
this.starting = true;
|
||||||
|
|
||||||
console.log("Starting daemon");
|
console.log("Starting daemon");
|
||||||
|
@ -682,7 +686,13 @@ export class DaemonService {
|
||||||
return SyncInfo.parse(response.result);
|
return SyncInfo.parse(response.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getLatestVersion(): Promise<DaemonVersion> {
|
private mLatestVersion?: DaemonVersion;
|
||||||
|
|
||||||
|
public async getLatestVersion(force: boolean = false): Promise<DaemonVersion> {
|
||||||
|
if (!force && this.mLatestVersion) {
|
||||||
|
return this.mLatestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await this.get(this.versionApiUrl);
|
const response = await this.get(this.versionApiUrl);
|
||||||
|
|
||||||
if (typeof response.tag_name != 'string') {
|
if (typeof response.tag_name != 'string') {
|
||||||
|
@ -701,15 +711,20 @@ export class DaemonService {
|
||||||
|
|
||||||
const name = nameComponents[0];
|
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<DaemonVersion> {
|
public async getVersion(dontUseRpc: boolean = false): Promise<DaemonVersion> {
|
||||||
if(!dontUseRpc && this.daemonRunning) {
|
if(!dontUseRpc && this.daemonRunning) {
|
||||||
const response = await this.callRpc(new GetVersionRequest());
|
const response = await this.callRpc(new GetVersionRequest());
|
||||||
|
|
||||||
return DaemonVersion.parse(response.result);
|
return DaemonVersion.parse(response.result);
|
||||||
}
|
}
|
||||||
|
else if (this.version) return this.version;
|
||||||
else if (dontUseRpc) {
|
else if (dontUseRpc) {
|
||||||
const monerodPath: string = (await this.getSettings()).monerodPath;
|
const monerodPath: string = (await this.getSettings()).monerodPath;
|
||||||
|
|
||||||
|
@ -732,7 +747,8 @@ export class DaemonService {
|
||||||
|
|
||||||
window.electronAPI.getMoneroVersion(monerodPath);
|
window.electronAPI.getMoneroVersion(monerodPath);
|
||||||
|
|
||||||
return await promise;
|
this.version = await promise;
|
||||||
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error("Daemon not running");
|
throw new Error("Daemon not running");
|
||||||
|
|
|
@ -57,10 +57,15 @@
|
||||||
|
|
||||||
<hr class="my-4">
|
<hr class="my-4">
|
||||||
|
|
||||||
<button *ngIf="!loading && !upgrading && !installing" class="w-100 btn btn-primary btn-lg" type="submit" (click)="upgrade()" [disabled]="buttonDisabled">{{ buttonTitle }}</button>
|
<button *ngIf="!loading && !upgrading && !installing && !buttonDisabled" class="w-100 btn btn-primary btn-lg" type="submit" (click)="upgrade()" [disabled]="buttonDisabled">{{ buttonTitle }}</button>
|
||||||
|
<button *ngIf="!loading && !upgrading && !installing && buttonDisabled && !checkingLatestVersion" class="w-100 btn btn-primary btn-lg" type="submit" (click)="checkLatestVersion()">{{ buttonTitle }}</button>
|
||||||
<button *ngIf="!loading && upgrading || installing" class="w-100 btn btn-primary btn-lg" type="button" disabled>
|
<button *ngIf="!loading && upgrading || installing" class="w-100 btn btn-primary btn-lg" type="button" disabled>
|
||||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
||||||
{{ upgrading ? 'Upgrading' : 'Installing' }} monerod {{ downloadProgress }}
|
{{ upgrading ? 'Upgrading' : 'Installing' }} monerod {{ downloadProgress }}
|
||||||
</button>
|
</button>
|
||||||
|
<button *ngIf="!loading && !upgrading && !installing && checkingLatestVersion" class="w-100 btn btn-primary btn-lg" type="button" disabled>
|
||||||
|
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
||||||
|
Checking Updates
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,6 +18,10 @@ export class VersionComponent implements AfterViewInit {
|
||||||
public latestVersion?: DaemonVersion;
|
public latestVersion?: DaemonVersion;
|
||||||
public settings: DaemonSettings = new DaemonSettings();
|
public settings: DaemonSettings = new DaemonSettings();
|
||||||
|
|
||||||
|
public get configured(): boolean {
|
||||||
|
return this.settings.monerodPath != '';
|
||||||
|
}
|
||||||
|
|
||||||
public get buttonDisabled(): boolean {
|
public get buttonDisabled(): boolean {
|
||||||
const title = this.buttonTitle;
|
const title = this.buttonTitle;
|
||||||
|
|
||||||
|
@ -48,7 +52,7 @@ export class VersionComponent implements AfterViewInit {
|
||||||
return 'Install';
|
return 'Install';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'Upgrade';
|
return 'Check Updates';
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(private daemonData: DaemonDataService, private daemonService: DaemonService, private electronService: ElectronService, private moneroInstaller: MoneroInstallerService, private ngZone: NgZone) {
|
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<void> {
|
private async refreshLatestVersion(force: boolean = false): Promise<void> {
|
||||||
try {
|
try {
|
||||||
this.latestVersion = await this.daemonService.getLatestVersion();
|
this.latestVersion = await this.daemonService.getLatestVersion(force);
|
||||||
}
|
}
|
||||||
catch(error: any) {
|
catch(error: any) {
|
||||||
console.error(error);
|
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<void> {
|
public async load(): Promise<void> {
|
||||||
await this.ngZone.run(async () => {
|
await this.ngZone.run(async () => {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
@ -125,6 +138,17 @@ export class VersionComponent implements AfterViewInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public checkingLatestVersion: boolean = false;
|
||||||
|
|
||||||
|
public async checkLatestVersion(): Promise<void> {
|
||||||
|
if (this.checkingLatestVersion) return;
|
||||||
|
|
||||||
|
this.checkingLatestVersion = true;
|
||||||
|
await this.refreshLatestVersion(true);
|
||||||
|
|
||||||
|
setTimeout(() => { this.checkingLatestVersion = false; this.refreshCards() }, 500);
|
||||||
|
}
|
||||||
|
|
||||||
public get upgrading(): boolean {
|
public get upgrading(): boolean {
|
||||||
return this.moneroInstaller.upgrading;
|
return this.moneroInstaller.upgrading;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue