Disable all navbar link when daemon status changes

This commit is contained in:
everoddandeven 2024-10-29 17:47:57 +01:00
parent 10142f5b88
commit 9ff618809e
5 changed files with 56 additions and 15 deletions

View file

@ -990,10 +990,18 @@ export class DaemonService {
this.stopping = false; this.stopping = false;
if (!this.restarting) { if (!this.restarting) {
window.electronAPI.showNotification({ if (!this.quitting) {
title: 'Daemon stopped', window.electronAPI.showNotification({
body: 'Successfully stopped monero daemon' title: 'Daemon stopped',
}); body: 'Successfully stopped monero daemon'
});
}
else {
window.electronAPI.showNotification({
title: 'Daemon quitted',
body: 'Successfully quit monero daemon'
});
}
} }
return; return;

View file

@ -16,6 +16,7 @@ export class ElectronService {
private _isAppImage?: boolean; private _isAppImage?: boolean;
private _isAutoLaunched?: boolean; private _isAutoLaunched?: boolean;
private _online: boolean = false;
constructor() { constructor() {
// Conditional imports // Conditional imports
@ -50,6 +51,14 @@ export class ElectronService {
// ipcRenderer.invoke can serve many common use cases. // ipcRenderer.invoke can serve many common use cases.
// https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendererinvokechannel-args // https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendererinvokechannel-args
} }
this._online = navigator.onLine;
window.addEventListener('online', () => this._online = true);
window.addEventListener('offline', () => this._online = false);
}
public get online(): boolean {
return this._online;
} }
get isElectron(): boolean { get isElectron(): boolean {

View file

@ -11,7 +11,7 @@ export abstract class BasePageComponent implements AfterContentInit, OnDestroy {
private _links: NavbarLink[] = []; private _links: NavbarLink[] = [];
public get links(): NavbarLink[] { public get links(): NavbarLink[] {
return this._links; return this.navbarService.links;
} }
protected subscriptions: Subscription[] = []; protected subscriptions: Subscription[] = [];

View file

@ -179,12 +179,18 @@ export class DetailComponent extends BasePageComponent implements AfterViewInit
}); });
}); });
const daemonStatusSub = this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => {
if (!running) {
this.destroyTables();
}
});
const syncInfoRefreshEndSub: Subscription = this.daemonData.syncInfoRefreshEnd.subscribe(() => { const syncInfoRefreshEndSub: Subscription = this.daemonData.syncInfoRefreshEnd.subscribe(() => {
this.cards = this.createCards(); this.cards = this.createCards();
this.loadTables(); this.loadTables();
}); });
this.subscriptions.push(syncStartSub, syncInfoRefreshEndSub); this.subscriptions.push(syncStartSub, syncInfoRefreshEndSub, daemonStatusSub);
} }
public ngAfterViewInit(): void { public ngAfterViewInit(): void {

View file

@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'; import { Injectable, NgZone } from '@angular/core';
import { NavbarLink } from './navbar.model'; import { NavbarLink } from './navbar.model';
import { DaemonService } from '../../../core/services'; import { DaemonService } from '../../../core/services';
@ -13,31 +13,49 @@ export class NavbarService {
return this._navbarLinks; return this._navbarLinks;
} }
constructor(private daemonService: DaemonService) { constructor(private daemonService: DaemonService, private zone: NgZone) {
this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => { this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => {
this.daemonRunning = running; this.daemonRunning = running;
if (!running) this.disableLinks(); this.refreshLinks();
if (running) this.enableLinks();
}); });
this.daemonService.isRunning().then((running: boolean) => { this.daemonService.isRunning().then((running: boolean) => {
this.daemonRunning = running; this.daemonRunning = running;
if (!running) this.disableLinks();
if (running) this.enableLinks();
}).catch((error: any) => { }).catch((error: any) => {
console.error(error); console.error(error);
this.disableLinks(); }).finally(() => {
this.refreshLinks();
});
}
private refreshLinks(): void {
if (this._navbarLinks.length == 0) {
return;
}
const links = this._navbarLinks;
this.zone.run(() => {
setTimeout(() => {
this.setLinks([]);
}, 0);
setTimeout(() => {
this.setLinks(links);
}, 0);
}) })
} }
public addLink(... navbarLinks: NavbarLink[]): void { public addLink(... navbarLinks: NavbarLink[]): void {
navbarLinks.forEach((navLink: NavbarLink) => this._navbarLinks.push(navLink)); navbarLinks.forEach((navLink: NavbarLink) => this._navbarLinks.push(navLink));
} }
private get enabled(): boolean {
return this.daemonRunning && !this.daemonService.stopping && !this.daemonService.starting && !this.daemonService.restarting;
}
public setLinks(navbarLinks: NavbarLink[]): void { public setLinks(navbarLinks: NavbarLink[]): void {
this._navbarLinks = navbarLinks; this._navbarLinks = navbarLinks;
if (this.daemonRunning) this.enableLinks(); if (this.enabled) this.enableLinks();
else this.disableLinks(); else this.disableLinks();
} }