From f0ec1cc9b6fc3808351e34f1e22643006ff9fd12 Mon Sep 17 00:00:00 2001 From: Brendan Mulholland Date: Wed, 4 Oct 2023 10:24:47 +0200 Subject: [PATCH] chore: Replace remote for setting auto-open pref --- main.js | 16 ++++++++++------ src/utils/comms.test.ts | 16 ++++++---------- src/utils/comms.ts | 3 +-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/main.js b/main.js index dd9803100..56ffc84ce 100644 --- a/main.js +++ b/main.js @@ -66,8 +66,16 @@ menubarApp.on('ready', () => { } }); + ipcMain.handle('get-platform', async () => { + return process.platform; + }); + ipcMain.handle('get-app-version', async () => { + return app.getVersion(); + }); + ipcMain.on('reopen-window', () => menubarApp.showWindow()); ipcMain.on('hide-window', () => menubarApp.hideWindow()); + ipcMain.on('app-quit', () => menubarApp.app.quit()); ipcMain.on('update-icon', (_, arg) => { if (!menubarApp.tray.isDestroyed()) { @@ -78,12 +86,8 @@ menubarApp.on('ready', () => { } } }); - ipcMain.handle('get-platform', async () => { - return process.platform; - }); - - ipcMain.handle('get-app-version', async () => { - return app.getVersion(); + ipcMain.on('set-login-item-settings', (event, settings) => { + app.setLoginItemSettings(settings); }); menubarApp.window.webContents.on('devtools-opened', () => { diff --git a/src/utils/comms.test.ts b/src/utils/comms.test.ts index 23e3c1fec..8ace7115e 100644 --- a/src/utils/comms.test.ts +++ b/src/utils/comms.test.ts @@ -8,7 +8,7 @@ import { } from './comms'; describe('utils/comms.ts', () => { - beforeEach(function () { + beforeEach(function() { jest.spyOn(ipcRenderer, 'send'); }); @@ -43,24 +43,20 @@ describe('utils/comms.ts', () => { }); it('should setAutoLaunch (true)', () => { - jest.spyOn(remote.app, 'setLoginItemSettings'); - setAutoLaunch(true); - expect(remote.app.setLoginItemSettings).toHaveBeenCalledTimes(1); - expect(remote.app.setLoginItemSettings).toHaveBeenCalledWith({ + + expect(ipcRenderer.send).toHaveBeenCalledWith('set-login-item-settings', { openAtLogin: true, openAsHidden: true, }); }); it('should setAutoLaunch (false)', () => { - jest.spyOn(remote.app, 'setLoginItemSettings'); - setAutoLaunch(false); - expect(remote.app.setLoginItemSettings).toHaveBeenCalledTimes(1); - expect(remote.app.setLoginItemSettings).toHaveBeenCalledWith({ - openAtLogin: false, + + expect(ipcRenderer.send).toHaveBeenCalledWith('set-login-item-settings', { openAsHidden: false, + openAtLogin: false, }); }); }); diff --git a/src/utils/comms.ts b/src/utils/comms.ts index 513073b00..09fe3a30c 100644 --- a/src/utils/comms.ts +++ b/src/utils/comms.ts @@ -1,12 +1,11 @@ import { ipcRenderer, shell } from 'electron'; -import remote from '@electron/remote'; export function openExternalLink(url: string): void { shell.openExternal(url); } export function setAutoLaunch(value: boolean): void { - remote.app.setLoginItemSettings({ + ipcRenderer.send('set-login-item-settings', { openAtLogin: value, openAsHidden: value, });