[MM-58455] Add error handling when FocusStatus is not authorized on macOS (#3053)
* [MM-58455] Add error handling when FocusStatus is not authorized on macOS * Do the permission check very early so that it's less likely for users to miss it * Move permissions check to initialize
This commit is contained in:
parent
923df7c187
commit
d11752e195
|
@ -143,6 +143,7 @@ jest.mock('main/CriticalErrorHandler', () => ({
|
|||
}));
|
||||
jest.mock('main/notifications', () => ({
|
||||
displayDownloadCompleted: jest.fn(),
|
||||
getDoNotDisturb: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/ParseArgs', () => jest.fn());
|
||||
jest.mock('common/servers/serverManager', () => ({
|
||||
|
|
|
@ -47,6 +47,7 @@ import {configPath, updatePaths} from 'main/constants';
|
|||
import CriticalErrorHandler from 'main/CriticalErrorHandler';
|
||||
import downloadsManager from 'main/downloadsManager';
|
||||
import i18nManager from 'main/i18nManager';
|
||||
import {getDoNotDisturb} from 'main/notifications';
|
||||
import parseArgs from 'main/ParseArgs';
|
||||
import PermissionsManager from 'main/permissionsManager';
|
||||
import Tray from 'main/tray/tray';
|
||||
|
@ -374,6 +375,9 @@ async function initializeAfterAppReady() {
|
|||
}
|
||||
}
|
||||
|
||||
// Call this to initiate a permissions check for DND state
|
||||
getDoNotDisturb();
|
||||
|
||||
// listen for status updates and pass on to renderer
|
||||
UserActivityMonitor.on('status', (status) => {
|
||||
log.debug('UserActivityMonitor.on(status)', status);
|
||||
|
|
|
@ -35,7 +35,7 @@ const mentions: Array<{body: string; value: any}> = [];
|
|||
jest.mock('child_process', () => ({
|
||||
execSync: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('electron-is-dev', () => false);
|
||||
jest.mock('electron', () => {
|
||||
class NotificationMock {
|
||||
callbackMap: Map<string, () => void>;
|
||||
|
@ -137,6 +137,7 @@ describe('main/notifications', () => {
|
|||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
mentions.length = 0;
|
||||
Config.notifications = {
|
||||
flashWindow: 0,
|
||||
bounceIcon: false,
|
||||
|
@ -156,7 +157,7 @@ describe('main/notifications', () => {
|
|||
{id: 1} as WebContents,
|
||||
'',
|
||||
);
|
||||
expect(MainWindow.show).not.toBeCalled();
|
||||
expect(mentions.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should do nothing when alarms only is enabled on windows', async () => {
|
||||
|
@ -176,7 +177,7 @@ describe('main/notifications', () => {
|
|||
{id: 1} as WebContents,
|
||||
'',
|
||||
);
|
||||
expect(MainWindow.show).not.toBeCalled();
|
||||
expect(mentions.length).toBe(0);
|
||||
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
|
@ -200,7 +201,35 @@ describe('main/notifications', () => {
|
|||
{id: 1} as WebContents,
|
||||
'',
|
||||
);
|
||||
expect(MainWindow.show).not.toBeCalled();
|
||||
expect(mentions.length).toBe(0);
|
||||
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
it('should still show notification when dnd permission on mac is not authorized', async () => {
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'darwin',
|
||||
});
|
||||
|
||||
getDarwinDoNotDisturb.mockImplementation(() => {
|
||||
throw new Error('Unauthorized');
|
||||
});
|
||||
await NotificationManager.displayMention(
|
||||
'test',
|
||||
'test body',
|
||||
'channel_id',
|
||||
'team_id',
|
||||
'http://server-1.com/team_id/channel_id',
|
||||
false,
|
||||
{id: 1} as WebContents,
|
||||
'',
|
||||
);
|
||||
expect(mentions.length).toBe(1);
|
||||
const mention = mentions[0];
|
||||
expect(mention.value.show).toHaveBeenCalled();
|
||||
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
|
@ -219,7 +248,7 @@ describe('main/notifications', () => {
|
|||
{id: 1} as WebContents,
|
||||
'',
|
||||
);
|
||||
expect(MainWindow.show).not.toBeCalled();
|
||||
expect(mentions.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should play notification sound when custom sound is provided', async () => {
|
||||
|
|
|
@ -197,14 +197,20 @@ class NotificationManager {
|
|||
}
|
||||
}
|
||||
|
||||
async function getDoNotDisturb() {
|
||||
export async function getDoNotDisturb() {
|
||||
if (process.platform === 'win32') {
|
||||
return getWindowsDoNotDisturb();
|
||||
}
|
||||
|
||||
// We have to turn this off for dev mode because the Electron binary doesn't have the focus center API entitlement
|
||||
if (process.platform === 'darwin' && !isDev) {
|
||||
return getDarwinDoNotDisturb();
|
||||
try {
|
||||
const dnd = await getDarwinDoNotDisturb();
|
||||
return dnd;
|
||||
} catch (e) {
|
||||
log.warn('macOS DND check threw an error', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
|
|
Loading…
Reference in a new issue