Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust DND detection on Linux #1538

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.toLowerCase()

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
5 changes: 5 additions & 0 deletions test/dndManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ describe('dndManager', function () {
resolve()
}))

it('should return something for _desktopEnviroment', () => new Promise((resolve) => {
dndManager._desktopEnviroment.should.not.be.equal(null)
resolve()
}))

afterEach(() => {
dndManager.stop()
dndManager = null
Expand Down
Loading