aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/dbus
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-03-15 17:26:13 +0100
committerLibravatar GitHub <noreply@github.com>2023-03-15 17:26:13 +0100
commitf1152d3dbb4c6deefea168d66f15f77b7155a5fe (patch)
tree22c27234b6e3a2dfe47ade037ece47b2533f7039 /src/lib/dbus
parent6.2.6-nightly.5 [skip ci] (diff)
downloadferdium-app-f1152d3dbb4c6deefea168d66f15f77b7155a5fe.tar.gz
ferdium-app-f1152d3dbb4c6deefea168d66f15f77b7155a5fe.tar.zst
ferdium-app-f1152d3dbb4c6deefea168d66f15f77b7155a5fe.zip
Basic D-Bus API (#866)
* feat: basic D-Bus API Expose muted state and the number of unread message over D-Bus when running on Linux. This is useful for, e.g., displaying notifications on a window manager status bar. Signed-off-by: Kristóf Marussy <kristof@marussy.com> * docs: create docs directory Move the documentation to a separate directory so that new documentation can be added into one place. We keep the following files still in the repository root by convention: * CHANGELOG.md * CODE_OF_CONDUCT.md * CONTRIBUTING.md * LICENSE.md * README.md * SECURITY.md Signed-off-by: Kristóf Marussy <kristof@marussy.com> * docs: D-Bus usage example Signed-off-by: Kristóf Marussy <kristof@marussy.com> * fix: remove unneeded D-Bus signals Only notify clients that the message counts or the mute status has changed if there actually was a change. Signed-off-by: Kristóf Marussy <kristof@marussy.com> * docs: rewrite sample bar client * docs: better unread --services help * docs: update dbus docs * docs: use ferdium-dbus in dbus bar example * docs: make command argument required in bar example --------- Signed-off-by: Kristóf Marussy <kristof@marussy.com> Co-authored-by: Victor Bonnelle <victor.bonnelle@protonmail.com>
Diffstat (limited to 'src/lib/dbus')
-rw-r--r--src/lib/dbus/Ferdium.ts88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/lib/dbus/Ferdium.ts b/src/lib/dbus/Ferdium.ts
new file mode 100644
index 000000000..b2a9105f4
--- /dev/null
+++ b/src/lib/dbus/Ferdium.ts
@@ -0,0 +1,88 @@
1import * as dbus from 'dbus-next';
2
3import type DBus from '../DBus';
4
5export type UnreadServices = [string, number, number][];
6
7export default class Ferdium extends dbus.interface.Interface {
8 constructor(private readonly dbus: DBus) {
9 super('org.ferdium.Ferdium');
10 }
11
12 emitMutedChanged(): void {
13 Ferdium.emitPropertiesChanged(this, { Muted: this.dbus.muted }, []);
14 }
15
16 get Muted(): boolean {
17 return this.dbus.muted;
18 }
19
20 set Muted(muted: boolean) {
21 if (this.dbus.muted !== muted) {
22 this.ToggleMute();
23 }
24 }
25
26 ToggleMute(): void {
27 this.dbus.trayIcon.mainWindow?.webContents.send('muteApp');
28 }
29
30 ToggleWindow(): void {
31 this.dbus.trayIcon._toggleWindow();
32 }
33
34 emitUnreadChanged(): void {
35 Ferdium.emitPropertiesChanged(
36 this,
37 {
38 UnreadDirectMessageCount: this.dbus.unreadDirectMessageCount,
39 UnreadIndirectMessageCount: this.dbus.unreadIndirectMessageCount,
40 UnreadServices: this.dbus.unreadServices,
41 },
42 [],
43 );
44 }
45
46 get UnreadDirectMessageCount(): number {
47 return this.dbus.unreadDirectMessageCount;
48 }
49
50 get UnreadIndirectMessageCount(): number {
51 return this.dbus.unreadIndirectMessageCount;
52 }
53
54 get UnreadServices(): UnreadServices {
55 return this.dbus.unreadServices;
56 }
57}
58
59Ferdium.configureMembers({
60 methods: {
61 ToggleMute: {
62 inSignature: '',
63 outSignature: '',
64 },
65 ToggleWindow: {
66 inSignature: '',
67 outSignature: '',
68 },
69 },
70 properties: {
71 Muted: {
72 signature: 'b',
73 access: dbus.interface.ACCESS_READWRITE,
74 },
75 UnreadDirectMessageCount: {
76 signature: 'u',
77 access: dbus.interface.ACCESS_READ,
78 },
79 UnreadIndirectMessageCount: {
80 signature: 'u',
81 access: dbus.interface.ACCESS_READ,
82 },
83 UnreadServices: {
84 signature: 'a(suu)',
85 access: dbus.interface.ACCESS_READ,
86 },
87 },
88});