pragma ComponentBehavior: Bound import QtQuick import Quickshell import Quickshell.Io QtObject { id: root property bool busy: false property string error: "" property string token: "" property int secondsRemaining: 0 property string operation: "" function preview(name, mode, scale, transform, x, y) { if (busy || token !== "") return; busy = true; error = ""; operation = "preview"; worker.command = ["python3", Quickshell.shellPath("backend/display_preview.py"), "preview", name, mode, String(scale), String(transform), String(x), String(y)]; worker.running = true; } function confirm() { if (busy || token === "") return; busy = true; operation = "confirm"; worker.command = ["python3", Quickshell.shellPath("backend/display_preview.py"), "confirm", token]; worker.running = 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) throw new Error(result.error || errors.text || "Не удалось изменить дисплей"); if (root.operation === "preview") { root.token = result.token; root.secondsRemaining = result.seconds; countdown.start(); } else { root.token = ""; root.secondsRemaining = 0; countdown.stop(); } root.error = ""; } catch (e) { root.error = String(e); } } } property Timer countdown: Timer { id: countdown interval: 1000 repeat: true onTriggered: { root.secondsRemaining = Math.max(0, root.secondsRemaining - 1); if (root.secondsRemaining === 0) { stop(); root.token = ""; } } } }