diff --git a/main.js b/main.js index 9f03f89a1..7e9ef229c 100644 --- a/main.js +++ b/main.js @@ -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( diff --git a/package.json b/package.json index 9e85b0cd0..a1dce386b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bcbe86733..3b83d9549 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + '@electron/remote': + specifier: ^2.0.11 + version: 2.0.11(electron@13.1.7) '@primer/octicons-react': specifier: 19.8.0 version: 19.8.0(react@18.2.0) @@ -566,6 +569,14 @@ packages: - supports-color dev: true + /@electron/remote@2.0.11(electron@13.1.7): + resolution: {integrity: sha512-PYEs7W3GrQNuhgiMHjFEvL5MbAL6C7m1AwSAHGqC+xc33IdP7rcGtJSdTP2eg1ssyB3oI00KwTsiSlsQbAoXpA==} + peerDependencies: + electron: '>= 13.0.0' + dependencies: + electron: 13.1.7 + dev: false + /@electron/universal@1.4.1: resolution: {integrity: sha512-lE/U3UNw1YHuowNbTmKNs9UlS3En3cPgwM5MI+agIgr/B1hSze9NdOP0qn7boZaI9Lph8IDv3/24g9IxnJP7aQ==} engines: {node: '>=8.6'} diff --git a/src/__mocks__/@electron/remote.js b/src/__mocks__/@electron/remote.js new file mode 100644 index 000000000..7efd1ca9c --- /dev/null +++ b/src/__mocks__/@electron/remote.js @@ -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()), +} diff --git a/src/__mocks__/electron.js b/src/__mocks__/electron.js index 83fd9ad4c..2b77c5938 100644 --- a/src/__mocks__/electron.js +++ b/src/__mocks__/electron.js @@ -1,4 +1,4 @@ -window.Notification = function (title) { +window.Notification = function(title) { this.title = title; return { @@ -11,15 +11,15 @@ 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(), @@ -27,46 +27,7 @@ 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(), diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index a7b929fb6..1e3c118ce 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -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'; diff --git a/src/utils/auth.test.ts b/src/utils/auth.test.ts index 4072e17c7..95d558881 100644 --- a/src/utils/auth.test.ts +++ b/src/utils/auth.test.ts @@ -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'; diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 991b19f55..a5d3d405d 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -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'; diff --git a/src/utils/comms.test.ts b/src/utils/comms.test.ts index ce6ff012b..e607611f8 100644 --- a/src/utils/comms.test.ts +++ b/src/utils/comms.test.ts @@ -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'); }); diff --git a/src/utils/comms.ts b/src/utils/comms.ts index 6b2b5a33c..69c03e48b 100644 --- a/src/utils/comms.ts +++ b/src/utils/comms.ts @@ -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); diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 09350c873..6af31d95e 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -1,4 +1,4 @@ -const { remote } = require('electron'); +const remote = require('@electron/remote'); import { openInBrowser } from '../utils/helpers'; import { reOpenWindow, updateTrayIcon } from './comms';