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 * 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)
})

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -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",

View File

@@ -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<NgMo
const module = getRootModule(pluginsModules)
window['rootModule'] = module
return platformBrowserDynamic().bootstrapModule(module).then(moduleRef => {
if (isDev) {
if (process.env.TERMINUS_DEV) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
enableDebugTools(componentRef)

View File

@@ -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',
)

View File

@@ -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',

View File

@@ -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"