diff --git a/app/lib/app.ts b/app/lib/app.ts index 1a7ca2a4..63382ee9 100644 --- a/app/lib/app.ts +++ b/app/lib/app.ts @@ -1,5 +1,7 @@ import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions } from 'electron' import * as promiseIpc from 'electron-promise-ipc' +import * as remote from '@electron/remote/main' + import { loadConfig } from './config' import { Window, WindowOptions } from './window' import { pluginManager } from './pluginManager' @@ -9,6 +11,8 @@ export class Application { private windows: Window[] = [] constructor () { + remote.initialize() + ipcMain.on('app:config-change', (_event, config) => { this.broadcast('host:config-change', config) }) diff --git a/app/lib/portable.ts b/app/lib/portable.ts index 0b92b1c5..367e15da 100755 --- a/app/lib/portable.ts +++ b/app/lib/portable.ts @@ -1,12 +1,8 @@ import * as path from 'path' import * as fs from 'fs' +import * as electron from 'electron' -let appPath: string | null = null -try { - appPath = path.dirname(require('electron').app.getPath('exe')) -} catch { - appPath = path.dirname(require('electron').remote.app.getPath('exe')) -} +const appPath = path.dirname(electron.app.getPath('exe')) if (fs.existsSync(path.join(appPath, 'terminus-data'))) { fs.renameSync(path.join(appPath, 'terminus-data'), path.join(appPath, 'data')) @@ -14,9 +10,5 @@ if (fs.existsSync(path.join(appPath, 'terminus-data'))) { const portableData = path.join(appPath, 'data') if (fs.existsSync(portableData)) { console.log('reset user data to ' + portableData) - try { - require('electron').app.setPath('userData', portableData) - } catch { - require('electron').remote.app.setPath('userData', portableData) - } + electron.app.setPath('userData', portableData) } diff --git a/app/lib/sentry.ts b/app/lib/sentry.ts index d87c9538..57912449 100755 --- a/app/lib/sentry.ts +++ b/app/lib/sentry.ts @@ -1,16 +1,14 @@ const { init } = String(process.type) === 'main' ? require('@sentry/electron/dist/main') : require('@sentry/electron/dist/renderer') -import * as isDev from 'electron-is-dev' - const SENTRY_DSN = 'https://4717a0a7ee0b4429bd3a0f06c3d7eec3@sentry.io/181876' let release = null try { release = require('electron').app.getVersion() } catch { - release = require('electron').remote.app.getVersion() + release = require('@electron/remote').app.getVersion() } -if (!isDev) { +if (!process.env.TERMINUS_DEV) { init({ dsn: SENTRY_DSN, release, diff --git a/app/package.json b/app/package.json index e6f092ec..94b4a1e9 100644 --- a/app/package.json +++ b/app/package.json @@ -21,11 +21,11 @@ "@angular/forms": "^11.1.1", "@angular/platform-browser": "^11.1.1", "@angular/platform-browser-dynamic": "^11.1.1", + "@electron/remote": "^1.0.4", "@ng-bootstrap/ng-bootstrap": "^7.0.0", "@terminus-term/node-pty": "0.10.0-terminus.3", "electron-config": "2.0.0", "electron-debug": "^3.2.0", - "electron-is-dev": "1.2.0", "electron-promise-ipc": "^2.2.4", "fontmanager-redux": "1.0.0", "glasstron": "0.0.7", diff --git a/app/src/entry.ts b/app/src/entry.ts index 4a6a446c..75073e61 100644 --- a/app/src/entry.ts +++ b/app/src/entry.ts @@ -2,8 +2,6 @@ import 'zone.js' import 'core-js/proposals/reflect-metadata' import 'rxjs' -import * as isDev from 'electron-is-dev' - import './global.scss' import './toastr.scss' @@ -23,7 +21,7 @@ if (process.platform === 'win32' && !('HOME' in process.env)) { process.env.HOME = `${process.env.HOMEDRIVE}${process.env.HOMEPATH}` } -if (isDev) { +if (process.env.TERMINUS_DEV) { console.warn('Running in debug mode') } else { enableProdMode() @@ -39,7 +37,7 @@ async function bootstrap (plugins: PluginInfo[], safeMode = false): Promise { - if (isDev) { + if (process.env.TERMINUS_DEV) { const applicationRef = moduleRef.injector.get(ApplicationRef) const componentRef = applicationRef.components[0] enableDebugTools(componentRef) diff --git a/app/src/plugins.ts b/app/src/plugins.ts index 8a8b2586..a15fa31d 100644 --- a/app/src/plugins.ts +++ b/app/src/plugins.ts @@ -1,5 +1,6 @@ import * as fs from 'mz/fs' import * as path from 'path' +import * as remote from '@electron/remote' const nodeModule = require('module') // eslint-disable-line @typescript-eslint/no-var-requires const nodeRequire = (global as any).require @@ -15,13 +16,13 @@ function normalizePath (p: string): string { global['module'].paths.map((x: string) => nodeModule.globalPaths.push(normalizePath(x))) if (process.env.TERMINUS_DEV) { - nodeModule.globalPaths.unshift(path.dirname(require('electron').remote.app.getAppPath())) + nodeModule.globalPaths.unshift(path.dirname(remote.app.getAppPath())) } -const builtinPluginsPath = process.env.TERMINUS_DEV ? path.dirname(require('electron').remote.app.getAppPath()) : path.join((process as any).resourcesPath, 'builtin-plugins') +const builtinPluginsPath = process.env.TERMINUS_DEV ? path.dirname(remote.app.getAppPath()) : path.join((process as any).resourcesPath, 'builtin-plugins') const userPluginsPath = path.join( - require('electron').remote.app.getPath('userData'), + remote.app.getPath('userData'), 'plugins', ) diff --git a/app/webpack.config.js b/app/webpack.config.js index 315204ad..0c814904 100644 --- a/app/webpack.config.js +++ b/app/webpack.config.js @@ -68,7 +68,6 @@ module.exports = { '@ng-bootstrap/ng-bootstrap': 'commonjs @ng-bootstrap/ng-bootstrap', child_process: 'commonjs child_process', electron: 'commonjs electron', - 'electron-is-dev': 'commonjs electron-is-dev', fs: 'commonjs fs', 'ngx-toastr': 'commonjs ngx-toastr', module: 'commonjs module', diff --git a/app/yarn.lock b/app/yarn.lock index 88362554..6a02be12 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -51,6 +51,11 @@ dependencies: tslib "^2.0.0" +"@electron/remote@^1.0.4": + version "1.0.4" + resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-1.0.4.tgz#f1c8cf3560bab762b462bfae9991919cced8bc33" + integrity sha512-kguDJRhL3ZynHrkbX8Tr7xoAzGsNgh4eqXkycXb6cgXbOgehGqkBVe+MnjSVMXz3QJykerGKPy28gqcM7AFGYw== + "@iarna/cli@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@iarna/cli/-/cli-1.2.0.tgz#0f7af5e851afe895104583c4ca07377a8094d641" diff --git a/terminus-core/package.json b/terminus-core/package.json index a2bd221b..5f655b11 100644 --- a/terminus-core/package.json +++ b/terminus-core/package.json @@ -17,6 +17,7 @@ "author": "Eugene Pankov", "license": "MIT", "devDependencies": { + "@electron/remote": "^1.0.4", "@types/js-yaml": "^4.0.0", "@types/shell-escape": "^0.2.0", "@types/winston": "^2.3.6", diff --git a/terminus-core/src/components/tabHeader.component.ts b/terminus-core/src/components/tabHeader.component.ts index 91f10bcd..1c1c9183 100644 --- a/terminus-core/src/components/tabHeader.component.ts +++ b/terminus-core/src/components/tabHeader.component.ts @@ -105,7 +105,7 @@ export class TabHeaderComponent { if ($event.which === 3) { $event.preventDefault() - const contextMenu = this.electron.remote.Menu.buildFromTemplate(await this.buildContextMenu()) + const contextMenu = this.electron.Menu.buildFromTemplate(await this.buildContextMenu()) contextMenu.popup({ x: $event.pageX, diff --git a/terminus-core/src/services/electron.service.ts b/terminus-core/src/services/electron.service.ts index 8a362982..63d1fa86 100644 --- a/terminus-core/src/services/electron.service.ts +++ b/terminus-core/src/services/electron.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core' import { App, IpcRenderer, Shell, Dialog, Clipboard, GlobalShortcut, Screen, Remote, AutoUpdater, TouchBar, BrowserWindow, Menu, MenuItem, NativeImage, MessageBoxOptions } from 'electron' +import * as remote from '@electron/remote' export interface MessageBoxResponse { response: number @@ -17,30 +18,31 @@ export class ElectronService { nativeImage: typeof NativeImage screen: Screen remote: Remote + process: any autoUpdater: AutoUpdater TouchBar: typeof TouchBar BrowserWindow: typeof BrowserWindow Menu: typeof Menu MenuItem: typeof MenuItem - private electron: any /** @hidden */ private constructor () { - this.electron = require('electron') - this.remote = this.electron.remote - this.app = this.remote.app - this.screen = this.remote.screen - this.dialog = this.remote.dialog - this.shell = this.electron.shell - this.clipboard = this.electron.clipboard - this.ipcRenderer = this.electron.ipcRenderer - this.globalShortcut = this.remote.globalShortcut - this.nativeImage = this.remote.nativeImage - this.autoUpdater = this.remote.autoUpdater - this.TouchBar = this.remote.TouchBar - this.BrowserWindow = this.remote.BrowserWindow - this.Menu = this.remote.Menu - this.MenuItem = this.remote.MenuItem + const electron = require('electron') + this.shell = electron.shell + this.clipboard = electron.clipboard + this.ipcRenderer = electron.ipcRenderer + + this.process = remote.process + this.app = remote.app + this.screen = remote.screen + this.dialog = remote.dialog + this.globalShortcut = remote.globalShortcut + this.nativeImage = remote.nativeImage + this.autoUpdater = remote.autoUpdater + this.TouchBar = remote.TouchBar + this.BrowserWindow = remote.BrowserWindow + this.Menu = remote.Menu + this.MenuItem = remote.MenuItem } async showMessageBox ( diff --git a/terminus-core/yarn.lock b/terminus-core/yarn.lock index 0df6edd6..d545f50b 100644 --- a/terminus-core/yarn.lock +++ b/terminus-core/yarn.lock @@ -11,6 +11,11 @@ enabled "2.0.x" kuler "^2.0.0" +"@electron/remote@^1.0.4": + version "1.0.4" + resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-1.0.4.tgz#f1c8cf3560bab762b462bfae9991919cced8bc33" + integrity sha512-kguDJRhL3ZynHrkbX8Tr7xoAzGsNgh4eqXkycXb6cgXbOgehGqkBVe+MnjSVMXz3QJykerGKPy28gqcM7AFGYw== + "@types/js-yaml@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.0.tgz#d1a11688112091f2c711674df3a65ea2f47b5dfb" diff --git a/terminus-terminal/src/buttonProvider.ts b/terminus-terminal/src/buttonProvider.ts index a550ae0e..b518f753 100644 --- a/terminus-terminal/src/buttonProvider.ts +++ b/terminus-terminal/src/buttonProvider.ts @@ -15,10 +15,10 @@ export class ButtonProvider extends ToolbarButtonProvider { private terminal: TerminalService, ) { super() - if (!electron.remote.process.env.TERMINUS_DEV) { + if (!electron.process.env.TERMINUS_DEV) { setImmediate(async () => { - const argv: string[] = electron.remote.process.argv - for (const arg of argv.slice(1).concat([electron.remote.process.argv0])) { + const argv: string[] = electron.process.argv + for (const arg of argv.slice(1).concat([electron.process.argv0])) { if (await fs.exists(arg)) { if ((await fs.stat(arg)).isDirectory()) { this.terminal.openTab(undefined, arg) diff --git a/terminus-terminal/src/frontends/xtermFrontend.ts b/terminus-terminal/src/frontends/xtermFrontend.ts index 41f094da..e874e4f2 100644 --- a/terminus-terminal/src/frontends/xtermFrontend.ts +++ b/terminus-terminal/src/frontends/xtermFrontend.ts @@ -175,12 +175,12 @@ export class XTermFrontend extends Frontend { copySelection (): void { const text = this.getSelection() if (text.length < 1024 * 32) { - require('electron').remote.clipboard.write({ + require('@electron/remote').clipboard.write({ text: this.getSelection(), html: this.getSelectionAsHTML(), }) } else { - require('electron').remote.clipboard.write({ + require('@electron/remote').clipboard.write({ text: this.getSelection(), }) } diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index d2f218ed..da958221 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -6,7 +6,7 @@ import { FormsModule } from '@angular/forms' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { ToastrModule } from 'ngx-toastr' -import TerminusCorePlugin, { HostAppService, ToolbarButtonProvider, TabRecoveryProvider, ConfigProvider, HotkeysService, HotkeyProvider, AppService, ConfigService, TabContextMenuItemProvider } from 'terminus-core' +import TerminusCorePlugin, { HostAppService, ToolbarButtonProvider, TabRecoveryProvider, ConfigProvider, HotkeysService, HotkeyProvider, AppService, ConfigService, TabContextMenuItemProvider, ElectronService } from 'terminus-core' import { SettingsTabProvider } from 'terminus-settings' import { AppearanceSettingsTabComponent } from './components/appearanceSettingsTab.component' @@ -139,6 +139,7 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/ terminal: TerminalService, hostApp: HostAppService, dockMenu: DockMenuService, + electron: ElectronService, ) { const events = [ { @@ -165,8 +166,7 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/ } }) if (config.store.terminal.autoOpen) { - - let argv = require('electron').remote.process.argv + let argv = electron.process.argv if (argv[0].includes('node')) { argv = argv.slice(1) } diff --git a/webpack.plugin.config.js b/webpack.plugin.config.js index 142caf37..8ff84479 100644 --- a/webpack.plugin.config.js +++ b/webpack.plugin.config.js @@ -41,7 +41,10 @@ module.exports = options => { ], paths: { 'terminus-*': [path.resolve(options.dirname, '../terminus-*')], - '*': [path.resolve(options.dirname, '../app/node_modules/*')], + '*': [ + path.resolve(options.dirname, '../app/node_modules/*'), + path.resolve(options.dirname, '../node_modules/*'), + ], }, }, },