Skip to content

Commit

Permalink
chore(refactor): Simplify window re-open (#651)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Afonso Jorge Ramos <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2023
1 parent 08406c2 commit ede8030
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
7 changes: 0 additions & 7 deletions src/utils/comms.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
updateTrayIcon,
reOpenWindow,
openExternalLink,
setAutoLaunch,
restoreSetting,
Expand Down Expand Up @@ -33,12 +32,6 @@ describe('utils/comms.ts', () => {
expect(ipcRenderer.send).toHaveBeenCalledWith('update-icon');
});

it('should reopen the window', () => {
reOpenWindow();
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
expect(ipcRenderer.send).toHaveBeenCalledWith('reopen-window');
});

it('should restore a setting', () => {
restoreSetting('foo', 'bar');
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
Expand Down
4 changes: 0 additions & 4 deletions src/utils/comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export function updateTrayIcon(notificationsLength = 0): void {
}
}

export function reOpenWindow(): void {
ipcRenderer.send('reopen-window');
}

export function restoreSetting(setting, value): void {
ipcRenderer.send(setting, value);
}
5 changes: 2 additions & 3 deletions src/utils/notifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
import { ipcRenderer } from 'electron';

import { generateGitHubWebUrl, getCommentId } from './helpers';
import {
Expand Down Expand Up @@ -128,15 +129,13 @@ describe('utils/notifications.ts', () => {
});

it('should click on a native notification (with more than 1 notification)', () => {
jest.spyOn(comms, 'reOpenWindow');

const nativeNotification = notificationsHelpers.raiseNativeNotification(
mockedGithubNotifications,
mockAccounts,
);
nativeNotification.onclick(null);

expect(comms.reOpenWindow).toHaveBeenCalledTimes(1);
expect(ipcRenderer.send).toHaveBeenCalledWith('reopen-window');
});

it('should play a sound', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ipcRenderer } from 'electron';
const remote = require('@electron/remote');

import { openInBrowser } from '../utils/helpers';
import { reOpenWindow, updateTrayIcon } from './comms';
import { updateTrayIcon } from './comms';
import { Notification } from '../typesGithub';

import { AccountNotifications, SettingsState, AuthState } from '../types';
Expand Down Expand Up @@ -86,7 +87,7 @@ export const raiseNativeNotification = (
remote.getCurrentWindow().hide();
openInBrowser(notifications[0], accounts);
} else {
reOpenWindow();
ipcRenderer.send('reopen-window');
}
};

Expand Down

0 comments on commit ede8030

Please sign in to comment.