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, 39 insertions, 19 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml index e7b7b673..05a40dbc 100644 --- a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml +++ b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml | |||
@@ -4,6 +4,7 @@ import Quickshell.Services.Pipewire | |||
4 | import Quickshell.Services.Mpris | 4 | import Quickshell.Services.Mpris |
5 | import qs.Services | 5 | import qs.Services |
6 | import Custom as Custom | 6 | import Custom as Custom |
7 | import QtQml | ||
7 | 8 | ||
8 | Scope { | 9 | Scope { |
9 | id: root | 10 | id: root |
@@ -14,26 +15,32 @@ Scope { | |||
14 | handler: Socket { | 15 | handler: Socket { |
15 | parser: SplitParser { | 16 | parser: SplitParser { |
16 | onRead: line => { | 17 | onRead: line => { |
17 | try { | 18 | const command = (() => { |
18 | 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; | ||
19 | 27 | ||
20 | if (command.Volume) | 28 | if (command.Volume) |
21 | root.onCommandVolume(command.Volume); | 29 | root.onCommandVolume(command.Volume); |
22 | else if (command.Brightness) | 30 | else if (command.Brightness) |
23 | root.onCommandBrightness(command.Brightness); | 31 | root.onCommandBrightness(command.Brightness); |
24 | else if (command.LockSession) | 32 | else if (command.LockSession) |
25 | Custom.Systemd.lockSession(); | 33 | Custom.Systemd.lockSession(); |
26 | else if (command.Suspend) | 34 | else if (command.Suspend) |
27 | Custom.Systemd.suspend(); | 35 | Custom.Systemd.suspend(); |
28 | else if (command.Hibernate) | 36 | else if (command.Hibernate) |
29 | Custom.Systemd.hibernate(); | 37 | Custom.Systemd.hibernate(); |
30 | else if (command.Mpris) | 38 | else if (command.Mpris) |
31 | root.onCommandMpris(command.Mpris); | 39 | root.onCommandMpris(command.Mpris); |
32 | else | 40 | else if (command.Notifications) |
33 | console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); | 41 | root.onCommandNotifications(command.Notifications); |
34 | } catch (e) { | 42 | else |
35 | console.warn("UnixIPC: Failed to parse command:", line, e); | 43 | console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); |
36 | } | ||
37 | } | 44 | } |
38 | } | 45 | } |
39 | 46 | ||
@@ -74,4 +81,17 @@ Scope { | |||
74 | player.pause(); | 81 | player.pause(); |
75 | }); | 82 | }); |
76 | } | 83 | } |
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 | } | ||
77 | } | 97 | } |