summaryrefslogtreecommitdiffstats
path: root/src/lib/DBus.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/DBus.ts')
-rw-r--r--src/lib/DBus.ts69
1 files changed, 67 insertions, 2 deletions
diff --git a/src/lib/DBus.ts b/src/lib/DBus.ts
index bbff405c4..530e30c85 100644
--- a/src/lib/DBus.ts
+++ b/src/lib/DBus.ts
@@ -1,28 +1,92 @@
1import { ipcMain } from 'electron';
2import { comparer } from 'mobx';
3
1import { MessageBus, sessionBus } from 'dbus-next'; 4import { MessageBus, sessionBus } from 'dbus-next';
2import { isLinux } from '../environment'; 5import { isLinux } from '../environment';
3import TrayIcon from './Tray'; 6import TrayIcon from './Tray';
7import Ferdium, { type UnreadServices } from './dbus/Ferdium';
4 8
5export default class DBus { 9export default class DBus {
6 bus: MessageBus | null = null; 10 private bus: MessageBus | null = null;
7 11
8 trayIcon: TrayIcon; 12 trayIcon: TrayIcon;
9 13
14 private ferdium: Ferdium | null = null;
15
16 muted = false;
17
18 unreadDirectMessageCount = 0;
19
20 unreadIndirectMessageCount = 0;
21
22 unreadServices: UnreadServices = [];
23
10 constructor(trayIcon: TrayIcon) { 24 constructor(trayIcon: TrayIcon) {
11 this.trayIcon = trayIcon; 25 this.trayIcon = trayIcon;
26 ipcMain.on('initialAppSettings', (_, appSettings) => {
27 this.updateSettings(appSettings);
28 });
29 ipcMain.on('updateAppSettings', (_, appSettings) => {
30 this.updateSettings(appSettings);
31 });
32 ipcMain.on(
33 'updateDBusUnread',
34 (
35 _,
36 unreadDirectMessageCount,
37 unreadIndirectMessageCount,
38 unreadServices,
39 ) => {
40 this.setUnread(
41 unreadDirectMessageCount,
42 unreadIndirectMessageCount,
43 unreadServices,
44 );
45 },
46 );
47 }
48
49 private updateSettings(appSettings): void {
50 const muted = !!appSettings.data.isAppMuted;
51 if (this.muted !== muted) {
52 this.muted = muted;
53 this.ferdium?.emitMutedChanged();
54 }
12 } 55 }
13 56
14 start() { 57 private setUnread(
58 unreadDirectMessageCount: number,
59 unreadIndirectMessageCount: number,
60 unreadServices: UnreadServices,
61 ): void {
62 if (
63 this.unreadDirectMessageCount !== unreadDirectMessageCount ||
64 this.unreadIndirectMessageCount !== unreadIndirectMessageCount ||
65 !comparer.structural(this.unreadServices, unreadServices)
66 ) {
67 this.unreadDirectMessageCount = unreadDirectMessageCount;
68 this.unreadIndirectMessageCount = unreadIndirectMessageCount;
69 this.unreadServices = unreadServices;
70 this.ferdium?.emitUnreadChanged();
71 }
72 }
73
74 async start() {
15 if (!isLinux || this.bus) { 75 if (!isLinux || this.bus) {
16 return; 76 return;
17 } 77 }
18 78
19 try { 79 try {
20 this.bus = sessionBus(); 80 this.bus = sessionBus();
81 await this.bus.requestName('org.ferdium.Ferdium', 0);
21 } catch { 82 } catch {
22 // Error connecting to the bus. 83 // Error connecting to the bus.
23 return; 84 return;
24 } 85 }
25 86
87 this.ferdium = new Ferdium(this);
88 this.bus.export('/org/ferdium', this.ferdium);
89
26 // HACK Hook onto the MessageBus to track StatusNotifierWatchers 90 // HACK Hook onto the MessageBus to track StatusNotifierWatchers
27 // @ts-expect-error Property '_addMatch' does not exist on type 'MessageBus'. 91 // @ts-expect-error Property '_addMatch' does not exist on type 'MessageBus'.
28 this.bus._addMatch( 92 this.bus._addMatch(
@@ -56,5 +120,6 @@ export default class DBus {
56 120
57 this.bus.disconnect(); 121 this.bus.disconnect();
58 this.bus = null; 122 this.bus = null;
123 this.ferdium = null;
59 } 124 }
60} 125}