Skip to content

Commit e7c7df9

Browse files
author
Brendan Mulholland
committed
chore(refactor): Simplify window re-open
1 parent d756682 commit e7c7df9

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

src/utils/comms.test.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
updateTrayIcon,
3-
reOpenWindow,
43
openExternalLink,
54
setAutoLaunch,
65
restoreSetting,
@@ -11,7 +10,7 @@ const { ipcRenderer, shell } = require('electron');
1110
const remote = require('@electron/remote');
1211

1312
describe('utils/comms.ts', () => {
14-
beforeEach(function () {
13+
beforeEach(function() {
1514
jest.spyOn(ipcRenderer, 'send');
1615
});
1716

@@ -33,12 +32,6 @@ describe('utils/comms.ts', () => {
3332
expect(ipcRenderer.send).toHaveBeenCalledWith('update-icon');
3433
});
3534

36-
it('should reopen the window', () => {
37-
reOpenWindow();
38-
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);
39-
expect(ipcRenderer.send).toHaveBeenCalledWith('reopen-window');
40-
});
41-
4235
it('should restore a setting', () => {
4336
restoreSetting('foo', 'bar');
4437
expect(ipcRenderer.send).toHaveBeenCalledTimes(1);

src/utils/comms.ts

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export function updateTrayIcon(notificationsLength = 0): void {
2020
}
2121
}
2222

23-
export function reOpenWindow(): void {
24-
ipcRenderer.send('reopen-window');
25-
}
26-
2723
export function restoreSetting(setting, value): void {
2824
ipcRenderer.send(setting, value);
2925
}

src/utils/notifications.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as _ from 'lodash';
2+
import { ipcRenderer } from 'electron';
23

34
import { generateGitHubWebUrl, getCommentId } from './helpers';
45
import {
@@ -128,15 +129,13 @@ describe('utils/notifications.ts', () => {
128129
});
129130

130131
it('should click on a native notification (with more than 1 notification)', () => {
131-
jest.spyOn(comms, 'reOpenWindow');
132-
133132
const nativeNotification = notificationsHelpers.raiseNativeNotification(
134133
mockedGithubNotifications,
135134
mockAccounts,
136135
);
137136
nativeNotification.onclick(null);
138137

139-
expect(comms.reOpenWindow).toHaveBeenCalledTimes(1);
138+
expect(ipcRenderer.send).toHaveBeenCalledWith('reopen-window');
140139
});
141140

142141
it('should play a sound', () => {

src/utils/notifications.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const remote = require('@electron/remote');
2-
1+
import { ipcRenderer } from 'electron';
32
import { openInBrowser } from '../utils/helpers';
4-
import { reOpenWindow, updateTrayIcon } from './comms';
3+
import { updateTrayIcon } from './comms';
54
import { Notification } from '../typesGithub';
65

76
import { AccountNotifications, SettingsState, AuthState } from '../types';
@@ -67,9 +66,8 @@ export const raiseNativeNotification = (
6766

6867
if (notifications.length === 1) {
6968
const notification = notifications[0];
70-
title = `${process.platform !== 'win32' ? 'Gitify - ' : ''}${
71-
notification.repository.full_name
72-
}`;
69+
title = `${process.platform !== 'win32' ? 'Gitify - ' : ''}${notification.repository.full_name
70+
}`;
7371
body = notification.subject.title;
7472
} else {
7573
title = 'Gitify';
@@ -81,12 +79,12 @@ export const raiseNativeNotification = (
8179
silent: true,
8280
});
8381

84-
nativeNotification.onclick = function () {
82+
nativeNotification.onclick = function() {
8583
if (notifications.length === 1) {
8684
remote.getCurrentWindow().hide();
8785
openInBrowser(notifications[0], accounts);
8886
} else {
89-
reOpenWindow();
87+
ipcRenderer.send('reopen-window');
9088
}
9189
};
9290

0 commit comments

Comments
 (0)