From 854cbf0bbfd50fc8dd8e786fd05ab3af1cd04262 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 15 May 2023 21:04:29 +0200 Subject: [PATCH 01/27] first try --- app/utils/env.ts | 7 +++++-- package.json | 2 +- webpack.config.renderer.js | 14 ++++---------- yarn.lock | 8 ++++---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/utils/env.ts b/app/utils/env.ts index d8d8436a..1f52518b 100644 --- a/app/utils/env.ts +++ b/app/utils/env.ts @@ -1,8 +1,11 @@ let _isPackaged = process.env.NODE_ENV !== 'test'; if (!['storybook', 'test'].includes(process.env.NODE_ENV!)) { - const { app, remote } = require('electron'); - _isPackaged = Boolean(process.type === 'renderer' ? remote.app.isPackaged : app.isPackaged); + _isPackaged = Boolean( + process.type === 'renderer' + ? require('@electron/remote').app.isPackaged + : require('electron').app.isPackaged + ); } export const isPackaged = _isPackaged; diff --git a/package.json b/package.json index 689f6c17..ae44417a 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,7 @@ "concurrently": "^4.1.1", "cross-env": "^6.0.3", "css-loader": "^3.2.1", - "electron": "^13.6.9", + "electron": "^14.2.9", "electron-builder": "23.6.0", "electron-mocha": "^8.1.0", "electron-notarize": "^1.0.0", diff --git a/webpack.config.renderer.js b/webpack.config.renderer.js index 08613681..ea07da53 100644 --- a/webpack.config.renderer.js +++ b/webpack.config.renderer.js @@ -6,7 +6,6 @@ const glob = require('glob'); const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); -const WriteFilePlugin = require('write-file-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const { mutateWebpackConfig } = require('./webpack.config.common'); @@ -54,19 +53,14 @@ module.exports = (config) => { if (plugin.constructor.name === 'HtmlWebpackPlugin') { plugin.options.chunks = ['worker']; } - - // css filenames must not conflict (default is just 'styles.css') - if (plugin.constructor.name === 'MiniCssExtractPlugin') { - return new MiniCssExtractPlugin({ - filename: '[name].styles.css', - chunkFilename: '[id].styles.css', - }); - } - return plugin; }); config.plugins = config.plugins.concat([ + new MiniCssExtractPlugin({ + filename: '[name].styles.css', + chunkFilename: '[id].styles.css', + }), // generates main window html file new HtmlWebpackPlugin({ chunks: ['mainRenderer'], diff --git a/yarn.lock b/yarn.lock index a863e8d7..ae568e56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9946,10 +9946,10 @@ electron-winstaller@^2.6.4: lodash.template "^4.2.2" temp "^0.8.3" -electron@^13.6.9: - version "13.6.9" - resolved "https://registry.yarnpkg.com/electron/-/electron-13.6.9.tgz#7bd83cc1662ceaaa09dcd132a7b507cec888b028" - integrity sha512-Es/sBy85NIuqsO9MW41PUCpwIkeinlTQ7g0ainfnmRAM2rmog3GBxVCaoV5dzEjwTF7TKG1Yr/E7Z3qHmlfWAg== +electron@^14.2.9: + version "14.2.9" + resolved "https://registry.yarnpkg.com/electron/-/electron-14.2.9.tgz#9e1e95643ec3847592a186e8115d1ddb2e4921ee" + integrity sha512-7LdJFmqVzO9NLKO0hwOwPA6Kv4GSybGMcej8f2q7fVT4O8mIfL9oo/v4axVjVWm0+58ROQtHv8hYnnAs3ygG0Q== dependencies: "@electron/get" "^1.0.1" "@types/node" "^14.6.2" From e81003d8b7fa3143c64063115d86816ad0da322d Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 16 May 2023 08:47:38 +0200 Subject: [PATCH 02/27] fix --- app/main.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/main.ts b/app/main.ts index 0ea787c6..6af5c3c0 100644 --- a/app/main.ts +++ b/app/main.ts @@ -15,12 +15,13 @@ import { getUserAgentForApp, getRefererForApp } from './session'; bootServices(); // all side effects related to services (in main process) +require("@electron/remote/main").initialize(); + const loadWorker = () => { const worker = new BrowserWindow({ webPreferences: { nodeIntegration: true, backgroundThrottling: false, - enableRemoteModule: true, /** * See {@link GenericWindowManager} for details */ @@ -33,6 +34,8 @@ const loadWorker = () => { show: false, }); + require("@electron/remote/main").enable(worker.webContents); + // Used by other renderers (global as any).worker = Object.freeze({ webContentsId: worker.webContents.id, @@ -59,13 +62,13 @@ const loadCliWindow = async (command: string) => { webPreferences: { nodeIntegration: true, backgroundThrottling: false, - enableRemoteModule: true, contextIsolation: false, }, width: 0, height: 0, show: false, }); + require("@electron/remote/main").enable(bw.webContents); await bw.loadURL(getUrlToLoad('cli.html')); From 5e5779e4ad4f003e3def8959f36605f74ee3a637 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 17 May 2023 00:50:25 +0200 Subject: [PATCH 03/27] fix main.ts --- app/main.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/main.ts b/app/main.ts index 6af5c3c0..59b39628 100644 --- a/app/main.ts +++ b/app/main.ts @@ -12,10 +12,12 @@ import services from './services/servicesManager'; import { getUrlToLoad } from './utils/dev'; import { isPackaged } from './utils/env'; import { getUserAgentForApp, getRefererForApp } from './session'; +import { initialize as remoteInitialize, enable as remoteEnable } from '@electron/remote/main'; bootServices(); // all side effects related to services (in main process) -require("@electron/remote/main").initialize(); +//require("@electron/remote/main").initialize(); +remoteInitialize(); const loadWorker = () => { const worker = new BrowserWindow({ @@ -34,7 +36,8 @@ const loadWorker = () => { show: false, }); - require("@electron/remote/main").enable(worker.webContents); + //require("@electron/remote/main").enable(worker.webContents); + remoteEnable(worker.webContents); // Used by other renderers (global as any).worker = Object.freeze({ @@ -68,7 +71,8 @@ const loadCliWindow = async (command: string) => { height: 0, show: false, }); - require("@electron/remote/main").enable(bw.webContents); + // require("@electron/remote/main").enable(bw.webContents); + remoteEnable(bw.webContents); await bw.loadURL(getUrlToLoad('cli.html')); From 7cf67d904a5392b8ef6c2b986021fcf1fb1c9eb3 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 17 May 2023 08:36:53 +0200 Subject: [PATCH 04/27] migrate to @electron/remote --- app/about-window/Presenter.js | 5 +++-- app/app-store/sagas.ts | 4 ++-- app/app-worker.ts | 7 ++++--- app/applications/Application.tsx | 5 +++-- app/applications/components/ConfirmResetApplication.tsx | 5 +++-- app/auto-update/components/AutoUpdateSubdock.tsx | 6 +++--- app/bang/search/providers.ts | 4 ++-- app/cli.ts | 7 ++++--- app/common/components/ElectronWebview.tsx | 4 ++-- app/containers/AppSub.js | 4 ++-- app/database/database.prod.ts | 4 ++-- app/dl-toaster/duck.js | 4 ++-- app/dock/Dock.js | 5 +++-- app/dock/components/TrafficLightsContainer.tsx | 5 +++-- app/downloads/sagas.ts | 5 +++-- app/index-sub.js | 5 +++-- app/onboarding/Onboarding.tsx | 7 ++++--- app/password-managers/providers/onePassword/runtime.ts | 5 +++-- app/plugins/webview-preload.js | 5 +++-- app/services/doc/cli.html | 7 ++++--- app/services/renderer/index.ts | 5 +++-- app/settings/components/SettingsOpenSourceInfo.tsx | 5 +++-- app/settings/components/SettingsPanelGeneral.tsx | 7 ++++--- app/store/configureStore.client.ts | 7 ++++--- app/store/configureStore.worker.ts | 5 +++-- app/tab-webcontents/sagas/close-current-tab.ts | 6 ++++-- app/urlrouter/sagas.ts | 5 +++-- app/utils/AppData.ts | 3 ++- manifests/private.ts | 5 +++-- 29 files changed, 87 insertions(+), 64 deletions(-) diff --git a/app/about-window/Presenter.js b/app/about-window/Presenter.js index 707b67cb..1289807a 100644 --- a/app/about-window/Presenter.js +++ b/app/about-window/Presenter.js @@ -1,4 +1,5 @@ -import { remote } from 'electron'; +//import { remote } from 'electron'; +import { getCurrentWindow as remoteGetCurrentWindow } from '@electron/remote'; import PropTypes from 'prop-types'; import React from 'react'; import injectSheet from 'react-jss'; @@ -64,7 +65,7 @@ class AboutWindowPresenter extends React.PureComponent { return (
{ isDarwin && - remote.getCurrentWindow().close()} /> + remoteGetCurrentWindow().close()} /> }
diff --git a/app/app-store/sagas.ts b/app/app-store/sagas.ts index a91aaeb1..1522f264 100644 --- a/app/app-store/sagas.ts +++ b/app/app-store/sagas.ts @@ -1,4 +1,4 @@ -import { remote } from 'electron'; +import { app as remoteApp } from '@electron/remote'; import * as isBlank from 'is-blank'; import * as _ from 'lodash'; import { SagaIterator } from 'redux-saga'; @@ -108,7 +108,7 @@ function* installAppStoreApplicationIfNotPresent(): SagaIterator { * Will be called once Station launches. */ function* installSlackStationNextIfNextAndNotPresent(): SagaIterator { - const appName = remote.app.name; + const appName = remoteApp.name; if (appName !== 'Station Next') return; const nextSlackAlreadyInstalled: boolean = yield select(hasAlreadyApplicationsForManifest, SLACK_STATION_NEXT_MANIFEST_URL); diff --git a/app/app-worker.ts b/app/app-worker.ts index a294d060..dd8e7fc3 100644 --- a/app/app-worker.ts +++ b/app/app-worker.ts @@ -2,7 +2,8 @@ process.worker = true; // tslint:disable:no-import-side-effect import './dotenv'; -import { ipcRenderer, remote } from 'electron'; +import { ipcRenderer /*, remote */ } from 'electron'; +import { app as remoteApp } from '@electron/remote'; import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory'; import ApolloClient from 'apollo-client'; import { join } from 'path'; @@ -87,7 +88,7 @@ export class BrowserXAppWorker { this.initAutoLaunch().catch(handleError()); } catch (e) { handleError()(e); - remote.app.exit(1); + remoteApp.exit(1); } } @@ -95,7 +96,7 @@ export class BrowserXAppWorker { this.manifestProvider = new ManifestProvider({ // Use native fetch for manifests fetching distantFetcher: new DistantFetcher(), - cachePath: join(remote.app.getPath('userData'), 'ApplicationManifestsCache'), + cachePath: join(remoteApp.getPath('userData'), 'ApplicationManifestsCache'), }); (services.manifest as ManifestServiceImpl).init(this.manifestProvider); diff --git a/app/applications/Application.tsx b/app/applications/Application.tsx index f28e5661..5d74957a 100644 --- a/app/applications/Application.tsx +++ b/app/applications/Application.tsx @@ -6,7 +6,8 @@ import * as slack from 'slack'; import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from 'app/common/components/ElectronWebview'; import classNames from 'classnames'; -import { clipboard, remote } from 'electron'; +import { clipboard /*, remote */ } from 'electron'; +import { webContents as remoteWebContents } from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; import Maybe from 'graphql/tsutils/Maybe'; @@ -382,7 +383,7 @@ class ApplicationImpl extends React.PureComponent { const webview = this.webView.view; webview.addEventListener('did-attach', () => { - const webContents = remote.webContents.fromId(webview.getWebContentsId()); + const webContents = remoteWebContents.fromId(webview.getWebContentsId()); webview.addEventListener('did-navigate-in-page', (e: any) => this.handleDidNavigateInPage(e)); webview.addEventListener('did-navigate', (e: any) => this.handleDidNavigate(e)); diff --git a/app/applications/components/ConfirmResetApplication.tsx b/app/applications/components/ConfirmResetApplication.tsx index a22cabca..4f7709c6 100644 --- a/app/applications/components/ConfirmResetApplication.tsx +++ b/app/applications/components/ConfirmResetApplication.tsx @@ -1,5 +1,6 @@ import { Modal } from '@getstation/theme'; -import { remote } from 'electron'; +//import { remote } from 'electron'; +import { getCurrentWindow as remoteGetCurrentWindow } from '@electron/remote'; import * as React from 'react'; // @ts-ignore: no declaration file import injectSheet from 'react-jss'; @@ -13,7 +14,7 @@ import { resetApplication, ResetApplicationAction } from '../duck'; import { withGetApplication } from '../queries@local.gql.generated'; import { getUIConfirmResetApplicationModalIsVisible } from '../selectors'; -const currentWindowId = remote.getCurrentWindow().id; +const currentWindowId = remoteGetCurrentWindow().id; interface Classes { description: string, diff --git a/app/auto-update/components/AutoUpdateSubdock.tsx b/app/auto-update/components/AutoUpdateSubdock.tsx index 61b48819..31fd21b1 100644 --- a/app/auto-update/components/AutoUpdateSubdock.tsx +++ b/app/auto-update/components/AutoUpdateSubdock.tsx @@ -1,5 +1,5 @@ import { Button, ThemeTypes as Theme } from '@getstation/theme'; -import { remote } from 'electron'; +import { app as remoteApp } from '@electron/remote'; import * as React from 'react'; // @ts-ignore: no declaration file import injectSheet from 'react-jss'; @@ -83,9 +83,9 @@ export default class AutoUpdateSubdock extends React.PureComponent {
-

What's new on {remote.app.name}?

+

What's new on {remoteApp.name}?

- You're now on version {remote.app.getVersion()} + You're now on version {remoteApp.getVersion()}

diff --git a/app/bang/search/providers.ts b/app/bang/search/providers.ts index 8dc749a4..f48fd7b5 100644 --- a/app/bang/search/providers.ts +++ b/app/bang/search/providers.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { LocalStorage } from 'node-localstorage'; -import { remote } from 'electron'; +import { app as remoteApp } from '@electron/remote'; import * as moment from 'moment'; import { reverse } from 'ramda'; import { SDK, activity } from '@getstation/sdk'; @@ -75,7 +75,7 @@ export const createInMemoryStorageProvider = (): FrecencyStorageProvider & { cle }; export const createContextualFrecencyStorageProvider = () => { - const userDataPath = remote.app.getPath('userData'); + const userDataPath = remoteApp.getPath('userData'); const storageProviderPath = path.join(userDataPath, 'frecencyDataStorage'); return new LocalStorage(storageProviderPath); }; diff --git a/app/cli.ts b/app/cli.ts index a5d40c4c..53252453 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -1,6 +1,7 @@ -import { ipcRenderer, remote } from 'electron'; +import { ipcRenderer /*, remote */ } from 'electron'; +import { app as remoteApp, getCurrentWebContents as remoteGetCurrentWebContents } from '@electron/remote'; -const exit = () => remote.app.exit(0); +const exit = () => remoteApp.exit(0); const commands: Record = { database(args: any[]) { @@ -14,6 +15,6 @@ ipcRenderer.on('command', async (_e, command: string, ...args: string[]) => { exit(); } catch (e) { console.error(e); - remote.getCurrentWebContents().openDevTools(); + remoteGetCurrentWebContents().openDevTools(); } }); diff --git a/app/common/components/ElectronWebview.tsx b/app/common/components/ElectronWebview.tsx index fdf13780..2c2df9a0 100644 --- a/app/common/components/ElectronWebview.tsx +++ b/app/common/components/ElectronWebview.tsx @@ -8,7 +8,7 @@ import * as ReactDOM from 'react-dom'; import { logger } from '../../api/logger'; import { Omit } from '../../types'; import { dissoc } from 'ramda'; -import { remote } from 'electron'; +import { webContents as remoteWebContents } from '@electron/remote'; export interface ElectronWebviewProps extends Omit { // webview `src` is updated by the webview itself, so we do not want to @@ -300,7 +300,7 @@ class ElectronWebview extends React.Component { */ forwardKeyboardEvents() { // Inspired by https://github.com/electron/electron/issues/14258#issuecomment-416893856 - remote.webContents + remoteWebContents .fromId(this.view.getWebContentsId()) .on('before-input-event', (_event, input) => { // Create a fake KeyboardEvent from the data provided diff --git a/app/containers/AppSub.js b/app/containers/AppSub.js index aab15d7b..4e217126 100644 --- a/app/containers/AppSub.js +++ b/app/containers/AppSub.js @@ -1,6 +1,6 @@ import { GradientType, withGradient } from '@getstation/theme'; import classNames from 'classnames'; -import { remote } from 'electron'; +import { getCurrentWindow as remoteGetCurrentWindow } from '@electron/remote'; import PropTypes from 'prop-types'; import React from 'react'; import injectSheet from 'react-jss'; @@ -65,7 +65,7 @@ class AppSub extends React.PureComponent { }; componentDidMount() { - this.currentWindowId = remote.getCurrentWindow().id; + this.currentWindowId = remoteGetCurrentWindow().id; } render() { diff --git a/app/database/database.prod.ts b/app/database/database.prod.ts index dd41c3e4..8417c62d 100644 --- a/app/database/database.prod.ts +++ b/app/database/database.prod.ts @@ -1,5 +1,5 @@ import * as cls from 'continuation-local-storage'; -import { app, remote } from 'electron'; +import { app /*, remote */ } from 'electron'; import log from 'electron-log'; import * as mkdirp from 'mkdirp'; import * as path from 'path'; @@ -9,7 +9,7 @@ import operatorsAliases from './operatorsAliases'; const isRenderer = process.type === 'renderer'; export const getDatabaseDir = () => { - const userDataPath = (isRenderer ? (remote.app) : app).getPath('userData'); + const userDataPath = (isRenderer ? require('@electron/remote').app : app).getPath('userData'); const p = path.join(userDataPath, 'db'); mkdirp.sync(p); return p; diff --git a/app/dl-toaster/duck.js b/app/dl-toaster/duck.js index d164e83a..f8537f32 100644 --- a/app/dl-toaster/duck.js +++ b/app/dl-toaster/duck.js @@ -1,4 +1,4 @@ -import { remote } from 'electron'; +import { shell as remoteShell } from '@electron/remote'; import { Set } from 'immutable'; // actions @@ -19,7 +19,7 @@ export const removeToastForDownload = downloadId => ({ export const openDownloadedFile = downloadId => (dispatch, getState) => { const state = getState(); const filePath = state.getIn(['downloads', downloadId, 'filePath']); - remote.shell.openPath(filePath); + remoteShell.openPath(filePath); }; // reducer diff --git a/app/dock/Dock.js b/app/dock/Dock.js index 4da58bd5..c052f4b6 100644 --- a/app/dock/Dock.js +++ b/app/dock/Dock.js @@ -1,7 +1,8 @@ import { updateUI } from 'redux-ui/transpiled/action-reducer'; import classNames from 'classnames'; import memoize from 'memoizee'; -import { remote } from 'electron'; +//import { remote } from 'electron'; +import { getCurrentWindow as remoteGetCurrentWindow } from '@electron/remote'; import mod from 'mod-op'; import PropTypes from 'prop-types'; import { findIndex, prop, propEq, tail } from 'ramda'; @@ -62,7 +63,7 @@ const styles = () => ({ } }); -const onTrafficLightClose = () => remote.getCurrentWindow().close(); +const onTrafficLightClose = () => remoteGetCurrentWindow().close(); @injectSheet(styles) class DockImpl extends React.PureComponent { diff --git a/app/dock/components/TrafficLightsContainer.tsx b/app/dock/components/TrafficLightsContainer.tsx index 990cce03..e3814a61 100644 --- a/app/dock/components/TrafficLightsContainer.tsx +++ b/app/dock/components/TrafficLightsContainer.tsx @@ -1,4 +1,5 @@ -import { remote } from 'electron'; +//import { remote } from 'electron'; +import { getCurrentWindow as remoteGetCurrentWindow } from '@electron/remote'; import * as React from 'react'; import TrafficLights from './TrafficLights'; @@ -17,7 +18,7 @@ export default class TrafficLightsContainer extends React.PureComponent { constructor(props: Props) { super(props); - this.win = remote.getCurrentWindow(); + this.win = remoteGetCurrentWindow(); this.state = { isWindowFocused: this.win.isFocused(), @@ -166,7 +167,7 @@ class OnboardingImpl extends React.PureComponent { } handleCloseWindow() { - remote.getCurrentWindow().close(); + remoteGetCurrentWindow().close(); } handleMinimizeWindow() { diff --git a/app/password-managers/providers/onePassword/runtime.ts b/app/password-managers/providers/onePassword/runtime.ts index dc974828..1612dc90 100644 --- a/app/password-managers/providers/onePassword/runtime.ts +++ b/app/password-managers/providers/onePassword/runtime.ts @@ -6,7 +6,8 @@ import { LoginItem, Session, } from '1password-node'; -import { remote } from 'electron'; +//import { remote } from 'electron'; +import { app as remoteApp } from '@electron/remote'; import { join } from 'path'; import { logger } from '../../../api/logger'; @@ -17,7 +18,7 @@ import { } from '../../types'; import Abstract from '../abstract/runtime'; -const binaryFolderPath = join(remote.app.getPath('userData'), 'Resources', '1PasswordCLI', 'op'); +const binaryFolderPath = join(remoteApp.getPath('userData'), 'Resources', '1PasswordCLI', 'op'); class OnePassword extends Abstract implements IProviderRuntime { private session: Session; diff --git a/app/plugins/webview-preload.js b/app/plugins/webview-preload.js index 430031c8..25b454d2 100644 --- a/app/plugins/webview-preload.js +++ b/app/plugins/webview-preload.js @@ -17,9 +17,10 @@ const protocolsAllowed = [ 'station:', ]; if (micromatch.isMatch(window.location.origin, originsAllowed) || protocolsAllowed.includes(window.location.protocol)) { - const { ipcRenderer, remote } = require('electron'); + const { ipcRenderer /*, remote */ } = require('electron'); + const { getGlobal: remoteGetGlobal } = require('@electron/remote'); const { Observable } = require('rxjs/Rx'); - const workerWebContentsId = remote.getGlobal('worker').webContentsId; + const workerWebContentsId = remoteGetGlobal('worker').webContentsId; const sendPerformToProxy = (channel, payload) => { const p = new Promise(resolve => { diff --git a/app/services/doc/cli.html b/app/services/doc/cli.html index 5dc972df..a1857c22 100644 --- a/app/services/doc/cli.html +++ b/app/services/doc/cli.html @@ -6,14 +6,15 @@