aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/dbus/Ferdium.ts
blob: b2a9105f4e4fa2c3abbedb0ae63512914f0480e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import * as dbus from 'dbus-next';

import type DBus from '../DBus';

export type UnreadServices = [string, number, number][];

export default class Ferdium extends dbus.interface.Interface {
  constructor(private readonly dbus: DBus) {
    super('org.ferdium.Ferdium');
  }

  emitMutedChanged(): void {
    Ferdium.emitPropertiesChanged(this, { Muted: this.dbus.muted }, []);
  }

  get Muted(): boolean {
    return this.dbus.muted;
  }

  set Muted(muted: boolean) {
    if (this.dbus.muted !== muted) {
      this.ToggleMute();
    }
  }

  ToggleMute(): void {
    this.dbus.trayIcon.mainWindow?.webContents.send('muteApp');
  }

  ToggleWindow(): void {
    this.dbus.trayIcon._toggleWindow();
  }

  emitUnreadChanged(): void {
    Ferdium.emitPropertiesChanged(
      this,
      {
        UnreadDirectMessageCount: this.dbus.unreadDirectMessageCount,
        UnreadIndirectMessageCount: this.dbus.unreadIndirectMessageCount,
        UnreadServices: this.dbus.unreadServices,
      },
      [],
    );
  }

  get UnreadDirectMessageCount(): number {
    return this.dbus.unreadDirectMessageCount;
  }

  get UnreadIndirectMessageCount(): number {
    return this.dbus.unreadIndirectMessageCount;
  }

  get UnreadServices(): UnreadServices {
    return this.dbus.unreadServices;
  }
}

Ferdium.configureMembers({
  methods: {
    ToggleMute: {
      inSignature: '',
      outSignature: '',
    },
    ToggleWindow: {
      inSignature: '',
      outSignature: '',
    },
  },
  properties: {
    Muted: {
      signature: 'b',
      access: dbus.interface.ACCESS_READWRITE,
    },
    UnreadDirectMessageCount: {
      signature: 'u',
      access: dbus.interface.ACCESS_READ,
    },
    UnreadIndirectMessageCount: {
      signature: 'u',
      access: dbus.interface.ACCESS_READ,
    },
    UnreadServices: {
      signature: 'a(suu)',
      access: dbus.interface.ACCESS_READ,
    },
  },
});