1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-11 07:28:08 +03:00

pass the web connector via an angular provider

This commit is contained in:
Eugene Pankov 2021-06-27 19:08:37 +02:00
parent 45e6844931
commit 406baafd8d
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
4 changed files with 17 additions and 11 deletions

View File

@ -64,8 +64,7 @@
"**/graceful-fs": "^4.2.4"
},
"scripts": {
"build": "npm run build:typings && webpack --color --config app/webpack.main.config.js && webpack --color --config app/webpack.config.js && webpack --color --config terminus-core/webpack.config.js && webpack --color --config terminus-settings/webpack.config.js && webpack --color --config terminus-terminal/webpack.config.js && webpack --color --config terminus-local/webpack.config.js && webpack --color --config terminus-plugin-manager/webpack.config.js && webpack --color --config terminus-community-color-schemes/webpack.config.js && webpack --color --config terminus-ssh/webpack.config.js && webpack --color --config terminus-serial/webpack.config.js && webpack --color --config terminus-electron/webpack.config.js && webpack --color --config terminus-web/webpack.config.js",
"build:web": "webpack --color --config web/webpack.config.js",
"build": "npm run build:typings && webpack --color --config app/webpack.main.config.js && webpack --color --config app/webpack.config.js && webpack --color --config terminus-core/webpack.config.js && webpack --color --config terminus-settings/webpack.config.js && webpack --color --config terminus-terminal/webpack.config.js && webpack --color --config terminus-local/webpack.config.js && webpack --color --config terminus-plugin-manager/webpack.config.js && webpack --color --config terminus-community-color-schemes/webpack.config.js && webpack --color --config terminus-ssh/webpack.config.js && webpack --color --config terminus-serial/webpack.config.js && webpack --color --config terminus-electron/webpack.config.js && webpack --color --config terminus-web/webpack.config.js && webpack --color --config web/webpack.config.js",
"build:typings": "node scripts/build-typings.js",
"watch": "cross-env TERMINUS_DEV=1 webpack --progress --color --watch",
"start": "cross-env TERMINUS_DEV=1 electron app --debug --inspect",

View File

@ -1,6 +1,6 @@
import '@vaadin/vaadin-context-menu/vaadin-context-menu.js'
import copyToClipboard from 'copy-text-to-clipboard'
import { Injectable } from '@angular/core'
import { Injectable, Inject } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { PlatformService, ClipboardContent, MenuItemOptions, MessageBoxOptions, MessageBoxResult, FileUpload, FileUploadOptions, FileDownload, HTMLFileUpload } from 'terminus-core'
@ -16,14 +16,13 @@ export class WebPlatformService extends PlatformService {
private menu: ContextMenuElement
private contextMenuHandlers = new Map<ContextMenuItem, () => void>()
private fileSelector: HTMLInputElement
private connector: any
constructor (
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@Inject('WEB_CONNECTOR') private connector: any,
private ngbModal: NgbModal,
) {
super()
this.connector = window['__connector__']
this.menu = window.document.createElement('vaadin-context-menu')
this.menu.addEventListener('item-selected', e => {
this.contextMenuHandlers.get(e.detail.value)?.()

View File

@ -15,19 +15,25 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { getRootModule } from '../app/src/app.module'
import { BootstrapData, BOOTSTRAP_DATA } from '../terminus-core/src/api/mainProcess'
interface BootstrapOptions {
packageModules: any[]
bootstrapData: BootstrapData
debugMode: boolean
connector: any
}
window['bootstrapTerminus'] = async function bootstrap (packageModules: any[], bootstrapData: BootstrapData, debugMode = false): Promise<NgModuleRef<any>> {
window['bootstrapTerminus'] = async function bootstrap (options: BootstrapOptions): Promise<NgModuleRef<any>> {
window.parent.postMessage('request-connector', '*')
const pluginModules = []
for (const packageModule of packageModules) {
for (const packageModule of options.packageModules) {
const pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
pluginModule.pluginName = packageModule.pluginName
pluginModule.bootstrap = packageModule.bootstrap
pluginModules.push(pluginModule)
}
if (!debugMode) {
if (!options.debugMode) {
enableProdMode()
}
@ -35,9 +41,10 @@ window['bootstrapTerminus'] = async function bootstrap (packageModules: any[], b
window['rootModule'] = module
const moduleRef = await platformBrowserDynamic([
{ provide: BOOTSTRAP_DATA, useValue: bootstrapData },
{ provide: BOOTSTRAP_DATA, useValue: options.bootstrapData },
{ provide: 'WEB_CONNECTOR', useValue: options.connector },
]).bootstrapModule(module)
if (debugMode) {
if (options.debugMode) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
enableDebugTools(componentRef)

View File

@ -12,4 +12,5 @@ module.exports = [
require('./terminus-ssh/webpack.config.js'),
require('./terminus-serial/webpack.config.js'),
require('./terminus-web/webpack.config.js'),
require('./web/webpack.config.js'),
]