bluetooth: fix devices

Also add animation for bar bluetooth devices
This commit is contained in:
2 * r + 2 * t 2025-04-29 20:47:06 +10:00
parent ae878e390f
commit 0d5389a687
2 changed files with 19 additions and 13 deletions

View file

@ -10,6 +10,9 @@ StyledRect {
readonly property color colour: Appearance.colours.rosewater readonly property color colour: Appearance.colours.rosewater
animate: true
clip: true
MaterialIcon { MaterialIcon {
id: network id: network

View file

@ -9,14 +9,17 @@ Singleton {
property bool powered property bool powered
property bool discovering property bool discovering
readonly property list<Device> devices: [] property list<Device> devices: []
readonly property list<Device> connected: devices.filter(d => d.connected) readonly property list<Device> connected: devices.filter(d => d.connected)
Process { Process {
running: true running: true
command: ["bluetoothctl"] command: ["bluetoothctl"]
stdout: SplitParser { stdout: SplitParser {
onRead: getInfo.running = true onRead: {
getInfo.running = true;
getDevices.running = true;
}
} }
} }
@ -35,19 +38,19 @@ Singleton {
Process { Process {
id: getDevices id: getDevices
running: true 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`] 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 { stdout: SplitParser {
onRead: data => { onRead: data => {
const d = JSON.parse(data); const devices = JSON.parse(data);
root.devices.push(deviceComp.createObject(root, { root.devices = devices.map(d => deviceComp.createObject(root, {
name: d.Name, name: d.Name,
alias: d.Alias, alias: d.Alias,
address: d.Address, address: d.Address,
icon: d.Icon, icon: d.Icon,
connected: d.Connected === "yes", connected: d.Connected === "yes",
paired: d.Paired === "yes", paired: d.Paired === "yes",
trusted: d.Trusted === "yes" trusted: d.Trusted === "yes"
})); })).filter(d => d);
} }
} }
} }