diff --git a/src/app/core/services/electron/electron.service.ts b/src/app/core/services/electron/electron.service.ts index 3d90262..0aff963 100644 --- a/src/app/core/services/electron/electron.service.ts +++ b/src/app/core/services/electron/electron.service.ts @@ -30,8 +30,14 @@ export class ElectronService { window.addEventListener('offline', () => this._online = false); this._isProduction = APP_CONFIG.production; - window.electronAPI.onBattery((event: any) => this.onBatteryPower.emit()); - window.electronAPI.onAc((event: any) => this.onAcPower.emit()); + window.electronAPI.onBattery((event: any) => { + console.debug(event); + this.onBatteryPower.emit() + }); + window.electronAPI.onAc((event: any) => { + console.debug(event); + this.onAcPower.emit() + }); } public get online(): boolean { diff --git a/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts b/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts index 88c73d5..afdeee3 100644 --- a/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts +++ b/src/app/shared/components/daemon-not-running/daemon-not-running.component.ts @@ -1,8 +1,5 @@ import { Component, OnDestroy } from '@angular/core'; -import { DaemonService } from '../../../core/services/daemon/daemon.service'; -import { DaemonDataService, MoneroInstallerService } from '../../../core/services'; import { Subscription } from 'rxjs'; -import { DaemonSettings } from '../../../../common'; import { DaemonStatusService } from './daemon-status.service'; @Component({ diff --git a/src/app/shared/components/daemon-not-running/daemon-status.service.ts b/src/app/shared/components/daemon-not-running/daemon-status.service.ts index 40979bb..ad2f39e 100644 --- a/src/app/shared/components/daemon-not-running/daemon-status.service.ts +++ b/src/app/shared/components/daemon-not-running/daemon-status.service.ts @@ -78,45 +78,44 @@ export class DaemonStatusService { private daemonService: DaemonService, private electronService: ElectronService, private ngZone: NgZone ) { - const onSavedSettingsSub: Subscription = this.daemonService.onSavedSettings.subscribe((settings) => { - this.refresh().then().catch((error: any) => console.error(error)); + const onSavedSettingsSub: Subscription = this.daemonService.onSavedSettings.subscribe(() => { + this.refresh(); }); const onDaemonStatusSub: Subscription = this.daemonService.onDaemonStatusChanged.subscribe((running: boolean) => { - this.refresh().then().catch((error: any) => console.error(error)); + if (running) return; + this.refresh(); }); const onAcPower: Subscription = this.electronService.onAcPower.subscribe(() => { - this.refresh().then().catch((error: any) => console.error(error)); + this.refresh(); }); const onBatteryPower: Subscription = this.electronService.onBatteryPower.subscribe(() => { - this.refresh().then().catch((error: any) => console.error(error)); + this.refresh(); }); - this.refresh().then().catch((error: any) => console.error(error)); + this.refresh(); this.subscriptions.push(onSavedSettingsSub, onDaemonStatusSub, onAcPower, onBatteryPower); } - public async refresh(): Promise { + public refresh(): void { //await this.daemonService.isRunning(); - this.ngZone.run(() => { - setTimeout(async () => { - this.settings = await this.daemonService.getSettings(); - this._runningOnBattery = await this.electronService.isOnBatteryPower(); + this.ngZone.run(async () => { + this.settings = await this.daemonService.getSettings(); + this._runningOnBattery = await this.electronService.isOnBatteryPower(); - if (this._runningOnBattery) this._batteryLevel = await this.electronService.getBatteryLevel(); + if (this._runningOnBattery) this._batteryLevel = await this.electronService.getBatteryLevel(); - if (this.settings.runOnBattery && this._runningOnBattery && this.settings.batteryLevelThreshold > 0) { - const batteryLevel = await this.electronService.getBatteryLevel(); - this._batteryTooLow = batteryLevel <= this.settings.batteryLevelThreshold; - console.log(`battery level: ${batteryLevel}, threshold: ${this.settings.batteryLevelThreshold}, too low: ${this._batteryTooLow}`); - } - else if (!this.settings.runOnBattery) { - this._batteryTooLow = false; - } - }, 0); + if (this.settings.runOnBattery && this._runningOnBattery && this.settings.batteryLevelThreshold > 0) { + const batteryLevel = await this.electronService.getBatteryLevel(); + this._batteryTooLow = batteryLevel <= this.settings.batteryLevelThreshold; + console.log(`battery level: ${batteryLevel}, threshold: ${this.settings.batteryLevelThreshold}, too low: ${this._batteryTooLow}`); + } + else if (!this.settings.runOnBattery) { + this._batteryTooLow = false; + } }); }