From f1152d3dbb4c6deefea168d66f15f77b7155a5fe Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 15 Mar 2023 17:26:13 +0100 Subject: Basic D-Bus API (#866) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * 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 * docs: D-Bus usage example Signed-off-by: Kristóf Marussy * 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 * 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 Co-authored-by: Victor Bonnelle --- src/lib/dbus/Ferdium.ts | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/lib/dbus/Ferdium.ts (limited to 'src/lib/dbus') 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 @@ +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, + }, + }, +}); -- cgit v1.2.3-70-g09d2