mirror of
https://github.com/Eugeny/tabby
synced 2025-01-23 18:35:25 +00:00
63 lines
2 KiB
TypeScript
63 lines
2 KiB
TypeScript
import 'zone.js'
|
|
import 'core-js/proposals/reflect-metadata'
|
|
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 { findPlugins, loadPlugins, PluginInfo } from './plugins'
|
|
|
|
// Always land on the start view
|
|
location.hash = ''
|
|
|
|
;(process as any).enablePromiseAPI = true
|
|
|
|
if (process.platform === 'win32' && !('HOME' in process.env)) {
|
|
process.env.HOME = `${process.env.HOMEDRIVE}${process.env.HOMEPATH}`
|
|
}
|
|
|
|
if (process.env.TERMINUS_DEV) {
|
|
console.warn('Running in debug mode')
|
|
} else {
|
|
enableProdMode()
|
|
}
|
|
|
|
async function bootstrap (plugins: PluginInfo[], safeMode = false): Promise<NgModuleRef<any>> {
|
|
if (safeMode) {
|
|
plugins = plugins.filter(x => x.isBuiltin)
|
|
}
|
|
const pluginsModules = await loadPlugins(plugins, (current, total) => {
|
|
(document.querySelector('.progress .bar') as HTMLElement).style.width = `${100 * current / total}%` // eslint-disable-line
|
|
})
|
|
const module = getRootModule(pluginsModules)
|
|
window['rootModule'] = module
|
|
return platformBrowserDynamic().bootstrapModule(module).then(moduleRef => {
|
|
if (process.env.TERMINUS_DEV) {
|
|
const applicationRef = moduleRef.injector.get(ApplicationRef)
|
|
const componentRef = applicationRef.components[0]
|
|
enableDebugTools(componentRef)
|
|
}
|
|
return moduleRef
|
|
})
|
|
}
|
|
|
|
findPlugins().then(async plugins => {
|
|
console.log('Starting with plugins:', plugins)
|
|
try {
|
|
await bootstrap(plugins)
|
|
} catch (error) {
|
|
console.error('Angular bootstrapping error:', error)
|
|
console.warn('Trying safe mode')
|
|
window['safeModeReason'] = error
|
|
try {
|
|
await bootstrap(plugins, true)
|
|
} catch (error2) {
|
|
console.error('Bootstrap failed:', error2)
|
|
}
|
|
}
|
|
})
|