started separating terminus-electron and terminus-web

This commit is contained in:
Eugene Pankov
2021-05-24 17:48:12 +02:00
parent c19e131d8c
commit 012986dc7e
94 changed files with 1899 additions and 972 deletions

View File

@@ -1,4 +0,0 @@
export interface BootstrapData {
config: Record<string, any>
executable: string
}

View File

@@ -1,5 +1,5 @@
doctype html
html
html.terminus
head
meta(charset='UTF-8')
base(href='index.html')

View File

@@ -7,6 +7,12 @@ import { Window, WindowOptions } from './window'
import { pluginManager } from './pluginManager'
import { PTYManager } from './pty'
/* eslint-disable block-scoped-var */
try {
var wnr = require('windows-native-registry') // eslint-disable-line @typescript-eslint/no-var-requires, no-var
} catch (_) { }
export class Application {
private tray?: Tray
private ptyManager = new PTYManager()
@@ -14,6 +20,7 @@ export class Application {
constructor () {
remote.initialize()
this.useBuiltinGraphics()
this.ptyManager.init(this)
ipcMain.on('app:config-change', (_event, config) => {
@@ -161,6 +168,16 @@ export class Application {
this.windows[this.windows.length - 1].passCliArguments(argv, cwd, true)
}
private useBuiltinGraphics (): void {
if (process.platform === 'win32') {
const keyPath = 'SOFTWARE\\Microsoft\\DirectX\\UserGpuPreferences'
const valueName = app.getPath('exe')
if (!wnr.getRegistryValue(wnr.HK.CU, keyPath, valueName)) {
wnr.setRegistryValue(wnr.HK.CU, keyPath, valueName, wnr.REG.SZ, 'GpuPreference=1;')
}
}
}
private setupMenu () {
const template: MenuItemConstructorOptions[] = [
{

View File

@@ -122,7 +122,7 @@ export class Window {
}
})
this.window.loadURL(`file://${app.getAppPath()}/dist/index.html?${this.window.id}`, { extraHeaders: 'pragma: no-cache\n' })
this.window.loadURL(`file://${app.getAppPath()}/dist/index.html`, { extraHeaders: 'pragma: no-cache\n' })
this.window.webContents.setVisualZoomLevelLimits(1, 1)
this.window.webContents.setZoomFactor(1)
@@ -297,6 +297,8 @@ export class Window {
this.window.webContents.send('start', {
config: this.configStore,
executable: app.getPath('exe'),
windowID: this.window.id,
isFirstWindow: this.window.id === 1,
})
})

View File

@@ -57,6 +57,7 @@
"peerDependencies": {
"terminus-community-color-schemes": "*",
"terminus-core": "*",
"terminus-electron": "*",
"terminus-local": "*",
"terminus-plugin-manager": "*",
"terminus-serial": "*",

View File

@@ -16,10 +16,15 @@ export function getRootModule (plugins: any[]) {
extendedTimeOut: 1000,
}),
]
const bootstrap = [
...plugins.filter(x => x.bootstrap).map(x => x.bootstrap),
]
const providers = [
...plugins.filter(x => x.providers).map(x => x.providers),
].flat()
if (bootstrap.length === 0) {
throw new Error('Did not find any bootstrap components. Are there any plugins installed?')
}
@@ -27,6 +32,7 @@ export function getRootModule (plugins: any[]) {
@NgModule({
imports,
bootstrap,
providers,
}) class RootModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class
return RootModule

42
app/src/entry-web.ts Normal file
View File

@@ -0,0 +1,42 @@
import 'zone.js'
import 'core-js/proposals/reflect-metadata'
import 'core-js/features/array/flat'
import 'rxjs'
import './global.scss'
import './toastr.scss'
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
import { enableDebugTools } from '@angular/platform-browser'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { getRootModule } from './app.module'
import { BootstrapData, BOOTSTRAP_DATA } from '../../terminus-core/src/api/mainProcess'
window['bootstrapTerminus'] = async function bootstrap (packageModules: any[], bootstrapData: BootstrapData, debugMode = false): Promise<NgModuleRef<any>> {
const pluginModules = []
for (const packageModule of packageModules) {
const pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
pluginModule.pluginName = packageModule.pluginName
pluginModule.bootstrap = packageModule.bootstrap
pluginModules.push(pluginModule)
}
if (!debugMode) {
enableProdMode()
}
const module = getRootModule(pluginModules)
window['rootModule'] = module
const moduleRef = await platformBrowserDynamic([
{ provide: BOOTSTRAP_DATA, useValue: bootstrapData },
]).bootstrapModule(module)
if (debugMode) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
enableDebugTools(componentRef)
}
return moduleRef
}

View File

@@ -12,7 +12,7 @@ import { ipcRenderer } from 'electron'
import { getRootModule } from './app.module'
import { findPlugins, loadPlugins, PluginInfo } from './plugins'
import { BootstrapData } from '../common'
import { BootstrapData, BOOTSTRAP_DATA } from '../../terminus-core/src/api/mainProcess'
// Always land on the start view
location.hash = ''
@@ -39,11 +39,9 @@ async function bootstrap (plugins: PluginInfo[], bootstrapData: BootstrapData, s
})
const module = getRootModule(pluginModules)
window['rootModule'] = module
const moduleRef = await platformBrowserDynamic().bootstrapModule(module, {
providers: [
{ provide: 'bootstrapData', useValue: bootstrapData },
],
})
const moduleRef = await platformBrowserDynamic([
{ provide: BOOTSTRAP_DATA, useValue: bootstrapData },
]).bootstrapModule(module)
if (process.env.TERMINUS_DEV) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
@@ -54,12 +52,12 @@ async function bootstrap (plugins: PluginInfo[], bootstrapData: BootstrapData, s
ipcRenderer.once('start', async (_$event, bootstrapData: BootstrapData) => {
console.log('Window bootstrap data:', bootstrapData)
;(window as any).bootstrapData = bootstrapData
let plugins = await findPlugins()
if (bootstrapData.config.pluginBlacklist) {
plugins = plugins.filter(x => !bootstrapData.config.pluginBlacklist.includes(x.name))
}
plugins = plugins.filter(x => x.name !== 'web')
console.log('Starting with plugins:', plugins)
try {
await bootstrap(plugins, bootstrapData)

View File

@@ -9,6 +9,7 @@ module.exports = {
sentry: path.resolve(__dirname, 'lib/sentry.ts'),
preload: path.resolve(__dirname, 'src/entry.preload.ts'),
bundle: path.resolve(__dirname, 'src/entry.ts'),
'bundle-web': path.resolve(__dirname, 'src/entry-web.ts'),
},
mode: process.env.TERMINUS_DEV ? 'development' : 'production',
optimization:{
@@ -41,9 +42,9 @@ module.exports = {
{
test: /\.(png|svg)$/,
use: {
loader: 'file-loader',
loader: 'url-loader',
options: {
name: 'images/[name].[ext]',
limit: 999999,
},
},
},
@@ -66,6 +67,7 @@ module.exports = {
'@angular/forms': 'commonjs @angular/forms',
'@angular/common': 'commonjs @angular/common',
'@ng-bootstrap/ng-bootstrap': 'commonjs @ng-bootstrap/ng-bootstrap',
'@electron/remote': 'commonjs @electron/remote',
child_process: 'commonjs child_process',
electron: 'commonjs electron',
fs: 'commonjs fs',

View File

@@ -51,6 +51,7 @@ module.exports = {
util: 'commonjs util',
'source-map-support': 'commonjs source-map-support',
'windows-swca': 'commonjs windows-swca',
'windows-native-registry': 'commonjs windows-native-registry',
'windows-blurbehind': 'commonjs windows-blurbehind',
'yargs/yargs': 'commonjs yargs/yargs',
},