Skip to content

Commit 26b1fa5

Browse files
Brendan Mulhollandafonsojramos
Brendan Mulholland
andauthored
chore: Replace remote for setting auto-open pref (#653)
Co-authored-by: Afonso Jorge Ramos <[email protected]>
1 parent 9150830 commit 26b1fa5

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

main.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ menubarApp.on('ready', () => {
6666
}
6767
});
6868

69+
ipcMain.handle('get-platform', async () => {
70+
return process.platform;
71+
});
72+
ipcMain.handle('get-app-version', async () => {
73+
return app.getVersion();
74+
});
75+
6976
ipcMain.on('reopen-window', () => menubarApp.showWindow());
7077
ipcMain.on('hide-window', () => menubarApp.hideWindow());
78+
7179
ipcMain.on('app-quit', () => menubarApp.app.quit());
7280
ipcMain.on('update-icon', (_, arg) => {
7381
if (!menubarApp.tray.isDestroyed()) {
@@ -78,12 +86,8 @@ menubarApp.on('ready', () => {
7886
}
7987
}
8088
});
81-
ipcMain.handle('get-platform', async () => {
82-
return process.platform;
83-
});
84-
85-
ipcMain.handle('get-app-version', async () => {
86-
return app.getVersion();
89+
ipcMain.on('set-login-item-settings', (event, settings) => {
90+
app.setLoginItemSettings(settings);
8791
});
8892

8993
menubarApp.window.webContents.on('devtools-opened', () => {

src/utils/comms.test.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ipcRenderer, shell } from 'electron';
2-
import remote from '@electron/remote';
32
import {
43
updateTrayIcon,
54
openExternalLink,
@@ -43,24 +42,20 @@ describe('utils/comms.ts', () => {
4342
});
4443

4544
it('should setAutoLaunch (true)', () => {
46-
jest.spyOn(remote.app, 'setLoginItemSettings');
47-
4845
setAutoLaunch(true);
49-
expect(remote.app.setLoginItemSettings).toHaveBeenCalledTimes(1);
50-
expect(remote.app.setLoginItemSettings).toHaveBeenCalledWith({
46+
47+
expect(ipcRenderer.send).toHaveBeenCalledWith('set-login-item-settings', {
5148
openAtLogin: true,
5249
openAsHidden: true,
5350
});
5451
});
5552

5653
it('should setAutoLaunch (false)', () => {
57-
jest.spyOn(remote.app, 'setLoginItemSettings');
58-
5954
setAutoLaunch(false);
60-
expect(remote.app.setLoginItemSettings).toHaveBeenCalledTimes(1);
61-
expect(remote.app.setLoginItemSettings).toHaveBeenCalledWith({
62-
openAtLogin: false,
55+
56+
expect(ipcRenderer.send).toHaveBeenCalledWith('set-login-item-settings', {
6357
openAsHidden: false,
58+
openAtLogin: false,
6459
});
6560
});
6661
});

src/utils/comms.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { ipcRenderer, shell } from 'electron';
2-
import remote from '@electron/remote';
32

43
export function openExternalLink(url: string): void {
54
shell.openExternal(url);
65
}
76

87
export function setAutoLaunch(value: boolean): void {
9-
remote.app.setLoginItemSettings({
8+
ipcRenderer.send('set-login-item-settings', {
109
openAtLogin: value,
1110
openAsHidden: value,
1211
});

0 commit comments

Comments
 (0)