Skip to content

Commit

Permalink
chore(electron): Move off deprecated remote module (#649)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brendan Mulholland authored Oct 9, 2023
1 parent 51a5aae commit 4d65077
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 144 deletions.
9 changes: 9 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { autoUpdater } = require('electron-updater');
const { onFirstRunMaybe } = require('./first-run');
const path = require('path');

require('@electron/remote/main').initialize()

app.setAppUserModelId('com.electron.gitify');

const iconIdle = path.join(
Expand Down Expand Up @@ -75,6 +77,13 @@ menubarApp.on('ready', () => {
}
}
});
ipcMain.handle('get-platform', async () => {
return process.platform;
});

ipcMain.handle('get-app-version', async () => {
return app.getVersion();
});

menubarApp.window.webContents.on('devtools-opened', () => {
menubarApp.window.setSize(800, 600);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"afterSign": "scripts/notarize.js"
},
"dependencies": {
"@electron/remote": "^2.0.11",
"@primer/octicons-react": "19.8.0",
"axios": "1.5.1",
"date-fns": "2.30.0",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/__mocks__/@electron/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
let instance;

class BrowserWindow {
constructor() {
if (!instance) {
instance = this;
}
return instance;
}
loadURL = jest.fn();
webContents = {
on: () => {},
session: {
clearStorageData: jest.fn(),
},
};
on() {}
close = jest.fn();
hide = jest.fn();
destroy = jest.fn();
}

const dialog = {
showErrorBox: jest.fn(),
};

module.exports = {
BrowserWindow: BrowserWindow,
dialog: dialog,
process: {
platform: 'darwin',
},
app: {
getLoginItemSettings: jest.fn(),
setLoginItemSettings: () => {},
},
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
};
50 changes: 11 additions & 39 deletions src/__mocks__/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,21 @@ window.localStorage = {

window.alert = jest.fn();

let instance;

class BrowserWindow {
constructor() {
if (!instance) {
instance = this;
}
return instance;
}
loadURL = jest.fn();
webContents = {
on: () => {},
session: {
clearStorageData: jest.fn(),
},
};
on() {}
close = jest.fn();
hide = jest.fn();
destroy = jest.fn();
}

const dialog = {
showErrorBox: jest.fn(),
};

module.exports = {
remote: {
BrowserWindow: BrowserWindow,
dialog: dialog,
process: {
platform: 'darwin',
},
app: {
getVersion: () => '0.0.1',
getLoginItemSettings: jest.fn(),
setLoginItemSettings: () => {},
},
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
},
ipcRenderer: {
send: jest.fn(),
on: jest.fn(),
sendSync: jest.fn(),
invoke: jest.fn((channel, ...args) => {
switch (channel) {
case 'get-platform':
return Promise.resolve('darwin');
case 'get-app-version':
return Promise.resolve('0.0.1');
default:
return Promise.reject(new Error(`Unknown channel: ${channel}`));
}
}),
},
shell: {
openExternal: jest.fn(),
Expand Down
Loading

0 comments on commit 4d65077

Please sign in to comment.