diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/UnixIPC.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/UnixIPC.qml | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml index 4ec5186c..05a40dbc 100644 --- a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml +++ b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml | |||
@@ -15,26 +15,32 @@ Scope { | |||
15 | handler: Socket { | 15 | handler: Socket { |
16 | parser: SplitParser { | 16 | parser: SplitParser { |
17 | onRead: line => { | 17 | onRead: line => { |
18 | try { | 18 | const command = (() => { |
19 | const command = JSON.parse(line); | 19 | try { |
20 | return JSON.parse(line); | ||
21 | } catch (e) { | ||
22 | console.warn("UnixIPC: Failed to parse command:", line, e); | ||
23 | } | ||
24 | })(); | ||
25 | if (!command) | ||
26 | return; | ||
20 | 27 | ||
21 | if (command.Volume) | 28 | if (command.Volume) |
22 | root.onCommandVolume(command.Volume); | 29 | root.onCommandVolume(command.Volume); |
23 | else if (command.Brightness) | 30 | else if (command.Brightness) |
24 | root.onCommandBrightness(command.Brightness); | 31 | root.onCommandBrightness(command.Brightness); |
25 | else if (command.LockSession) | 32 | else if (command.LockSession) |
26 | Custom.Systemd.lockSession(); | 33 | Custom.Systemd.lockSession(); |
27 | else if (command.Suspend) | 34 | else if (command.Suspend) |
28 | Custom.Systemd.suspend(); | 35 | Custom.Systemd.suspend(); |
29 | else if (command.Hibernate) | 36 | else if (command.Hibernate) |
30 | Custom.Systemd.hibernate(); | 37 | Custom.Systemd.hibernate(); |
31 | else if (command.Mpris) | 38 | else if (command.Mpris) |
32 | root.onCommandMpris(command.Mpris); | 39 | root.onCommandMpris(command.Mpris); |
33 | else | 40 | else if (command.Notifications) |
34 | console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); | 41 | root.onCommandNotifications(command.Notifications); |
35 | } catch (e) { | 42 | else |
36 | console.warn("UnixIPC: Failed to parse command:", line, e); | 43 | console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); |
37 | } | ||
38 | } | 44 | } |
39 | } | 45 | } |
40 | 46 | ||
@@ -75,5 +81,17 @@ Scope { | |||
75 | player.pause(); | 81 | player.pause(); |
76 | }); | 82 | }); |
77 | } | 83 | } |
78 | Binding { target: MprisProxy; } | 84 | Component.onCompleted: { (_ => {})(MprisProxy.players); } |
85 | |||
86 | function onCommandNotifications(command) { | ||
87 | if (command.DismissGroup && NotificationManager.active) { | ||
88 | if (NotificationManager.groups.length > 0) | ||
89 | for (const notif of [...NotificationManager.groups[0]]) | ||
90 | notif.dismiss(); | ||
91 | } | ||
92 | if (command.DismissAll && NotificationManager.active) { | ||
93 | for (const notif of [...NotificationManager.trackedNotifications.values]) | ||
94 | notif.dismiss(); | ||
95 | } | ||
96 | } | ||
79 | } | 97 | } |