mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-09 05:50:08 +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')
|
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 => {
|
ipcMain.on('window-focus', event => {
|
||||||
if (!this.window || event.sender !== this.window.webContents) {
|
if (!this.window || event.sender !== this.window.webContents) {
|
||||||
return
|
return
|
||||||
|
@ -8,9 +8,11 @@ import './toastr.scss'
|
|||||||
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
|
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
|
||||||
import { enableDebugTools } from '@angular/platform-browser'
|
import { enableDebugTools } from '@angular/platform-browser'
|
||||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
|
||||||
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
import { getRootModule } from './app.module'
|
import { getRootModule } from './app.module'
|
||||||
import { findPlugins, loadPlugins, PluginInfo } from './plugins'
|
import { findPlugins, loadPlugins, PluginInfo } from './plugins'
|
||||||
|
import { BootstrapData } from '../common'
|
||||||
|
|
||||||
// Always land on the start view
|
// Always land on the start view
|
||||||
location.hash = ''
|
location.hash = ''
|
||||||
@ -27,37 +29,48 @@ if (process.env.TERMINUS_DEV && !process.env.TERMINUS_FORCE_ANGULAR_PROD) {
|
|||||||
enableProdMode()
|
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) {
|
if (safeMode) {
|
||||||
plugins = plugins.filter(x => x.isBuiltin)
|
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
|
(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
|
window['rootModule'] = module
|
||||||
return platformBrowserDynamic().bootstrapModule(module).then(moduleRef => {
|
const moduleRef = await platformBrowserDynamic().bootstrapModule(module, {
|
||||||
if (process.env.TERMINUS_DEV) {
|
providers: [
|
||||||
const applicationRef = moduleRef.injector.get(ApplicationRef)
|
{ provide: 'bootstrapData', useValue: bootstrapData },
|
||||||
const componentRef = applicationRef.components[0]
|
],
|
||||||
enableDebugTools(componentRef)
|
|
||||||
}
|
|
||||||
return 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 => {
|
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)
|
console.log('Starting with plugins:', plugins)
|
||||||
try {
|
try {
|
||||||
await bootstrap(plugins)
|
await bootstrap(plugins, bootstrapData)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Angular bootstrapping error:', error)
|
console.error('Angular bootstrapping error:', error)
|
||||||
console.warn('Trying safe mode')
|
console.warn('Trying safe mode')
|
||||||
window['safeModeReason'] = error
|
window['safeModeReason'] = error
|
||||||
try {
|
try {
|
||||||
await bootstrap(plugins, true)
|
await bootstrap(plugins, bootstrapData, true)
|
||||||
} catch (error2) {
|
} catch (error2) {
|
||||||
console.error('Bootstrap failed:', 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 candidateLocations: { pluginDir: string, packageName: string }[] = []
|
||||||
const PREFIX = 'terminus-'
|
const PREFIX = 'terminus-'
|
||||||
|
|
||||||
|
const processedPaths = []
|
||||||
|
|
||||||
for (let pluginDir of paths) {
|
for (let pluginDir of paths) {
|
||||||
|
if (processedPaths.includes(pluginDir)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
processedPaths.push(pluginDir)
|
||||||
|
|
||||||
pluginDir = normalizePath(pluginDir)
|
pluginDir = normalizePath(pluginDir)
|
||||||
if (!await fs.exists(pluginDir)) {
|
if (!await fs.exists(pluginDir)) {
|
||||||
continue
|
continue
|
||||||
@ -133,6 +140,8 @@ export async function findPlugins (): Promise<PluginInfo[]> {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Found ${name} in ${pluginDir}`)
|
||||||
|
|
||||||
if (foundPlugins.some(x => x.name === name)) {
|
if (foundPlugins.some(x => x.name === name)) {
|
||||||
console.info(`Plugin ${packageName} already exists, overriding`)
|
console.info(`Plugin ${packageName} already exists, overriding`)
|
||||||
foundPlugins = foundPlugins.filter(x => x.name !== name)
|
foundPlugins = foundPlugins.filter(x => x.name !== name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user