summaryrefslogtreecommitdiff
path: root/services/Bluetooth.qml
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-30 17:28:30 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-30 17:28:30 +1000
commit81055262d2cc6b762fa48772b7462d3e79e0f084 (patch)
tree5e67357a86cb45f6850e6eda695e411c9f9567bf /services/Bluetooth.qml
parentbar: animate bluetooth devices (diff)
downloadcaelestia-shell-81055262d2cc6b762fa48772b7462d3e79e0f084.tar.gz
caelestia-shell-81055262d2cc6b762fa48772b7462d3e79e0f084.tar.bz2
caelestia-shell-81055262d2cc6b762fa48772b7462d3e79e0f084.zip
bluetooth: lazy update devices
Diffstat (limited to 'services/Bluetooth.qml')
-rw-r--r--services/Bluetooth.qml45
1 files changed, 28 insertions, 17 deletions
diff --git a/services/Bluetooth.qml b/services/Bluetooth.qml
index 7cdd457..4092212 100644
--- a/services/Bluetooth.qml
+++ b/services/Bluetooth.qml
@@ -9,7 +9,7 @@ Singleton {
property bool powered
property bool discovering
- property list<Device> devices: []
+ readonly property list<Device> devices: []
Process {
running: true
@@ -41,27 +41,38 @@ Singleton {
stdout: SplitParser {
onRead: data => {
const devices = JSON.parse(data);
- root.devices = devices.map(d => deviceComp.createObject(root, {
- name: d.Name,
- alias: d.Alias,
- address: d.Address,
- icon: d.Icon,
- connected: d.Connected === "yes",
- paired: d.Paired === "yes",
- trusted: d.Trusted === "yes"
- })).filter(d => d);
+ const rDevices = root.devices;
+
+ const len = rDevices.length;
+ for (let i = 0; i < len; i++) {
+ const device = rDevices[i];
+ if (!devices.find(d => d.address === device?.Address))
+ rDevices.splice(i, 1);
+ }
+
+ for (const device of devices) {
+ const match = rDevices.find(d => d.address === device.Address);
+ if (match) {
+ match.lastIpcObject = device;
+ } else {
+ rDevices.push(deviceComp.createObject(root, {
+ lastIpcObject: device
+ }));
+ }
+ }
}
}
}
component Device: QtObject {
- property string name
- property string alias
- property string address
- property string icon
- property bool connected
- property bool paired
- property bool trusted
+ required property var lastIpcObject
+ readonly property string name: lastIpcObject.Name
+ readonly property string alias: lastIpcObject.Alias
+ readonly property string address: lastIpcObject.Address
+ readonly property string icon: lastIpcObject.Icon
+ readonly property bool connected: lastIpcObject.Connected === "yes"
+ readonly property bool paired: lastIpcObject.Paired === "yes"
+ readonly property bool trusted: lastIpcObject.Trusted === "yes"
}
Component {