Skip to content

Commit

Permalink
chore: Replace remote for setting auto-open pref
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Mulholland committed Oct 10, 2023
1 parent d8a35aa commit f0ec1cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
16 changes: 10 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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', () => {
Expand Down
16 changes: 6 additions & 10 deletions src/utils/comms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './comms';

describe('utils/comms.ts', () => {
beforeEach(function () {
beforeEach(function() {
jest.spyOn(ipcRenderer, 'send');
});

Expand Down Expand Up @@ -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,
});
});
});
3 changes: 1 addition & 2 deletions src/utils/comms.ts
Original file line number Diff line number Diff line change
@@ -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,
});
Expand Down

0 comments on commit f0ec1cc

Please sign in to comment.