diff options
Diffstat (limited to 'services/Bluetooth.qml')
| -rw-r--r-- | services/Bluetooth.qml | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/services/Bluetooth.qml b/services/Bluetooth.qml index 43f3636..f5e9de1 100644 --- a/services/Bluetooth.qml +++ b/services/Bluetooth.qml @@ -24,31 +24,47 @@ Singleton { Process { id: getInfo + running: true - command: ["sh", "-c", "bluetoothctl show | paste -s"] - stdout: SplitParser { - onRead: data => { - root.powered = data.includes("Powered: yes"); - root.discovering = data.includes("Discovering: yes"); + command: ["bluetoothctl", "show"] + stdout: StdioCollector { + onStreamFinished: { + root.powered = text.includes("Powered: yes"); + root.discovering = text.includes("Discovering: yes"); } } } Process { id: getDevices + running: true - command: ["fish", "-c", `for a in (bluetoothctl devices | cut -d ' ' -f 2); bluetoothctl info $a | jq -R 'reduce (inputs / ":") as [$key, $value] ({}; .[$key | ltrimstr("\t")] = ($value | ltrimstr(" ")))' | jq -c --arg addr $a '.Address = $addr'; end | jq -sc`] - stdout: SplitParser { - onRead: data => { - const devices = JSON.parse(data).filter(d => d.Name); + command: ["fish", "-c", ` + for a in (bluetoothctl devices) + if string match -q 'Device *' $a + bluetoothctl info $addr (string split ' ' $a)[2] + echo + end + end`] + stdout: StdioCollector { + onStreamFinished: { + const devices = text.trim().split("\n\n").map(d => ({ + name: d.match(/Name: (.*)/)[1], + alias: d.match(/Alias: (.*)/)[1], + address: d.match(/Device ([0-9A-Z:]{17})/)[1], + icon: d.match(/Icon: (.*)/)[1], + connected: d.includes("Connected: yes"), + paired: d.includes("Paired: yes"), + trusted: d.includes("Trusted: yes") + })); const rDevices = root.devices; - const destroyed = rDevices.filter(rd => !devices.find(d => d.Address === rd.address)); + const destroyed = rDevices.filter(rd => !devices.find(d => d.address === rd.address)); for (const device of destroyed) rDevices.splice(rDevices.indexOf(device), 1).forEach(d => d.destroy()); for (const device of devices) { - const match = rDevices.find(d => d.address === device.Address); + const match = rDevices.find(d => d.address === device.address); if (match) { match.lastIpcObject = device; } else { @@ -63,13 +79,13 @@ Singleton { component Device: QtObject { 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" + 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 + readonly property bool paired: lastIpcObject.paired + readonly property bool trusted: lastIpcObject.trusted } Component { |