From 26b1fa5973fc0a105a62901ba2451af04c10891a Mon Sep 17 00:00:00 2001 From: Brendan Mulholland Date: Wed, 18 Oct 2023 15:30:12 +0200 Subject: [PATCH] chore: Replace remote for setting auto-open pref (#653) Co-authored-by: Afonso Jorge Ramos --- main.js | 16 ++++++++++------ src/utils/comms.test.ts | 15 +++++---------- src/utils/comms.ts | 3 +-- 3 files changed, 16 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..166f5d938 100644 --- a/src/utils/comms.test.ts +++ b/src/utils/comms.test.ts @@ -1,5 +1,4 @@ import { ipcRenderer, shell } from 'electron'; -import remote from '@electron/remote'; import { updateTrayIcon, openExternalLink, @@ -43,24 +42,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, });