mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-08 13:30:02 +00:00
truly blacklist plugins and don't load them
This commit is contained in:
parent
8f2a3f1333
commit
2f99eeef40
3
app/common.ts
Normal file
3
app/common.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface BootstrapData {
|
||||
config: Record<string, any>
|
||||
}
|
@ -290,6 +290,15 @@ export class Window {
|
||||
this.send('host:window-focused')
|
||||
})
|
||||
|
||||
ipcMain.on('ready', event => {
|
||||
if (!this.window || event.sender !== this.window.webContents) {
|
||||
return
|
||||
}
|
||||
this.window.webContents.send('start', {
|
||||
config: this.configStore,
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.on('window-focus', event => {
|
||||
if (!this.window || event.sender !== this.window.webContents) {
|
||||
return
|
||||
|
@ -8,9 +8,11 @@ import './toastr.scss'
|
||||
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
|
||||
import { enableDebugTools } from '@angular/platform-browser'
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
|
||||
import { ipcRenderer } from 'electron'
|
||||
|
||||
import { getRootModule } from './app.module'
|
||||
import { findPlugins, loadPlugins, PluginInfo } from './plugins'
|
||||
import { BootstrapData } from '../common'
|
||||
|
||||
// Always land on the start view
|
||||
location.hash = ''
|
||||
@ -27,37 +29,48 @@ if (process.env.TERMINUS_DEV && !process.env.TERMINUS_FORCE_ANGULAR_PROD) {
|
||||
enableProdMode()
|
||||
}
|
||||
|
||||
async function bootstrap (plugins: PluginInfo[], safeMode = false): Promise<NgModuleRef<any>> {
|
||||
async function bootstrap (plugins: PluginInfo[], bootstrapData: BootstrapData, safeMode = false): Promise<NgModuleRef<any>> {
|
||||
if (safeMode) {
|
||||
plugins = plugins.filter(x => x.isBuiltin)
|
||||
}
|
||||
const pluginsModules = await loadPlugins(plugins, (current, total) => {
|
||||
|
||||
const pluginModules = await loadPlugins(plugins, (current, total) => {
|
||||
(document.querySelector('.progress .bar') as HTMLElement).style.width = `${100 * current / total}%` // eslint-disable-line
|
||||
})
|
||||
const module = getRootModule(pluginsModules)
|
||||
const module = getRootModule(pluginModules)
|
||||
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
|
||||
const moduleRef = await platformBrowserDynamic().bootstrapModule(module, {
|
||||
providers: [
|
||||
{ provide: 'bootstrapData', useValue: bootstrapData },
|
||||
],
|
||||
})
|
||||
if (process.env.TERMINUS_DEV) {
|
||||
const applicationRef = moduleRef.injector.get(ApplicationRef)
|
||||
const componentRef = applicationRef.components[0]
|
||||
enableDebugTools(componentRef)
|
||||
}
|
||||
return moduleRef
|
||||
}
|
||||
|
||||
findPlugins().then(async plugins => {
|
||||
ipcRenderer.once('start', async (_$event, bootstrapData: BootstrapData) => {
|
||||
console.log('Window bootstrap data:', bootstrapData)
|
||||
let plugins = await findPlugins()
|
||||
if (bootstrapData.config.pluginBlacklist) {
|
||||
plugins = plugins.filter(x => !bootstrapData.config.pluginBlacklist.includes(x.name))
|
||||
}
|
||||
console.log('Starting with plugins:', plugins)
|
||||
try {
|
||||
await bootstrap(plugins)
|
||||
await bootstrap(plugins, bootstrapData)
|
||||
} catch (error) {
|
||||
console.error('Angular bootstrapping error:', error)
|
||||
console.warn('Trying safe mode')
|
||||
window['safeModeReason'] = error
|
||||
try {
|
||||
await bootstrap(plugins, true)
|
||||
await bootstrap(plugins, bootstrapData, true)
|
||||
} catch (error2) {
|
||||
console.error('Bootstrap failed:', error2)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
ipcRenderer.send('ready')
|
||||
|
@ -101,7 +101,14 @@ export async function findPlugins (): Promise<PluginInfo[]> {
|
||||
const candidateLocations: { pluginDir: string, packageName: string }[] = []
|
||||
const PREFIX = 'terminus-'
|
||||
|
||||
const processedPaths = []
|
||||
|
||||
for (let pluginDir of paths) {
|
||||
if (processedPaths.includes(pluginDir)) {
|
||||
continue
|
||||
}
|
||||
processedPaths.push(pluginDir)
|
||||
|
||||
pluginDir = normalizePath(pluginDir)
|
||||
if (!await fs.exists(pluginDir)) {
|
||||
continue
|
||||
@ -133,6 +140,8 @@ export async function findPlugins (): Promise<PluginInfo[]> {
|
||||
continue
|
||||
}
|
||||
|
||||
console.log(`Found ${name} in ${pluginDir}`)
|
||||
|
||||
if (foundPlugins.some(x => x.name === name)) {
|
||||
console.info(`Plugin ${packageName} already exists, overriding`)
|
||||
foundPlugins = foundPlugins.filter(x => x.name !== name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user