This commit is contained in:
argenius 2024-11-10 22:00:25 +01:00
parent 9ac4cef1c0
commit 0c13fc5bec
3 changed files with 28 additions and 26 deletions

View file

@ -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 {

View file

@ -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({

View file

@ -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<void> {
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;
}
});
}