diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-03-15 17:26:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-15 17:26:13 +0100 |
commit | f1152d3dbb4c6deefea168d66f15f77b7155a5fe (patch) | |
tree | 22c27234b6e3a2dfe47ade037ece47b2533f7039 /src/stores | |
parent | 6.2.6-nightly.5 [skip ci] (diff) | |
download | ferdium-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/stores')
-rw-r--r-- | src/stores/ServicesStore.ts | 52 |
1 files changed, 31 insertions, 21 deletions
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 @@ | |||
1 | import { shell } from 'electron'; | 1 | import { ipcRenderer, shell } from 'electron'; |
2 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; | 2 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; |
3 | import { debounce, remove } from 'lodash'; | 3 | import { debounce, remove } from 'lodash'; |
4 | import ms from 'ms'; | 4 | import ms from 'ms'; |
@@ -23,6 +23,7 @@ import { cleanseJSObject } from '../jsUtils'; | |||
23 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 23 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
24 | import { ferdiumVersion } from '../environment-remote'; | 24 | import { ferdiumVersion } from '../environment-remote'; |
25 | import TypedStore from './lib/TypedStore'; | 25 | import TypedStore from './lib/TypedStore'; |
26 | import type { UnreadServices } from '../lib/dbus/Ferdium'; | ||
26 | 27 | ||
27 | const debug = require('../preload-safe-debug')('Ferdium:ServiceStore'); | 28 | const debug = require('../preload-safe-debug')('Ferdium:ServiceStore'); |
28 | 29 | ||
@@ -1230,26 +1231,29 @@ export default class ServicesStore extends TypedStore { | |||
1230 | const { showMessageBadgeWhenMuted } = this.stores.settings.all.app; | 1231 | const { showMessageBadgeWhenMuted } = this.stores.settings.all.app; |
1231 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; | 1232 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; |
1232 | 1233 | ||
1233 | const unreadDirectMessageCount = this.allDisplayed | 1234 | const unreadServices: UnreadServices = []; |
1234 | .filter( | 1235 | let unreadDirectMessageCount = 0; |
1235 | s => | 1236 | let unreadIndirectMessageCount = 0; |
1236 | (showMessageBadgeWhenMuted || s.isNotificationEnabled) && | 1237 | |
1237 | showMessageBadgesEvenWhenMuted && | 1238 | if (showMessageBadgesEvenWhenMuted) { |
1238 | s.isBadgeEnabled, | 1239 | for (const s of this.allDisplayed) { |
1239 | ) | 1240 | if (s.isBadgeEnabled) { |
1240 | .map(s => s.unreadDirectMessageCount) | 1241 | const direct = |
1241 | .reduce((a, b) => a + b, 0); | 1242 | showMessageBadgeWhenMuted || s.isNotificationEnabled |
1242 | 1243 | ? s.unreadDirectMessageCount | |
1243 | const unreadIndirectMessageCount = this.allDisplayed | 1244 | : 0; |
1244 | .filter( | 1245 | const indirect = |
1245 | s => | 1246 | showMessageBadgeWhenMuted && s.isIndirectMessageBadgeEnabled |
1246 | showMessageBadgeWhenMuted && | 1247 | ? s.unreadIndirectMessageCount |
1247 | showMessageBadgesEvenWhenMuted && | 1248 | : 0; |
1248 | s.isBadgeEnabled && | 1249 | unreadDirectMessageCount += direct; |
1249 | s.isIndirectMessageBadgeEnabled, | 1250 | unreadIndirectMessageCount += indirect; |
1250 | ) | 1251 | if (direct > 0 || indirect > 0) { |
1251 | .map(s => s.unreadIndirectMessageCount) | 1252 | unreadServices.push([s.name, direct, indirect]); |
1252 | .reduce((a, b) => a + b, 0); | 1253 | } |
1254 | } | ||
1255 | } | ||
1256 | } | ||
1253 | 1257 | ||
1254 | // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases | 1258 | // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases |
1255 | if (showMessageBadgesEvenWhenMuted) { | 1259 | if (showMessageBadgesEvenWhenMuted) { |
@@ -1257,6 +1261,12 @@ export default class ServicesStore extends TypedStore { | |||
1257 | unreadDirectMessageCount, | 1261 | unreadDirectMessageCount, |
1258 | unreadIndirectMessageCount, | 1262 | unreadIndirectMessageCount, |
1259 | }); | 1263 | }); |
1264 | ipcRenderer.send( | ||
1265 | 'updateDBusUnread', | ||
1266 | unreadDirectMessageCount, | ||
1267 | unreadIndirectMessageCount, | ||
1268 | unreadServices, | ||
1269 | ); | ||
1260 | } | 1270 | } |
1261 | } | 1271 | } |
1262 | 1272 | ||