bluetooth: lazy update devices
This commit is contained in:
parent
1ed0db3b48
commit
81055262d2
2 changed files with 42 additions and 31 deletions
|
|
@ -9,7 +9,7 @@ Singleton {
|
||||||
|
|
||||||
property bool powered
|
property bool powered
|
||||||
property bool discovering
|
property bool discovering
|
||||||
property list<Device> devices: []
|
readonly property list<Device> devices: []
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
running: true
|
running: true
|
||||||
|
|
@ -41,27 +41,38 @@ Singleton {
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
const devices = JSON.parse(data);
|
const devices = JSON.parse(data);
|
||||||
root.devices = devices.map(d => deviceComp.createObject(root, {
|
const rDevices = root.devices;
|
||||||
name: d.Name,
|
|
||||||
alias: d.Alias,
|
const len = rDevices.length;
|
||||||
address: d.Address,
|
for (let i = 0; i < len; i++) {
|
||||||
icon: d.Icon,
|
const device = rDevices[i];
|
||||||
connected: d.Connected === "yes",
|
if (!devices.find(d => d.address === device?.Address))
|
||||||
paired: d.Paired === "yes",
|
rDevices.splice(i, 1);
|
||||||
trusted: d.Trusted === "yes"
|
}
|
||||||
})).filter(d => d);
|
|
||||||
|
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 {
|
component Device: QtObject {
|
||||||
property string name
|
required property var lastIpcObject
|
||||||
property string alias
|
readonly property string name: lastIpcObject.Name
|
||||||
property string address
|
readonly property string alias: lastIpcObject.Alias
|
||||||
property string icon
|
readonly property string address: lastIpcObject.Address
|
||||||
property bool connected
|
readonly property string icon: lastIpcObject.Icon
|
||||||
property bool paired
|
readonly property bool connected: lastIpcObject.Connected === "yes"
|
||||||
property bool trusted
|
readonly property bool paired: lastIpcObject.Paired === "yes"
|
||||||
|
readonly property bool trusted: lastIpcObject.Trusted === "yes"
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
|
|
||||||
|
|
@ -82,20 +82,20 @@ Singleton {
|
||||||
|
|
||||||
component Client: QtObject {
|
component Client: QtObject {
|
||||||
required property var lastIpcObject
|
required property var lastIpcObject
|
||||||
property string address: lastIpcObject.address
|
readonly property string address: lastIpcObject.address
|
||||||
property string wmClass: lastIpcObject.class
|
readonly property string wmClass: lastIpcObject.class
|
||||||
property string title: lastIpcObject.title
|
readonly property string title: lastIpcObject.title
|
||||||
property string initialClass: lastIpcObject.initialClass
|
readonly property string initialClass: lastIpcObject.initialClass
|
||||||
property string initialTitle: lastIpcObject.initialTitle
|
readonly property string initialTitle: lastIpcObject.initialTitle
|
||||||
property int x: lastIpcObject.at[0]
|
readonly property int x: lastIpcObject.at[0]
|
||||||
property int y: lastIpcObject.at[1]
|
readonly property int y: lastIpcObject.at[1]
|
||||||
property int width: lastIpcObject.size[0]
|
readonly property int width: lastIpcObject.size[0]
|
||||||
property int height: lastIpcObject.size[1]
|
readonly property int height: lastIpcObject.size[1]
|
||||||
property HyprlandWorkspace workspace: Hyprland.workspaces.values.find(w => w.id === lastIpcObject.workspace.id) ?? null
|
readonly property HyprlandWorkspace workspace: Hyprland.workspaces.values.find(w => w.id === lastIpcObject.workspace.id) ?? null
|
||||||
property bool floating: lastIpcObject.floating
|
readonly property bool floating: lastIpcObject.floating
|
||||||
property bool fullscreen: lastIpcObject.fullscreen
|
readonly property bool fullscreen: lastIpcObject.fullscreen
|
||||||
property int pid: lastIpcObject.pid
|
readonly property int pid: lastIpcObject.pid
|
||||||
property int focusHistoryId: lastIpcObject.focusHistoryID
|
readonly property int focusHistoryId: lastIpcObject.focusHistoryID
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue