[MM-36326][MM-45669] Added Native Node Module support - incl demo to fix DND issue (#2195)
* [MM-36326] Added Native Node Module support - incl demo to fix DND issue * Fix OS per build * Fix to include priority alarms on Windows * Update node command * Fixes for mac (only work on non-MAS build) * Attempt to rebuild properly since electron-builder is having issues with a module * Show me more logs maybe idk * Try with ignore-scripts * Force async to work asyncly * PR feedback and ESLint fixes * Add comment for node-gyp * Revert me: test msi and mac installer * Revert me too * Try reverting back to the old system cause the new one miraculously broke... * Add ignore scripts to makefile * Ignore non-macho files :P * Revert "Revert me too" This reverts commit 074dc9551a2d8ce34a23a3abaeed937d957e8b76. * Revert "Revert me: test msi and mac installer" This reverts commit 0ac998c26a824e7136bdfdc825280a407bb1aa7f.
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
|
||||
import {Notification, shell} from 'electron';
|
||||
|
||||
import {getFocusAssist} from 'windows-focus-assist';
|
||||
import {getDoNotDisturb as getDarwinDoNotDisturb} from 'macos-notification-state';
|
||||
|
||||
import {PLAY_SOUND} from 'common/communication';
|
||||
import {TAB_MESSAGING} from 'common/tabs/TabView';
|
||||
|
||||
@@ -53,6 +56,14 @@ jest.mock('electron', () => {
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('windows-focus-assist', () => ({
|
||||
getFocusAssist: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('macos-notification-state', () => ({
|
||||
getDoNotDisturb: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../windows/windowManager', () => ({
|
||||
getServerNameByWebContentsId: () => 'server_name',
|
||||
sendToRenderer: jest.fn(),
|
||||
@@ -68,6 +79,7 @@ describe('main/notifications', () => {
|
||||
describe('displayMention', () => {
|
||||
beforeEach(() => {
|
||||
Notification.isSupported.mockImplementation(() => true);
|
||||
getFocusAssist.mockReturnValue({value: false});
|
||||
});
|
||||
|
||||
it('should do nothing when Notification is not supported', () => {
|
||||
@@ -85,6 +97,54 @@ describe('main/notifications', () => {
|
||||
expect(Notification.didConstruct).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should do nothing when alarms only is enabled on windows', () => {
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'win32',
|
||||
});
|
||||
|
||||
getFocusAssist.mockReturnValue({value: 2});
|
||||
displayMention(
|
||||
'test',
|
||||
'test body',
|
||||
{id: 'channel_id'},
|
||||
'team_id',
|
||||
'http://server-1.com/team_id/channel_id',
|
||||
false,
|
||||
{id: 1},
|
||||
{},
|
||||
);
|
||||
expect(Notification.didConstruct).not.toBeCalled();
|
||||
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
it('should do nothing when dnd is enabled on mac', () => {
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'darwin',
|
||||
});
|
||||
|
||||
getDarwinDoNotDisturb.mockReturnValue(true);
|
||||
displayMention(
|
||||
'test',
|
||||
'test body',
|
||||
{id: 'channel_id'},
|
||||
'team_id',
|
||||
'http://server-1.com/team_id/channel_id',
|
||||
false,
|
||||
{id: 1},
|
||||
{},
|
||||
);
|
||||
expect(Notification.didConstruct).not.toBeCalled();
|
||||
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
it('should play notification sound when custom sound is provided', () => {
|
||||
displayMention(
|
||||
'test',
|
||||
|
@@ -4,6 +4,9 @@
|
||||
import {shell, Notification} from 'electron';
|
||||
import log from 'electron-log';
|
||||
|
||||
import {getFocusAssist, isPriority} from 'windows-focus-assist';
|
||||
import {getDoNotDisturb as getDarwinDoNotDisturb} from 'macos-notification-state';
|
||||
|
||||
import {MentionData} from 'types/notification';
|
||||
|
||||
import {PLAY_SOUND} from 'common/communication';
|
||||
@@ -24,6 +27,11 @@ export function displayMention(title: string, body: string, channel: {id: string
|
||||
log.error('notification not supported');
|
||||
return;
|
||||
}
|
||||
|
||||
if (getDoNotDisturb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const serverName = WindowManager.getServerNameByWebContentsId(webcontents.id);
|
||||
|
||||
const options = {
|
||||
@@ -72,6 +80,11 @@ export function displayDownloadCompleted(fileName: string, path: string, serverN
|
||||
log.error('notification not supported');
|
||||
return;
|
||||
}
|
||||
|
||||
if (getDoNotDisturb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const download = new DownloadNotification(fileName, serverName);
|
||||
|
||||
download.on('show', () => {
|
||||
@@ -87,6 +100,14 @@ export function displayDownloadCompleted(fileName: string, path: string, serverN
|
||||
let upgrade: NewVersionNotification;
|
||||
|
||||
export function displayUpgrade(version: string, handleUpgrade: () => void): void {
|
||||
if (!Notification.isSupported()) {
|
||||
log.error('notification not supported');
|
||||
return;
|
||||
}
|
||||
if (getDoNotDisturb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (upgrade) {
|
||||
upgrade.close();
|
||||
}
|
||||
@@ -100,6 +121,14 @@ export function displayUpgrade(version: string, handleUpgrade: () => void): void
|
||||
|
||||
let restartToUpgrade;
|
||||
export function displayRestartToUpgrade(version: string, handleUpgrade: () => void): void {
|
||||
if (!Notification.isSupported()) {
|
||||
log.error('notification not supported');
|
||||
return;
|
||||
}
|
||||
if (getDoNotDisturb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
restartToUpgrade = new UpgradeNotification();
|
||||
restartToUpgrade.on('click', () => {
|
||||
log.info(`User requested perform the upgrade now to ${version}`);
|
||||
@@ -107,3 +136,21 @@ export function displayRestartToUpgrade(version: string, handleUpgrade: () => vo
|
||||
});
|
||||
restartToUpgrade.show();
|
||||
}
|
||||
|
||||
function getDoNotDisturb() {
|
||||
if (process.platform === 'win32') {
|
||||
const focusAssistValue = getFocusAssist().value;
|
||||
switch (focusAssistValue) {
|
||||
case 1:
|
||||
return !isPriority('Mattermost.Desktop');
|
||||
default:
|
||||
return focusAssistValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
return getDarwinDoNotDisturb();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user