Skip to content

Commit

Permalink
More robus DND detection on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
hovancik committed Dec 28, 2024
1 parent 009173d commit 1a7bf86
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/utils/dndManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DndManager extends EventEmitter {
this._checkDnd()
log.info('Stretchly: starting Do Not Disturb monitoring')
if (process.platform === 'linux') {
log.info(`System: Your Desktop seems to be ${process.env.ORIGINAL_XDG_CURRENT_DESKTOP}`)
log.info(`System: Your Desktop seems to be ${this._desktopEnviroment}.`)
}
}

Expand All @@ -43,10 +43,16 @@ class DndManager extends EventEmitter {
log.info('Stretchly: stopping Do Not Disturb monitoring')
}

async _isDndEnabledLinux () {
const de = process.env.ORIGINAL_XDG_CURRENT_DESKTOP.toLowerCase()
get _desktopEnviroment () {
// https://github.com/electron/electron/issues/40795
// https://specifications.freedesktop.org/mime-apps-spec/latest/file.html
// https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html
return process.env.ORIGINAL_XDG_CURRENT_DESKTOP ||
process.env.XDG_CURRENT_DESKTOP || 'unknown'
}

async _isDndEnabledLinux () {
const de = this._desktopEnviroment.toLocaleLowerCase()

switch (true) {
case de.includes('kde'):
Expand All @@ -69,7 +75,7 @@ class DndManager extends EventEmitter {
}
} catch (e) { }
break
case de.includes('gnome'):
case de.includes('gnome') || de.includes('unity'):
try {
const exec = this.util.promisify(require('node:child_process').exec)
const { stdout } = await exec('gsettings get org.gnome.desktop.notifications show-banners')
Expand Down Expand Up @@ -100,7 +106,7 @@ class DndManager extends EventEmitter {
return await this._getConfigValue('~/.config/lxqt/notifications.conf', 'doNotDisturb')
default:
if (!this._unsupDEErrorShown) {
log.info(`Stretchly: ${process.env.ORIGINAL_XDG_CURRENT_DESKTOP} not supported for DND detection, yet.`)
log.info(`Stretchly: ${this._desktopEnviroment} not supported for DND detection, yet.`)
this._unsupDEErrorShown = true
}
return false
Expand Down

0 comments on commit 1a7bf86

Please sign in to comment.