Skip to content

Commit

Permalink
Linux fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Nov 12, 2024
1 parent 72c7442 commit 8c9519f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
32 changes: 31 additions & 1 deletion app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'));
Expand Down
5 changes: 5 additions & 0 deletions electron-installer-debian.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
],
"lintianOverrides": [
"changelog-file-missing-in-native-package"
],
"depends": [
"net-tools",
"upower",
"dbus"
]
}
5 changes: 5 additions & 0 deletions electron-installer-redhat.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
],
"lintianOverrides": [
"changelog-file-missing-in-native-package"
],
"depends": [
"net-tools",
"upower",
"dbus"
]
}
4 changes: 3 additions & 1 deletion src/app/pages/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8c9519f

Please sign in to comment.