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,50 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
property var devices: []
|
||||
property bool busy: false
|
||||
property string error: ""
|
||||
property var command: ["python3", Quickshell.shellPath("backend/brightness.py")]
|
||||
function refresh() {
|
||||
if (busy) return false;
|
||||
error = "";
|
||||
busy = true;
|
||||
worker.command = command.concat(["list"]);
|
||||
worker.running = true;
|
||||
return true;
|
||||
}
|
||||
function setBrightness(device, percent) {
|
||||
if (busy || !/^[A-Za-z0-9_.:-]{1,128}$/.test(device) || !Number.isInteger(percent) || percent < 1 || percent > 100)
|
||||
return false;
|
||||
if (!devices.some(d => d.name === device)) return false;
|
||||
error = "";
|
||||
busy = true;
|
||||
worker.command = command.concat(["set", device, String(percent)]);
|
||||
worker.running = true;
|
||||
return true;
|
||||
}
|
||||
property Process worker: Process {
|
||||
stdout: StdioCollector { id: output }
|
||||
stderr: StdioCollector { id: errors }
|
||||
onExited: (code, status) => {
|
||||
root.busy = false;
|
||||
try {
|
||||
const result = JSON.parse(output.text);
|
||||
if (code !== 0 || !result.ok || !Array.isArray(result.devices))
|
||||
throw new Error(result.error || errors.text || "Ошибка управления яркостью");
|
||||
root.devices = result.devices;
|
||||
} catch (e) { root.error = String(e); }
|
||||
}
|
||||
}
|
||||
property Timer refreshTimer: Timer {
|
||||
interval: 10000
|
||||
repeat: true
|
||||
running: true
|
||||
triggeredOnStart: true
|
||||
onTriggered: root.refresh()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user