added adaptive quickshell
This commit is contained in:
1 parent
6eb56d2065
commit
5b33a73fd8
189 files changed
+8678
-15
No files matched your search
@@ -0,0 +1,45 @@
|
||||
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() }
|
||||
}
|
||||
Reference in new issue
Block a user