Files
dotfiles/quickshell/services/PowerProfiles.qml
T
2026-11-17 18:15:16 +07:00

46 lines
1.6 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
Singleton {
id: root
property string profile: ""
property string error: ""
property bool busy: false
property string requested: ""
readonly property var profiles: ["power-saver", "balanced", "performance"]
function request(profileName) {
if (busy || !profiles.includes(profileName)) return false;
requested = profileName;
busy = true;
error = "";
worker.command = ["python3", Quickshell.shellPath("backend/power_profiles.py"), "set", profileName];
worker.running = true;
return true;
}
function refresh() {
if (busy) return;
requested = "";
busy = true;
worker.command = ["python3", Quickshell.shellPath("backend/power_profiles.py"), "get"];
worker.running = true;
}
Process {
id: worker
stdout: StdioCollector { id: output }
stderr: StdioCollector { id: errors }
onExited: (code, status) => {
root.busy = false;
try {
const data = JSON.parse(output.text);
if (code !== 0 || !data.ok || !root.profiles.includes(data.profile))
throw new Error(data.error || errors.text || "Не удалось изменить профиль");
root.profile = data.profile;
root.error = "";
} catch (e) { root.error = String(e); }
}
}
Timer { interval: 30000; repeat: true; running: true; triggeredOnStart: true; onTriggered: root.refresh() }
}