diff --git a/app/main.ts b/app/main.ts index f47b4d5..6f56428 100644 --- a/app/main.ts +++ b/app/main.ts @@ -15,6 +15,21 @@ const pidusage = require('pidusage'); const batteryLevel = require('battery-level'); const network = require('network'); +function isOnBatteryPower(): Promise { + return new Promise((resolve) => { + exec("upower -i $(upower -e | grep 'battery') | grep 'state'", (error, stdout) => { + if (error) { + console.error(`isOnBatteryPower(): ${error.message}`); + resolve(false); // Ritorna false se non riesce a rilevare lo stato della batteria + return; + } + + const isOnBattery = stdout.includes("discharging"); + resolve(isOnBattery); + }); + }); +} + interface Stats { /** * percentage (from 0 to 100*vcore) @@ -787,7 +802,22 @@ try { // #endregion ipcMain.handle('is-on-battery-power', (event: IpcMainInvokeEvent) => { - win?.webContents.send('on-is-on-battery-power', powerMonitor.isOnBatteryPower()); + const onBattery = powerMonitor.isOnBatteryPower(); + + if (!onBattery && os.platform() == 'linux') { + isOnBatteryPower().then((value) => { + win?.webContents.send('on-is-on-battery-power', value); + }).catch((error: any) => { + console.error(`${error}`); + win?.webContents.send('on-is-on-battery-power', false); + }); + + return; + } + else { + win?.webContents.send('on-is-on-battery-power', onBattery); + } + }); powerMonitor.on('on-ac', () => win?.webContents.send('on-ac')); diff --git a/electron-installer-debian.json b/electron-installer-debian.json index ab46640..236a37a 100644 --- a/electron-installer-debian.json +++ b/electron-installer-debian.json @@ -10,5 +10,10 @@ ], "lintianOverrides": [ "changelog-file-missing-in-native-package" + ], + "depends": [ + "net-tools", + "upower", + "dbus" ] } \ No newline at end of file diff --git a/electron-installer-redhat.json b/electron-installer-redhat.json index 55411d2..55f03fc 100644 --- a/electron-installer-redhat.json +++ b/electron-installer-redhat.json @@ -10,5 +10,10 @@ ], "lintianOverrides": [ "changelog-file-missing-in-native-package" + ], + "depends": [ + "net-tools", + "upower", + "dbus" ] } \ No newline at end of file diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index e898a6f..05a5bf9 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -71,7 +71,9 @@ export class SettingsComponent { public isAppImage: boolean = true; public refreshSyncMode(): void { - this.currentSettings.dbSyncMode = this.dbSyncMode; + setTimeout(() => { + this.currentSettings.dbSyncMode = this.dbSyncMode; + }, 100); } private initSyncMode(): void {