Skip to content

Commit a76fa67

Browse files
author
Brendan Mulholland
committed
chore(electron): Move off deprecated remote module
1 parent 968ef26 commit a76fa67

File tree

11 files changed

+68
-51
lines changed

11 files changed

+68
-51
lines changed

main.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const { autoUpdater } = require('electron-updater');
44
const { onFirstRunMaybe } = require('./first-run');
55
const path = require('path');
66

7+
require('@electron/remote/main').initialize()
8+
79
app.setAppUserModelId('com.electron.gitify');
810

911
const iconIdle = path.join(

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"afterSign": "scripts/notarize.js"
9494
},
9595
"dependencies": {
96+
"@electron/remote": "^2.0.11",
9697
"@primer/octicons-react": "19.8.0",
9798
"axios": "1.5.1",
9899
"date-fns": "2.30.0",

pnpm-lock.yaml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__mocks__/@electron/remote.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let instance;
2+
3+
class BrowserWindow {
4+
constructor() {
5+
if (!instance) {
6+
instance = this;
7+
}
8+
return instance;
9+
}
10+
loadURL = jest.fn();
11+
webContents = {
12+
on: () => { },
13+
session: {
14+
clearStorageData: jest.fn(),
15+
},
16+
};
17+
on() { }
18+
close = jest.fn();
19+
hide = jest.fn();
20+
destroy = jest.fn();
21+
}
22+
23+
const dialog = {
24+
showErrorBox: jest.fn(),
25+
};
26+
27+
module.exports = {
28+
BrowserWindow: BrowserWindow,
29+
dialog: dialog,
30+
process: {
31+
platform: 'darwin',
32+
},
33+
app: {
34+
getVersion: () => '0.0.1',
35+
getLoginItemSettings: jest.fn(),
36+
setLoginItemSettings: () => { },
37+
},
38+
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
39+
}

src/__mocks__/electron.js

+4-43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
window.Notification = function (title) {
1+
window.Notification = function(title) {
22
this.title = title;
33

44
return {
@@ -11,62 +11,23 @@ window.Audio = class Audio {
1111
this.path = path;
1212
}
1313

14-
play() {}
14+
play() { }
1515
};
1616

1717
window.localStorage = {
1818
store: {},
19-
getItem: function (key) {
19+
getItem: function(key) {
2020
return this.store[key];
2121
},
22-
setItem: function (key, item) {
22+
setItem: function(key, item) {
2323
this.store[key] = item;
2424
},
2525
removeItem: jest.fn(),
2626
};
2727

2828
window.alert = jest.fn();
2929

30-
let instance;
31-
32-
class BrowserWindow {
33-
constructor() {
34-
if (!instance) {
35-
instance = this;
36-
}
37-
return instance;
38-
}
39-
loadURL = jest.fn();
40-
webContents = {
41-
on: () => {},
42-
session: {
43-
clearStorageData: jest.fn(),
44-
},
45-
};
46-
on() {}
47-
close = jest.fn();
48-
hide = jest.fn();
49-
destroy = jest.fn();
50-
}
51-
52-
const dialog = {
53-
showErrorBox: jest.fn(),
54-
};
55-
5630
module.exports = {
57-
remote: {
58-
BrowserWindow: BrowserWindow,
59-
dialog: dialog,
60-
process: {
61-
platform: 'darwin',
62-
},
63-
app: {
64-
getVersion: () => '0.0.1',
65-
getLoginItemSettings: jest.fn(),
66-
setLoginItemSettings: () => {},
67-
},
68-
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
69-
},
7031
ipcRenderer: {
7132
send: jest.fn(),
7233
on: jest.fn(),

src/routes/Settings.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useCallback, useContext } from 'react';
2-
import { ipcRenderer, remote } from 'electron';
2+
import { ipcRenderer } from 'electron';
3+
import remote from '@electron/remote';
34
import { useNavigate } from 'react-router-dom';
45
import { ArrowLeftIcon } from '@primer/octicons-react';
56

src/utils/auth.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AxiosPromise, AxiosResponse } from 'axios';
22

3-
import { remote } from 'electron';
3+
import remote from '@electron/remote';
44
const browserWindow = new remote.BrowserWindow();
55

66
import * as auth from './auth';

src/utils/auth.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { generateGitHubAPIUrl } from './helpers';
22

3-
const { remote } = require('electron');
4-
const BrowserWindow = remote.BrowserWindow;
3+
const { BrowserWindow } = require('@electron/remote');
54

65
import { apiRequest, apiRequestAuth } from '../utils/api-requests';
76
import { AuthResponse, AuthState, AuthTokenResponse } from '../types';

src/utils/comms.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import {
66
restoreSetting,
77
} from './comms';
88

9-
const { ipcRenderer, remote, shell } = require('electron');
9+
const { ipcRenderer, shell } = require('electron');
10+
11+
const remote = require('@electron/remote');
1012

1113
describe('utils/comms.ts', () => {
12-
beforeEach(function () {
14+
beforeEach(function() {
1315
jest.spyOn(ipcRenderer, 'send');
1416
});
1517

src/utils/comms.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { ipcRenderer, remote, shell } = require('electron');
1+
const { ipcRenderer, shell } = require('electron');
2+
const remote = require('@electron/remote');
23

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

src/utils/notifications.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { remote } = require('electron');
1+
const remote = require('@electron/remote');
22

33
import { openInBrowser } from '../utils/helpers';
44
import { reOpenWindow, updateTrayIcon } from './comms';

0 commit comments

Comments
 (0)