mirror of
https://github.com/element-hq/element-desktop
synced 2025-03-15 08:53:31 +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.
|
// 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 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() {
|
function init() {
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
return initForLinux();
|
return initForLinux();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initForLinux() {
|
function isDoNotDisturb() {
|
||||||
// TODO: This is specific to the GNOME desktop implementation of DND
|
return doNotDisturbMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initForLinux() {
|
||||||
const DBus = require('dbus-next');
|
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.
|
// First we need to determine the value of dnd.
|
||||||
try {
|
try {
|
||||||
// XXX: After much flailing about, I couldn't find another acceptable way to fetch this setting value.
|
// 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) {
|
if (value) {
|
||||||
// Anything other than true will be safely false.
|
// Anything other than true will be safely false.
|
||||||
// Invert because show-banners === do-disturb :)
|
// Invert because show-banners === do-disturb :)
|
||||||
global.isDoNotDisturb = value !== 'true';
|
doNotDisturbMode = value !== 'true';
|
||||||
console.log(`do-not-disturb value has been detected as: ${global.isDoNotDisturb}`);
|
console.log(`do-not-disturb value has been detected as: ${doNotDisturbMode}`);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.warn("Could not execute gsettings command to determine do-not-disturb value. Functionality disabled");
|
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();
|
const session = DBus.sessionBus();
|
||||||
process.on("exit", () => {
|
process.on("exit", () => session.disconnect());
|
||||||
session.disconnect();
|
|
||||||
});
|
|
||||||
const obj = await session.getProxyObject('ca.desrt.dconf', '/ca/desrt/dconf/Writer/user');
|
const obj = await session.getProxyObject('ca.desrt.dconf', '/ca/desrt/dconf/Writer/user');
|
||||||
const signaller = obj.getInterface('ca.desrt.dconf.Writer');
|
const signaller = obj.getInterface('ca.desrt.dconf.Writer');
|
||||||
signaller.on('Notify', (settingName) => {
|
signaller.on('Notify', (settingName) => {
|
||||||
if (settingName == '/org/gnome/desktop/notifications/show-banners') {
|
if (settingName == '/org/gnome/desktop/notifications/show-banners') {
|
||||||
// The D-BUS signal will only tell you that the setting changed, but annoyingly
|
// 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.
|
// 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}`);
|
console.log(`do-not-disturb value has been detected as: ${global.isDoNotDisturb}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -50,4 +54,5 @@ async function initForLinux() {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init,
|
init,
|
||||||
|
isDoNotDisturb,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user