[MM-36456] Add support for Gnome's do-not-disturb (#2278)
* Add support for gnome do-not-disturb mode * Add tests * Invert condition
This commit is contained in:
parent
d5cf3e76e1
commit
cf647ce3e9
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
@ -20,6 +20,7 @@
|
|||
"filechooser",
|
||||
"flac",
|
||||
"FOCALBOARD",
|
||||
"gsettings",
|
||||
"ICONNAME",
|
||||
"loadscreen",
|
||||
"mmjstool",
|
||||
|
|
23
src/main/notifications/dnd-linux.ts
Normal file
23
src/main/notifications/dnd-linux.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {execSync} from 'child_process';
|
||||
|
||||
import log from 'electron-log';
|
||||
|
||||
const GNOME_READ_DND = 'gsettings get org.gnome.desktop.notifications show-banners';
|
||||
|
||||
function getLinuxDoNotDisturb() {
|
||||
try {
|
||||
const showNotifications = execSync(GNOME_READ_DND).toString().replace('\n', '');
|
||||
log.debug('getLinuxDoNotDisturb', {showNotifications});
|
||||
|
||||
return showNotifications !== 'true';
|
||||
} catch (error) {
|
||||
log.error('getLinuxDoNotDisturb Error:', {error});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default getLinuxDoNotDisturb;
|
|
@ -2,6 +2,7 @@
|
|||
// See LICENSE.txt for license information.
|
||||
|
||||
'use strict';
|
||||
import cp from 'child_process';
|
||||
|
||||
import {Notification, shell} from 'electron';
|
||||
|
||||
|
@ -15,10 +16,16 @@ import {localizeMessage} from 'main/i18nManager';
|
|||
|
||||
import WindowManager from '../windows/windowManager';
|
||||
|
||||
import getLinuxDoNotDisturb from './dnd-linux';
|
||||
|
||||
import {displayMention, displayDownloadCompleted, currentNotifications} from './index';
|
||||
|
||||
const mentions = [];
|
||||
|
||||
jest.mock('child_process', () => ({
|
||||
execSync: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('electron', () => {
|
||||
class NotificationMock {
|
||||
static isSupported = jest.fn();
|
||||
|
@ -231,4 +238,23 @@ describe('main/notifications', () => {
|
|||
expect(shell.showItemInFolder).toHaveBeenCalledWith('/path/to/file');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLinuxDoNotDisturb', () => {
|
||||
it('should return false', () => {
|
||||
cp.execSync.mockReturnValue('true');
|
||||
expect(getLinuxDoNotDisturb()).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if error is thrown', () => {
|
||||
cp.execSync.mockImplementation(() => {
|
||||
throw Error('error');
|
||||
});
|
||||
expect(getLinuxDoNotDisturb()).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
cp.execSync.mockReturnValue('false');
|
||||
expect(getLinuxDoNotDisturb()).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ import WindowManager from '../windows/windowManager';
|
|||
import {Mention} from './Mention';
|
||||
import {DownloadNotification} from './Download';
|
||||
import {NewVersionNotification, UpgradeNotification} from './Upgrade';
|
||||
import getLinuxDoNotDisturb from './dnd-linux';
|
||||
|
||||
export const currentNotifications = new Map();
|
||||
|
||||
|
@ -152,5 +153,9 @@ function getDoNotDisturb() {
|
|||
return getDarwinDoNotDisturb();
|
||||
}
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
return getLinuxDoNotDisturb();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue