1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-25 08:33:27 +03:00
tabby/web/entry.ts

57 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-06-16 00:43:02 +03:00
import './polyfills'
import 'zone.js'
import 'core-js/proposals/reflect-metadata'
import 'core-js/features/array/flat'
import 'rxjs'
2021-06-16 00:43:02 +03:00
import '../app/src/global.scss'
import '../app/src/toastr.scss'
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
import { enableDebugTools } from '@angular/platform-browser'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
2021-06-16 00:43:02 +03:00
import { getRootModule } from '../app/src/app.module'
2021-06-30 00:57:04 +03:00
import { BootstrapData, BOOTSTRAP_DATA } from '../tabby-core/src/api/mainProcess'
interface BootstrapOptions {
packageModules: any[]
bootstrapData: BootstrapData
debugMode: boolean
connector: any
}
2021-06-30 00:57:04 +03:00
window['bootstrapTabby'] = async function bootstrap (options: BootstrapOptions): Promise<NgModuleRef<any>> {
2021-06-16 00:43:02 +03:00
window.parent.postMessage('request-connector', '*')
const pluginModules = []
for (const packageModule of options.packageModules) {
2022-02-07 18:36:20 +03:00
if (!packageModule.default) {
continue
}
const pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
pluginModule.pluginName = packageModule.pluginName
pluginModule.bootstrap = packageModule.bootstrap
pluginModules.push(pluginModule)
}
if (!options.debugMode) {
enableProdMode()
}
const module = getRootModule(pluginModules)
window['rootModule'] = module
const moduleRef = await platformBrowserDynamic([
{ provide: BOOTSTRAP_DATA, useValue: options.bootstrapData },
{ provide: 'WEB_CONNECTOR', useValue: options.connector },
]).bootstrapModule(module)
if (options.debugMode) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
enableDebugTools(componentRef)
}
return moduleRef
}