Skip to content

Commit

Permalink
Downcase to be sure + Cinnamon
Browse files Browse the repository at this point in the history
  • Loading branch information
hovancik committed Dec 23, 2024
1 parent 4ecd7fe commit e27529c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
41 changes: 34 additions & 7 deletions app/utils/dndManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,51 @@ class DndManager extends EventEmitter {
}

async _isDndEnabledLinux () {
const de = process.env.XDG_CURRENT_DESKTOP
const de = process.env.XDG_CURRENT_DESKTOP.toLowerCase()
// https://specifications.freedesktop.org/mime-apps-spec/latest/file.html
// https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html

switch (true) {
case de.includes('KDE'):
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) {}
} catch (e) { }
break
case de.includes('XFCE'):
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) {}
} catch (e) { }
break
case de.includes('GNOME'):
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) {}
} catch (e) { }
break
case de.includes('cinnamon'):
try {
const exec = this.util.promisify(require('node:child_process').exec)
const { stdout } = await exec('gsettings get org.cinnamon.desktop.notifications display-notifications')
if (stdout.replace(/[^0-9a-zA-Z]/g, '') === 'false') {
return true
}
} catch (e) { }
break
case de.includes('lxqt'):
return await this._getConfigValue('~/.config/lxqt/notifications.conf', 'doNotDisturb')
default:
if (!this._unsupDEErrorShown) {
log.info(`Stretchly: ${process.env.XDG_CURRENT_DESKTOP} not supported for DND detection, yet.`)
Expand Down Expand Up @@ -107,6 +118,22 @@ class DndManager extends EventEmitter {
}
}

async _getConfigValue (filePath, key) {
try {
const data = await require('fs').promises.readFile(filePath, 'utf8')
const lines = data.split('\n')
for (const line of lines) {
const [configKey, value] = line.split('=')
if (configKey.trim() === key) {
return value.trim().toLowerCase() === 'true'
}
}
return false
} catch (e) {
return false
}
}

_checkDnd () {
this.timer = setInterval(async () => {
const doNotDisturb = await this._doNotDisturb()
Expand Down
8 changes: 8 additions & 0 deletions test/dndManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ describe('dndManager', function () {
resolve()
}))

it('should find correct value of LXQt config file', () => new Promise((resolve) => {
dndManager._getConfigValue(join(__dirname, '/test-lxqt.conf'), 'doNotDisturb')
.then(x => {
x.should.be.equal(true)
})
resolve()
}))

afterEach(() => {
dndManager.stop()
dndManager = null
Expand Down
8 changes: 8 additions & 0 deletions test/test-lxqt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[General]
doNotDisturb=true
placement=bottom-right
screenWithMouse=false
server_decides=10
spacing=8
unattendedMaxNum=0
width=640

0 comments on commit e27529c

Please sign in to comment.