Skip to content

Commit

Permalink
chore(electron): Move off deprecated remote module
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Mulholland committed Oct 3, 2023
1 parent 968ef26 commit a76fa67
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 51 deletions.
2 changes: 2 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
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.

39 changes: 39 additions & 0 deletions src/__mocks__/@electron/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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: {
getVersion: () => '0.0.1',
getLoginItemSettings: jest.fn(),
setLoginItemSettings: () => { },
},
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
}
47 changes: 4 additions & 43 deletions src/__mocks__/electron.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window.Notification = function (title) {
window.Notification = function(title) {
this.title = title;

return {
Expand All @@ -11,62 +11,23 @@ window.Audio = class Audio {
this.path = path;
}

play() {}
play() { }
};

window.localStorage = {
store: {},
getItem: function (key) {
getItem: function(key) {
return this.store[key];
},
setItem: function (key, item) {
setItem: function(key, item) {
this.store[key] = item;
},
removeItem: jest.fn(),
};

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(),
Expand Down
3 changes: 2 additions & 1 deletion src/routes/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useContext } from 'react';
import { ipcRenderer, remote } from 'electron';
import { ipcRenderer } from 'electron';
import remote from '@electron/remote';
import { useNavigate } from 'react-router-dom';
import { ArrowLeftIcon } from '@primer/octicons-react';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosPromise, AxiosResponse } from 'axios';

import { remote } from 'electron';
import remote from '@electron/remote';
const browserWindow = new remote.BrowserWindow();

import * as auth from './auth';
Expand Down
3 changes: 1 addition & 2 deletions src/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { generateGitHubAPIUrl } from './helpers';

const { remote } = require('electron');
const BrowserWindow = remote.BrowserWindow;
const { BrowserWindow } = require('@electron/remote');

import { apiRequest, apiRequestAuth } from '../utils/api-requests';
import { AuthResponse, AuthState, AuthTokenResponse } from '../types';
Expand Down
6 changes: 4 additions & 2 deletions src/utils/comms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
restoreSetting,
} from './comms';

const { ipcRenderer, remote, shell } = require('electron');
const { ipcRenderer, shell } = require('electron');

const remote = require('@electron/remote');

describe('utils/comms.ts', () => {
beforeEach(function () {
beforeEach(function() {
jest.spyOn(ipcRenderer, 'send');
});

Expand Down
3 changes: 2 additions & 1 deletion src/utils/comms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { ipcRenderer, remote, shell } = require('electron');
const { ipcRenderer, shell } = require('electron');
const remote = require('@electron/remote');

export function openExternalLink(url: string): void {
shell.openExternal(url);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { remote } = require('electron');
const remote = require('@electron/remote');

import { openInBrowser } from '../utils/helpers';
import { reOpenWindow, updateTrayIcon } from './comms';
Expand Down

0 comments on commit a76fa67

Please sign in to comment.