Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(electron): Move off deprecated remote module #649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const config = {
"preset": "ts-jest/presets/js-with-ts",
"setupFiles": [
"<rootDir>/src/__helpers__/setupEnvVars.js"
],
"testEnvironment": "jsdom",
"coverageThreshold": {
"global": {
"lines": 90
}
},
"moduleNameMapper": {
// Force CommonJS build for http adapter to be available.
// via https://github.com/axios/axios/issues/5101#issuecomment-1276572468
'^axios$': require.resolve('axios'),
},
}

module.exports = config;
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
15 changes: 2 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@
"url": "https://github.com/manosim/gitify/issues"
},
"homepage": "https://www.gitify.io/",
"jest": {
"preset": "ts-jest/presets/js-with-ts",
"setupFiles": [
"<rootDir>/src/__helpers__/setupEnvVars.js"
],
"testEnvironment": "jsdom",
"coverageThreshold": {
"global": {
"lines": 90
}
}
},
"build": {
"appId": "com.electron.gitify",
"productName": "Gitify",
Expand Down Expand Up @@ -105,8 +93,9 @@
"afterSign": "scripts/notarize.js"
},
"dependencies": {
"@electron/remote": "^2.0.11",
"@primer/octicons-react": "19.8.0",
"axios": "0.27.2",
"axios": "1.5.1",
"date-fns": "2.30.0",
"electron-updater": "6.1.4",
"final-form": "4.20.10",
Expand Down
24 changes: 20 additions & 4 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
4 changes: 3 additions & 1 deletion src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { mockedUser } from '../__mocks__/mockedData';

describe('hooks/useNotifications.ts', () => {
beforeEach(() => {
axios.defaults.adapter = require('axios/lib/adapters/http');
// axios will default to using the XHR adapter which can't be intercepted
// by nock. So, configure axios to use the node adapter.
axios.defaults.adapter = 'http';
});

describe('fetchNotifications', () => {
Expand Down
Loading