From 4ecd7fe5654c9f1c40d2ee1c3b9606507091b974 Mon Sep 17 00:00:00 2001 From: Jan Hovancik Date: Thu, 19 Dec 2024 20:49:06 +0100 Subject: [PATCH] Improve DND for Linux --- CHANGELOG.md | 1 + app/utils/dndManager.js | 72 +++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d9373b4..697cb004e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - improved break window loading +- improve DND detection for Linux - updated many translations - better icons for "Show time in tray" - `showBreakActionsInStrictMode` migrated to `showTrayMenuInStrictMode` diff --git a/app/utils/dndManager.js b/app/utils/dndManager.js index 54a0f99a9..1293711fe 100644 --- a/app/utils/dndManager.js +++ b/app/utils/dndManager.js @@ -9,6 +9,8 @@ class DndManager extends EventEmitter { this.timer = null this.isOnDnd = false + this._unsupDEErrorShown = false + if (process.platform === 'win32') { this.windowsFocusAssist = require('windows-focus-assist') this.windowsQuietHours = require('windows-quiet-hours') @@ -42,39 +44,47 @@ class DndManager extends EventEmitter { } async _isDndEnabledLinux () { - try { - const obj = await this.bus.getProxyObject('org.freedesktop.Notifications', '/org/freedesktop/Notifications') - const properties = obj.getInterface('org.freedesktop.DBus.Properties') - const dndEnabled = await properties.Get('org.freedesktop.Notifications', 'Inhibited') - if (await dndEnabled.value) { - return true - } - } catch (e) { - // KDE is not running - } - - try { - const obj = await this.bus.getProxyObject('org.xfce.Xfconf', '/org/xfce/Xfconf') - const properties = obj.getInterface('org.xfce.Xfconf') - const dndEnabled = await properties.GetProperty('xfce4-notifyd', '/do-not-disturb') - if (await dndEnabled.value) { - return true - } - } catch (e) { - // XFCE is not running - } + const de = process.env.XDG_CURRENT_DESKTOP + // https://specifications.freedesktop.org/mime-apps-spec/latest/file.html + // https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html - try { - const exec = this.util.promisify(require('node:child_process').exec) - const { stdout } = await exec('gsettings get org.gnome.desktop.notifications show-banners') - if (stdout.replace(/[^0-9a-zA-Z]/g, '') === 'false') { - return true - } - } catch (e) { - // Gnome / gsettings is not running + switch (true) { + case de.includes('KDE'): + try { + const obj = await this.bus.getProxyObject('org.freedesktop.Notifications', '/org/freedesktop/Notifications') + const properties = obj.getInterface('org.freedesktop.DBus.Properties') + const dndEnabled = await properties.Get('org.freedesktop.Notifications', 'Inhibited') + if (await dndEnabled.value) { + return true + } + } catch (e) {} + break + case de.includes('XFCE'): + try { + const obj = await this.bus.getProxyObject('org.xfce.Xfconf', '/org/xfce/Xfconf') + const properties = obj.getInterface('org.xfce.Xfconf') + const dndEnabled = await properties.GetProperty('xfce4-notifyd', '/do-not-disturb') + if (await dndEnabled.value) { + return true + } + } catch (e) {} + break + case de.includes('GNOME'): + try { + const exec = this.util.promisify(require('node:child_process').exec) + const { stdout } = await exec('gsettings get org.gnome.desktop.notifications show-banners') + if (stdout.replace(/[^0-9a-zA-Z]/g, '') === 'false') { + return true + } + } catch (e) {} + break + default: + if (!this._unsupDEErrorShown) { + log.info(`Stretchly: ${process.env.XDG_CURRENT_DESKTOP} not supported for DND detection, yet.`) + this._unsupDEErrorShown = true + } + return false } - - return false } async _doNotDisturb () {