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 4, 2023
1 parent 1cd043a commit 369befe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 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
18 changes: 6 additions & 12 deletions src/utils/comms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import {

const { ipcRenderer, shell } = require('electron');

const remote = require('@electron/remote');

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

Expand Down Expand Up @@ -45,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,
});
});
});
6 changes: 1 addition & 5 deletions src/utils/comms.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
const { ipcRenderer, shell } = require('electron');
const remote = require('@electron/remote');

export function openExternalLink(url: string): void {
shell.openExternal(url);
}

export function setAutoLaunch(value: boolean): void {
remote.app.setLoginItemSettings({
openAtLogin: value,
openAsHidden: value,
});
ipcRenderer.send('set-login-item-settings', { openAtLogin: value, openAsHidden: value });
}

export function updateTrayIcon(notificationsLength = 0): void {
Expand Down

0 comments on commit 369befe

Please sign in to comment.