Linux fixes

This commit is contained in:
everoddandeven 2024-11-12 22:05:49 +01:00
parent 72c7442306
commit 8c9519f604
4 changed files with 44 additions and 2 deletions

View file

@ -15,6 +15,21 @@ const pidusage = require('pidusage');
const batteryLevel = require('battery-level');
const network = require('network');
function isOnBatteryPower(): Promise<boolean> {
return new Promise<boolean>((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'));

View file

@ -10,5 +10,10 @@
],
"lintianOverrides": [
"changelog-file-missing-in-native-package"
],
"depends": [
"net-tools",
"upower",
"dbus"
]
}

View file

@ -10,5 +10,10 @@
],
"lintianOverrides": [
"changelog-file-missing-in-native-package"
],
"depends": [
"net-tools",
"upower",
"dbus"
]
}

View file

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