Add Control Center integration services
This commit is contained in:
@@ -16,7 +16,8 @@ Singleton {
|
||||
property bool kdeInitialized: false
|
||||
property string previousOutput: ""
|
||||
property string previousBluetooth: ""
|
||||
property string previousKde: ""
|
||||
property bool previousKdeReachable: false
|
||||
property string previousKdeName: ""
|
||||
|
||||
PwObjectTracker { objects: [Pipewire.defaultAudioSink] }
|
||||
|
||||
@@ -33,6 +34,8 @@ Singleton {
|
||||
.join("\u001f");
|
||||
}
|
||||
|
||||
readonly property string kdeName: KdeConnect.preferredPhone?.name ?? ""
|
||||
|
||||
onOutputNameChanged: {
|
||||
if (!root.outputInitialized) {
|
||||
root.previousOutput = root.outputName;
|
||||
@@ -78,55 +81,41 @@ Singleton {
|
||||
onTriggered: {
|
||||
root.previousOutput = root.outputName;
|
||||
root.previousBluetooth = root.bluetoothNames;
|
||||
root.previousKdeReachable = KdeConnect.phoneReachable;
|
||||
root.previousKdeName = root.kdeName;
|
||||
root.outputInitialized = true;
|
||||
root.bluetoothInitialized = true;
|
||||
root.kdeInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 15000
|
||||
repeat: true
|
||||
running: true
|
||||
triggeredOnStart: true
|
||||
onTriggered: {
|
||||
if (!kdeProbe.running)
|
||||
kdeProbe.running = true;
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: KdeConnect
|
||||
|
||||
Process {
|
||||
id: kdeProbe
|
||||
command: ["kdeconnect-cli", "-a", "--name-only"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const names = this.text.split("\n")
|
||||
.map(line => line.trim())
|
||||
.filter(line => line && !/^\d+ devices? found$/.test(line))
|
||||
.sort()
|
||||
.join("\u001f");
|
||||
if (root.kdeInitialized && names !== root.previousKde) {
|
||||
const current = names ? names.split("\u001f") : [];
|
||||
const previous = root.previousKde ? root.previousKde.split("\u001f") : [];
|
||||
const connected = current.find(name => !previous.includes(name));
|
||||
const disconnected = previous.find(name => !current.includes(name));
|
||||
StatusEvents.publish({
|
||||
key: "device-kdeconnect",
|
||||
glyph: "\u{F03F2}",
|
||||
title: connected || disconnected || "Phone",
|
||||
detail: connected ? "KDE Connect available" : "KDE Connect disconnected",
|
||||
tone: connected ? "accent" : "warn",
|
||||
priority: StatusEvents.ambientPriority
|
||||
});
|
||||
}
|
||||
root.previousKde = names;
|
||||
root.kdeInitialized = true;
|
||||
}
|
||||
function onPhoneReachableChanged(): void {
|
||||
if (!root.kdeInitialized)
|
||||
return;
|
||||
const reachable = KdeConnect.phoneReachable;
|
||||
if (reachable === root.previousKdeReachable)
|
||||
return;
|
||||
StatusEvents.publish({
|
||||
key: "device-kdeconnect",
|
||||
glyph: "\u{F03F2}",
|
||||
title: root.kdeName || root.previousKdeName || "Phone",
|
||||
detail: reachable ? "KDE Connect available" : "KDE Connect disconnected",
|
||||
tone: reachable ? "accent" : "warn",
|
||||
priority: StatusEvents.ambientPriority
|
||||
});
|
||||
root.previousKdeReachable = reachable;
|
||||
root.previousKdeName = root.kdeName || root.previousKdeName;
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
root.previousOutput = root.outputName;
|
||||
root.previousBluetooth = root.bluetoothNames;
|
||||
root.previousKdeReachable = KdeConnect.phoneReachable;
|
||||
root.previousKdeName = root.kdeName;
|
||||
discoverySettle.start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user