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,70 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
property var adapter: null
|
||||
property bool active: false
|
||||
property var backendCommand: ["python3", Quickshell.shellPath("backend/bluetooth.py")]
|
||||
property bool owned: false
|
||||
property bool starting: false
|
||||
property bool stopping: false
|
||||
readonly property bool busy: starting || worker.running
|
||||
property int durationMs: 60000
|
||||
property int startTimeoutMs: 6000
|
||||
property string error: ""
|
||||
property string backendError: ""
|
||||
function start() {
|
||||
if (busy) return false;
|
||||
if (!active || !adapter?.enabled) { error = "Bluetooth выключен или адаптер недоступен"; return false; }
|
||||
if (adapter.discovering) { error = "Поиск уже выполняется"; return false; }
|
||||
error = ""; backendError = ""; stopping = false; starting = true;
|
||||
worker.command = backendCommand.concat(["discover", adapter.dbusPath]);
|
||||
worker.running = true;
|
||||
startup.restart();
|
||||
return true;
|
||||
}
|
||||
function stop() {
|
||||
startup.stop(); deadline.stop();
|
||||
if (!busy) return;
|
||||
stopping = true; starting = false; owned = false;
|
||||
worker.signal(15);
|
||||
shutdown.restart();
|
||||
}
|
||||
onActiveChanged: if (!active) stop()
|
||||
onAdapterChanged: stop()
|
||||
Component.onDestruction: if (worker.running) worker.signal(9)
|
||||
property Connections events: Connections {
|
||||
target: root.adapter
|
||||
function onEnabledChanged() { if (!root.adapter?.enabled) root.stop(); }
|
||||
}
|
||||
property Process worker: Process {
|
||||
stdout: SplitParser {
|
||||
onRead: data => {
|
||||
try {
|
||||
const result = JSON.parse(data);
|
||||
if (result.ok !== true) { root.backendError = result.error || "Ошибка поиска Bluetooth"; return; }
|
||||
if (result.event === "started" && !root.stopping) {
|
||||
root.starting = false; root.owned = true; startup.stop(); deadline.restart();
|
||||
}
|
||||
} catch(e) { root.backendError = "Некорректный ответ поиска Bluetooth"; }
|
||||
}
|
||||
}
|
||||
stderr: StdioCollector { id: errors }
|
||||
onExited: (code, status) => {
|
||||
startup.stop(); deadline.stop(); shutdown.stop();
|
||||
root.starting = false; root.owned = false;
|
||||
if (!root.stopping && (code !== 0 || root.backendError !== ""))
|
||||
root.error = root.backendError || errors.text.trim().slice(0, 2000) || "Поиск Bluetooth завершился с ошибкой";
|
||||
root.stopping = false;
|
||||
}
|
||||
}
|
||||
property Timer startup: Timer {
|
||||
interval: root.startTimeoutMs
|
||||
onTriggered: if (root.starting) { root.error = "Не удалось подтвердить начало поиска"; root.stop(); }
|
||||
}
|
||||
property Timer deadline: Timer { interval: root.durationMs; onTriggered: root.stop() }
|
||||
property Timer shutdown: Timer { interval: 2000; onTriggered: { root.worker.signal(9); root.starting = false; if (!root.worker.running) root.stopping = false; } }
|
||||
}
|
||||
Reference in new issue
Block a user