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/stores/ServicesStore.ts | 52 +++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'src/stores/ServicesStore.ts') diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index 0ab4dbc5b..829c64d76 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts @@ -1,4 +1,4 @@ -import { shell } from 'electron'; +import { ipcRenderer, shell } from 'electron'; import { action, reaction, computed, observable, makeObservable } from 'mobx'; import { debounce, remove } from 'lodash'; import ms from 'ms'; @@ -23,6 +23,7 @@ import { cleanseJSObject } from '../jsUtils'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; import { ferdiumVersion } from '../environment-remote'; import TypedStore from './lib/TypedStore'; +import type { UnreadServices } from '../lib/dbus/Ferdium'; const debug = require('../preload-safe-debug')('Ferdium:ServiceStore'); @@ -1230,26 +1231,29 @@ export default class ServicesStore extends TypedStore { const { showMessageBadgeWhenMuted } = this.stores.settings.all.app; const { showMessageBadgesEvenWhenMuted } = this.stores.ui; - const unreadDirectMessageCount = this.allDisplayed - .filter( - s => - (showMessageBadgeWhenMuted || s.isNotificationEnabled) && - showMessageBadgesEvenWhenMuted && - s.isBadgeEnabled, - ) - .map(s => s.unreadDirectMessageCount) - .reduce((a, b) => a + b, 0); - - const unreadIndirectMessageCount = this.allDisplayed - .filter( - s => - showMessageBadgeWhenMuted && - showMessageBadgesEvenWhenMuted && - s.isBadgeEnabled && - s.isIndirectMessageBadgeEnabled, - ) - .map(s => s.unreadIndirectMessageCount) - .reduce((a, b) => a + b, 0); + const unreadServices: UnreadServices = []; + let unreadDirectMessageCount = 0; + let unreadIndirectMessageCount = 0; + + if (showMessageBadgesEvenWhenMuted) { + for (const s of this.allDisplayed) { + if (s.isBadgeEnabled) { + const direct = + showMessageBadgeWhenMuted || s.isNotificationEnabled + ? s.unreadDirectMessageCount + : 0; + const indirect = + showMessageBadgeWhenMuted && s.isIndirectMessageBadgeEnabled + ? s.unreadIndirectMessageCount + : 0; + unreadDirectMessageCount += direct; + unreadIndirectMessageCount += indirect; + if (direct > 0 || indirect > 0) { + unreadServices.push([s.name, direct, indirect]); + } + } + } + } // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases if (showMessageBadgesEvenWhenMuted) { @@ -1257,6 +1261,12 @@ export default class ServicesStore extends TypedStore { unreadDirectMessageCount, unreadIndirectMessageCount, }); + ipcRenderer.send( + 'updateDBusUnread', + unreadDirectMessageCount, + unreadIndirectMessageCount, + unreadServices, + ); } } -- cgit v1.2.3-70-g09d2