mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
BatteryService: implement basic functionality to set battery treshold
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.UPower
|
||||
import qs.Commons
|
||||
import qs.Services
|
||||
@@ -8,6 +9,15 @@ import qs.Services
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
enum ChargingMode {
|
||||
Full,
|
||||
Balanced,
|
||||
Conservative
|
||||
}
|
||||
|
||||
property int chargingMode: BatteryService.ChargingMode.Balanced
|
||||
readonly property string batteryTresholdScript: Quickshell.shellDir + '/Bin/set-battery-treshold.sh'
|
||||
|
||||
// Choose icon based on charge and charging state
|
||||
function getIcon(percent, charging, isReady) {
|
||||
if (!isReady) {
|
||||
@@ -28,4 +38,37 @@ Singleton {
|
||||
return "battery"
|
||||
}
|
||||
}
|
||||
|
||||
function setChargingMode(newMode) {
|
||||
switch (newMode) {
|
||||
case BatteryService.ChargingMode.Full:
|
||||
BatteryService.chargingMode = newMode
|
||||
chargeLimitProcess.command = [batteryTresholdScript, "100"]
|
||||
break
|
||||
case BatteryService.ChargingMode.Balanced:
|
||||
BatteryService.chargingMode = newMode
|
||||
chargeLimitProcess.command = [batteryTresholdScript, "80"]
|
||||
break
|
||||
case BatteryService.ChargingMode.Conservative:
|
||||
BatteryService.chargingMode = newMode
|
||||
chargeLimitProcess.command = [batteryTresholdScript, "60"]
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
chargeLimitProcess.running = true
|
||||
}
|
||||
|
||||
Process {
|
||||
id: chargeLimitProcess
|
||||
workingDirectory: Quickshell.shellDir
|
||||
running: false
|
||||
stderr: StdioCollector {
|
||||
onStreamFinished: {
|
||||
if (this.text) {
|
||||
Logger.warn("BatteryService", "ChargeLimitProcess stderr:", this.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user