mirror of
https://github.com/element-hq/element-desktop
synced 2025-03-15 00:47:47 +01:00
tweak for review
This commit is contained in:
parent
1ca888a21c
commit
cd315a55d7
@ -1,29 +1,35 @@
|
||||
|
||||
// Always false if the platform doesn't support it.
|
||||
global.isDoNotDisturb = false;
|
||||
|
||||
const LINUX_SETTING_COMMAND = "gsettings get org.gnome.desktop.notifications show-banners";
|
||||
|
||||
const { promisify } = require('util');
|
||||
const childProcess = require('child_process');
|
||||
const exec = promisify(childProcess.exec);
|
||||
|
||||
let doNotDisturbMode = false;
|
||||
|
||||
function init() {
|
||||
if (process.platform === "linux") {
|
||||
return initForLinux();
|
||||
}
|
||||
}
|
||||
|
||||
async function initForLinux() {
|
||||
// TODO: This is specific to the GNOME desktop implementation of DND
|
||||
function isDoNotDisturb() {
|
||||
return doNotDisturbMode;
|
||||
}
|
||||
|
||||
async function initForLinux() {
|
||||
const DBus = require('dbus-next');
|
||||
const { execSync } = require('child_process');
|
||||
// This is specific to the GNOME implementation for do-not-distrub
|
||||
|
||||
// First we need to determine the value of dnd.
|
||||
try {
|
||||
// XXX: After much flailing about, I couldn't find another acceptable way to fetch this setting value.
|
||||
const value = execSync(LINUX_SETTING_COMMAND, { encoding: "utf-8" }).trim();
|
||||
const value = (await exec(LINUX_SETTING_COMMAND, { encoding: "utf-8" })).trim();
|
||||
if (value) {
|
||||
// Anything other than true will be safely false.
|
||||
// Invert because show-banners === do-disturb :)
|
||||
global.isDoNotDisturb = value !== 'true';
|
||||
console.log(`do-not-disturb value has been detected as: ${global.isDoNotDisturb}`);
|
||||
doNotDisturbMode = value !== 'true';
|
||||
console.log(`do-not-disturb value has been detected as: ${doNotDisturbMode}`);
|
||||
}
|
||||
} catch (ex) {
|
||||
console.warn("Could not execute gsettings command to determine do-not-disturb value. Functionality disabled");
|
||||
@ -33,16 +39,14 @@ async function initForLinux() {
|
||||
|
||||
|
||||
const session = DBus.sessionBus();
|
||||
process.on("exit", () => {
|
||||
session.disconnect();
|
||||
});
|
||||
process.on("exit", () => session.disconnect());
|
||||
const obj = await session.getProxyObject('ca.desrt.dconf', '/ca/desrt/dconf/Writer/user');
|
||||
const signaller = obj.getInterface('ca.desrt.dconf.Writer');
|
||||
signaller.on('Notify', (settingName) => {
|
||||
if (settingName == '/org/gnome/desktop/notifications/show-banners') {
|
||||
// The D-BUS signal will only tell you that the setting changed, but annoyingly
|
||||
// not the value. Since we got the value on startup, assume it's just been toggled.
|
||||
global.isDoNotDisturb = !global.isDoNotDisturb;
|
||||
doNotDisturbMode = !doNotDisturbMode;
|
||||
console.log(`do-not-disturb value has been detected as: ${global.isDoNotDisturb}`);
|
||||
}
|
||||
});
|
||||
@ -50,4 +54,5 @@ async function initForLinux() {
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
isDoNotDisturb,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user