use @electron/remote

This commit is contained in:
Eugene Pankov
2021-03-20 17:12:39 +01:00
parent 4a97cc4383
commit bd46b08c9d
16 changed files with 58 additions and 50 deletions

View File

@@ -1,5 +1,7 @@
import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions } from 'electron' import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions } from 'electron'
import * as promiseIpc from 'electron-promise-ipc' import * as promiseIpc from 'electron-promise-ipc'
import * as remote from '@electron/remote/main'
import { loadConfig } from './config' import { loadConfig } from './config'
import { Window, WindowOptions } from './window' import { Window, WindowOptions } from './window'
import { pluginManager } from './pluginManager' import { pluginManager } from './pluginManager'
@@ -9,6 +11,8 @@ export class Application {
private windows: Window[] = [] private windows: Window[] = []
constructor () { constructor () {
remote.initialize()
ipcMain.on('app:config-change', (_event, config) => { ipcMain.on('app:config-change', (_event, config) => {
this.broadcast('host:config-change', config) this.broadcast('host:config-change', config)
}) })

View File

@@ -1,12 +1,8 @@
import * as path from 'path' import * as path from 'path'
import * as fs from 'fs' import * as fs from 'fs'
import * as electron from 'electron'
let appPath: string | null = null const appPath = path.dirname(electron.app.getPath('exe'))
try {
appPath = path.dirname(require('electron').app.getPath('exe'))
} catch {
appPath = path.dirname(require('electron').remote.app.getPath('exe'))
}
if (fs.existsSync(path.join(appPath, 'terminus-data'))) { if (fs.existsSync(path.join(appPath, 'terminus-data'))) {
fs.renameSync(path.join(appPath, 'terminus-data'), path.join(appPath, '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') const portableData = path.join(appPath, 'data')
if (fs.existsSync(portableData)) { if (fs.existsSync(portableData)) {
console.log('reset user data to ' + portableData) console.log('reset user data to ' + portableData)
try { electron.app.setPath('userData', portableData)
require('electron').app.setPath('userData', portableData)
} catch {
require('electron').remote.app.setPath('userData', portableData)
}
} }

View File

@@ -1,16 +1,14 @@
const { init } = String(process.type) === 'main' ? require('@sentry/electron/dist/main') : require('@sentry/electron/dist/renderer') 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' const SENTRY_DSN = 'https://4717a0a7ee0b4429bd3a0f06c3d7eec3@sentry.io/181876'
let release = null let release = null
try { try {
release = require('electron').app.getVersion() release = require('electron').app.getVersion()
} catch { } catch {
release = require('electron').remote.app.getVersion() release = require('@electron/remote').app.getVersion()
} }
if (!isDev) { if (!process.env.TERMINUS_DEV) {
init({ init({
dsn: SENTRY_DSN, dsn: SENTRY_DSN,
release, release,

View File

@@ -21,11 +21,11 @@
"@angular/forms": "^11.1.1", "@angular/forms": "^11.1.1",
"@angular/platform-browser": "^11.1.1", "@angular/platform-browser": "^11.1.1",
"@angular/platform-browser-dynamic": "^11.1.1", "@angular/platform-browser-dynamic": "^11.1.1",
"@electron/remote": "^1.0.4",
"@ng-bootstrap/ng-bootstrap": "^7.0.0", "@ng-bootstrap/ng-bootstrap": "^7.0.0",
"@terminus-term/node-pty": "0.10.0-terminus.3", "@terminus-term/node-pty": "0.10.0-terminus.3",
"electron-config": "2.0.0", "electron-config": "2.0.0",
"electron-debug": "^3.2.0", "electron-debug": "^3.2.0",
"electron-is-dev": "1.2.0",
"electron-promise-ipc": "^2.2.4", "electron-promise-ipc": "^2.2.4",
"fontmanager-redux": "1.0.0", "fontmanager-redux": "1.0.0",
"glasstron": "0.0.7", "glasstron": "0.0.7",

View File

@@ -2,8 +2,6 @@ import 'zone.js'
import 'core-js/proposals/reflect-metadata' import 'core-js/proposals/reflect-metadata'
import 'rxjs' import 'rxjs'
import * as isDev from 'electron-is-dev'
import './global.scss' import './global.scss'
import './toastr.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}` process.env.HOME = `${process.env.HOMEDRIVE}${process.env.HOMEPATH}`
} }
if (isDev) { if (process.env.TERMINUS_DEV) {
console.warn('Running in debug mode') console.warn('Running in debug mode')
} else { } else {
enableProdMode() enableProdMode()
@@ -39,7 +37,7 @@ async function bootstrap (plugins: PluginInfo[], safeMode = false): Promise<NgMo
const module = getRootModule(pluginsModules) const module = getRootModule(pluginsModules)
window['rootModule'] = module window['rootModule'] = module
return platformBrowserDynamic().bootstrapModule(module).then(moduleRef => { return platformBrowserDynamic().bootstrapModule(module).then(moduleRef => {
if (isDev) { if (process.env.TERMINUS_DEV) {
const applicationRef = moduleRef.injector.get(ApplicationRef) const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0] const componentRef = applicationRef.components[0]
enableDebugTools(componentRef) enableDebugTools(componentRef)

View File

@@ -1,5 +1,6 @@
import * as fs from 'mz/fs' import * as fs from 'mz/fs'
import * as path from 'path' import * as path from 'path'
import * as remote from '@electron/remote'
const nodeModule = require('module') // eslint-disable-line @typescript-eslint/no-var-requires const nodeModule = require('module') // eslint-disable-line @typescript-eslint/no-var-requires
const nodeRequire = (global as any).require 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))) global['module'].paths.map((x: string) => nodeModule.globalPaths.push(normalizePath(x)))
if (process.env.TERMINUS_DEV) { 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( const userPluginsPath = path.join(
require('electron').remote.app.getPath('userData'), remote.app.getPath('userData'),
'plugins', 'plugins',
) )

View File

@@ -68,7 +68,6 @@ module.exports = {
'@ng-bootstrap/ng-bootstrap': 'commonjs @ng-bootstrap/ng-bootstrap', '@ng-bootstrap/ng-bootstrap': 'commonjs @ng-bootstrap/ng-bootstrap',
child_process: 'commonjs child_process', child_process: 'commonjs child_process',
electron: 'commonjs electron', electron: 'commonjs electron',
'electron-is-dev': 'commonjs electron-is-dev',
fs: 'commonjs fs', fs: 'commonjs fs',
'ngx-toastr': 'commonjs ngx-toastr', 'ngx-toastr': 'commonjs ngx-toastr',
module: 'commonjs module', module: 'commonjs module',

View File

@@ -51,6 +51,11 @@
dependencies: dependencies:
tslib "^2.0.0" 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": "@iarna/cli@^1.2.0":
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/@iarna/cli/-/cli-1.2.0.tgz#0f7af5e851afe895104583c4ca07377a8094d641" resolved "https://registry.yarnpkg.com/@iarna/cli/-/cli-1.2.0.tgz#0f7af5e851afe895104583c4ca07377a8094d641"

View File

@@ -17,6 +17,7 @@
"author": "Eugene Pankov", "author": "Eugene Pankov",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@electron/remote": "^1.0.4",
"@types/js-yaml": "^4.0.0", "@types/js-yaml": "^4.0.0",
"@types/shell-escape": "^0.2.0", "@types/shell-escape": "^0.2.0",
"@types/winston": "^2.3.6", "@types/winston": "^2.3.6",

View File

@@ -105,7 +105,7 @@ export class TabHeaderComponent {
if ($event.which === 3) { if ($event.which === 3) {
$event.preventDefault() $event.preventDefault()
const contextMenu = this.electron.remote.Menu.buildFromTemplate(await this.buildContextMenu()) const contextMenu = this.electron.Menu.buildFromTemplate(await this.buildContextMenu())
contextMenu.popup({ contextMenu.popup({
x: $event.pageX, x: $event.pageX,

View File

@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { App, IpcRenderer, Shell, Dialog, Clipboard, GlobalShortcut, Screen, Remote, AutoUpdater, TouchBar, BrowserWindow, Menu, MenuItem, NativeImage, MessageBoxOptions } from 'electron' 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 { export interface MessageBoxResponse {
response: number response: number
@@ -17,30 +18,31 @@ export class ElectronService {
nativeImage: typeof NativeImage nativeImage: typeof NativeImage
screen: Screen screen: Screen
remote: Remote remote: Remote
process: any
autoUpdater: AutoUpdater autoUpdater: AutoUpdater
TouchBar: typeof TouchBar TouchBar: typeof TouchBar
BrowserWindow: typeof BrowserWindow BrowserWindow: typeof BrowserWindow
Menu: typeof Menu Menu: typeof Menu
MenuItem: typeof MenuItem MenuItem: typeof MenuItem
private electron: any
/** @hidden */ /** @hidden */
private constructor () { private constructor () {
this.electron = require('electron') const electron = require('electron')
this.remote = this.electron.remote this.shell = electron.shell
this.app = this.remote.app this.clipboard = electron.clipboard
this.screen = this.remote.screen this.ipcRenderer = electron.ipcRenderer
this.dialog = this.remote.dialog
this.shell = this.electron.shell this.process = remote.process
this.clipboard = this.electron.clipboard this.app = remote.app
this.ipcRenderer = this.electron.ipcRenderer this.screen = remote.screen
this.globalShortcut = this.remote.globalShortcut this.dialog = remote.dialog
this.nativeImage = this.remote.nativeImage this.globalShortcut = remote.globalShortcut
this.autoUpdater = this.remote.autoUpdater this.nativeImage = remote.nativeImage
this.TouchBar = this.remote.TouchBar this.autoUpdater = remote.autoUpdater
this.BrowserWindow = this.remote.BrowserWindow this.TouchBar = remote.TouchBar
this.Menu = this.remote.Menu this.BrowserWindow = remote.BrowserWindow
this.MenuItem = this.remote.MenuItem this.Menu = remote.Menu
this.MenuItem = remote.MenuItem
} }
async showMessageBox ( async showMessageBox (

View File

@@ -11,6 +11,11 @@
enabled "2.0.x" enabled "2.0.x"
kuler "^2.0.0" 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": "@types/js-yaml@^4.0.0":
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.0.tgz#d1a11688112091f2c711674df3a65ea2f47b5dfb" resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.0.tgz#d1a11688112091f2c711674df3a65ea2f47b5dfb"

View File

@@ -15,10 +15,10 @@ export class ButtonProvider extends ToolbarButtonProvider {
private terminal: TerminalService, private terminal: TerminalService,
) { ) {
super() super()
if (!electron.remote.process.env.TERMINUS_DEV) { if (!electron.process.env.TERMINUS_DEV) {
setImmediate(async () => { setImmediate(async () => {
const argv: string[] = electron.remote.process.argv const argv: string[] = electron.process.argv
for (const arg of argv.slice(1).concat([electron.remote.process.argv0])) { for (const arg of argv.slice(1).concat([electron.process.argv0])) {
if (await fs.exists(arg)) { if (await fs.exists(arg)) {
if ((await fs.stat(arg)).isDirectory()) { if ((await fs.stat(arg)).isDirectory()) {
this.terminal.openTab(undefined, arg) this.terminal.openTab(undefined, arg)

View File

@@ -175,12 +175,12 @@ export class XTermFrontend extends Frontend {
copySelection (): void { copySelection (): void {
const text = this.getSelection() const text = this.getSelection()
if (text.length < 1024 * 32) { if (text.length < 1024 * 32) {
require('electron').remote.clipboard.write({ require('@electron/remote').clipboard.write({
text: this.getSelection(), text: this.getSelection(),
html: this.getSelectionAsHTML(), html: this.getSelectionAsHTML(),
}) })
} else { } else {
require('electron').remote.clipboard.write({ require('@electron/remote').clipboard.write({
text: this.getSelection(), text: this.getSelection(),
}) })
} }

View File

@@ -6,7 +6,7 @@ import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr' 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 { SettingsTabProvider } from 'terminus-settings'
import { AppearanceSettingsTabComponent } from './components/appearanceSettingsTab.component' import { AppearanceSettingsTabComponent } from './components/appearanceSettingsTab.component'
@@ -139,6 +139,7 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/
terminal: TerminalService, terminal: TerminalService,
hostApp: HostAppService, hostApp: HostAppService,
dockMenu: DockMenuService, dockMenu: DockMenuService,
electron: ElectronService,
) { ) {
const events = [ const events = [
{ {
@@ -165,8 +166,7 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/
} }
}) })
if (config.store.terminal.autoOpen) { if (config.store.terminal.autoOpen) {
let argv = electron.process.argv
let argv = require('electron').remote.process.argv
if (argv[0].includes('node')) { if (argv[0].includes('node')) {
argv = argv.slice(1) argv = argv.slice(1)
} }

View File

@@ -41,7 +41,10 @@ module.exports = options => {
], ],
paths: { paths: {
'terminus-*': [path.resolve(options.dirname, '../terminus-*')], '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/*'),
],
}, },
}, },
}, },