tabby/app/src/entry.ts

83 lines
2.8 KiB
TypeScript
Raw Normal View History

2017-06-30 22:55:21 +00:00
import 'zone.js'
2019-05-24 18:30:42 +00:00
import 'core-js/proposals/reflect-metadata'
2017-04-16 21:04:29 +00:00
import 'rxjs'
2018-08-25 07:37:56 +00:00
import './global.scss'
2018-03-30 21:24:34 +00:00
import './toastr.scss'
2016-12-23 09:06:53 +00:00
2021-07-06 19:22:57 +00:00
// Importing before @angular/*
import { findPlugins, initModuleLookup, loadPlugins } from './plugins'
2019-12-31 21:30:05 +00:00
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
import { enableDebugTools } from '@angular/platform-browser'
2016-12-23 09:06:53 +00:00
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { ipcRenderer } from 'electron'
2016-12-23 09:06:53 +00:00
2017-04-23 22:34:07 +00:00
import { getRootModule } from './app.module'
2021-06-29 21:57:04 +00:00
import { BootstrapData, BOOTSTRAP_DATA, PluginInfo } from '../../tabby-core/src/api/mainProcess'
2019-06-14 21:47:48 +00:00
// Always land on the start view
location.hash = ''
2017-04-23 22:34:07 +00:00
2019-01-03 14:20:02 +00:00
;(process as any).enablePromiseAPI = true
if (process.platform === 'win32' && !('HOME' in process.env)) {
2019-09-18 18:56:59 +00:00
process.env.HOME = `${process.env.HOMEDRIVE}${process.env.HOMEPATH}`
}
2021-06-29 21:57:04 +00:00
if (process.env.TABBY_DEV && !process.env.TABBY_FORCE_ANGULAR_PROD) {
2016-12-23 09:06:53 +00:00
console.warn('Running in debug mode')
} else {
enableProdMode()
}
async function bootstrap (bootstrapData: BootstrapData, plugins: PluginInfo[], safeMode = false): Promise<NgModuleRef<any>> {
2017-08-13 12:13:04 +00:00
if (safeMode) {
plugins = plugins.filter(x => x.isBuiltin)
2017-08-13 12:13:04 +00:00
}
const pluginModules = await loadPlugins(plugins, (current, total) => {
2019-06-14 21:47:48 +00:00
(document.querySelector('.progress .bar') as HTMLElement).style.width = `${100 * current / total}%` // eslint-disable-line
2017-04-24 19:26:59 +00:00
})
const module = getRootModule(pluginModules)
2017-11-26 21:14:46 +00:00
window['rootModule'] = module
const moduleRef = await platformBrowserDynamic([
{ provide: BOOTSTRAP_DATA, useValue: bootstrapData },
]).bootstrapModule(module)
2021-06-29 21:57:04 +00:00
if (process.env.TABBY_DEV) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
enableDebugTools(componentRef)
}
return moduleRef
2017-08-13 12:13:04 +00:00
}
ipcRenderer.once('start', async (_$event, bootstrapData: BootstrapData) => {
console.log('Window bootstrap data:', bootstrapData)
2021-06-18 23:36:25 +00:00
initModuleLookup(bootstrapData.userPluginsPath)
let plugins = await findPlugins()
bootstrapData.installedPlugins = plugins
if (bootstrapData.config.pluginBlacklist) {
plugins = plugins.filter(x => !bootstrapData.config.pluginBlacklist.includes(x.name))
}
plugins = plugins.filter(x => x.name !== 'web')
2021-06-18 23:36:25 +00:00
2017-08-13 12:13:04 +00:00
console.log('Starting with plugins:', plugins)
try {
await bootstrap(bootstrapData, plugins)
2017-08-13 12:13:04 +00:00
} catch (error) {
console.error('Angular bootstrapping error:', error)
console.warn('Trying safe mode')
window['safeModeReason'] = error
try {
await bootstrap(bootstrapData, plugins, true)
2021-01-02 19:53:34 +00:00
} catch (error2) {
console.error('Bootstrap failed:', error2)
2017-08-13 12:13:04 +00:00
}
}
2017-04-15 13:20:18 +00:00
})
ipcRenderer.send('ready')