Skip to content

Commit 4d65077

Browse files
author
Brendan Mulholland
authored
chore(electron): Move off deprecated remote module (#649)
This is [a requirement for electron v14, which drops the module](https://www.electronjs.org/blog/electron-14-0/#removed-remote-module). We can do it before the upgrade, for smaller changes.
1 parent 51a5aae commit 4d65077

File tree

12 files changed

+243
-144
lines changed

12 files changed

+243
-144
lines changed

main.js

+9
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(
@@ -75,6 +77,13 @@ menubarApp.on('ready', () => {
7577
}
7678
}
7779
});
80+
ipcMain.handle('get-platform', async () => {
81+
return process.platform;
82+
});
83+
84+
ipcMain.handle('get-app-version', async () => {
85+
return app.getVersion();
86+
});
7887

7988
menubarApp.window.webContents.on('devtools-opened', () => {
8089
menubarApp.window.setSize(800, 600);

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

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
getLoginItemSettings: jest.fn(),
35+
setLoginItemSettings: () => {},
36+
},
37+
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
38+
};

src/__mocks__/electron.js

+11-39
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,21 @@ window.localStorage = {
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(),
34+
sendSync: jest.fn(),
35+
invoke: jest.fn((channel, ...args) => {
36+
switch (channel) {
37+
case 'get-platform':
38+
return Promise.resolve('darwin');
39+
case 'get-app-version':
40+
return Promise.resolve('0.0.1');
41+
default:
42+
return Promise.reject(new Error(`Unknown channel: ${channel}`));
43+
}
44+
}),
7345
},
7446
shell: {
7547
openExternal: jest.fn(),

0 commit comments

Comments
 (0)