From df213c3b0af414912b5648b75c9420584cd82e05 Mon Sep 17 00:00:00 2001 From: thegecko Date: Thu, 2 Jul 2020 12:55:18 +0100 Subject: [PATCH] Add activatePlugin and didStart to plugins --- .../plugin-ext/src/common/plugin-api-rpc.ts | 2 ++ .../src/hosted/browser/hosted-plugin.ts | 19 +++++++++++++++++++ .../plugin-ext/src/plugin/plugin-manager.ts | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 398e40294a6fb..cd8d45ace28e4 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -189,6 +189,8 @@ export interface PluginManagerExt { $updateStoragePath(path: string | undefined): Promise; $activateByEvent(event: string): Promise; + + $activatePlugin(id: string): Promise; } export interface CommandRegistryMain { diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index 1b7c05fdea7cf..d9f8c797fe9c6 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -151,6 +151,14 @@ export class HostedPluginSupport { protected readonly onDidChangePluginsEmitter = new Emitter(); readonly onDidChangePlugins = this.onDidChangePluginsEmitter.event; + protected readonly deferredDidStart = new Deferred(); + /** + * Resolves when the initial plugins are started. + */ + get didStart(): Promise { + return this.deferredDidStart.promise; + } + @postConstruct() protected init(): void { this.theiaReadyPromise = Promise.all([this.preferenceServiceImpl.ready, this.workspaceService.roots]); @@ -241,6 +249,9 @@ export class HostedPluginSupport { return; } await this.startPlugins(contributionsByHost, toDisconnect); + + this.deferredDidStart.resolve(); + this.restoreWebviews(); } @@ -576,6 +587,14 @@ export class HostedPluginSupport { } } + async activatePlugin(id: string): Promise { + const activation = []; + for (const manager of this.managers.values()) { + activation.push(manager.$activatePlugin(id)); + } + await Promise.all(activation); + } + protected createMeasurement(name: string): () => number { const startMarker = `${name}-start`; const endMarker = `${name}-end`; diff --git a/packages/plugin-ext/src/plugin/plugin-manager.ts b/packages/plugin-ext/src/plugin/plugin-manager.ts index f62bf8ec61913..08428277ce955 100644 --- a/packages/plugin-ext/src/plugin/plugin-manager.ts +++ b/packages/plugin-ext/src/plugin/plugin-manager.ts @@ -77,6 +77,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager { 'onWebviewPanel' ]); + private configStorage: ConfigStorage | undefined; private readonly registry = new Map(); private readonly activations = new Map Promise)[] | undefined>(); /** promises to whether loading each plugin has been successful */ @@ -158,6 +159,8 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager { } async $start(params: PluginManagerStartParams): Promise { + this.configStorage = params.configStorage; + const [plugins, foreignPlugins] = await this.host.init(params.plugins); // add foreign plugins for (const plugin of foreignPlugins) { @@ -256,6 +259,10 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager { } async $updateStoragePath(path: string | undefined): Promise { + if (this.configStorage) { + this.configStorage.hostStoragePath = path; + } + this.pluginContextsMap.forEach((pluginContext: theia.PluginContext, pluginId: string) => { pluginContext.storagePath = path ? join(path, pluginId) : undefined; }); @@ -272,6 +279,13 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager { } } + async $activatePlugin(id: string): Promise { + const plugin = this.registry.get(id); + if (plugin && this.configStorage) { + await this.loadPlugin(plugin, this.configStorage); + } + } + // tslint:disable-next-line:no-any private async startPlugin(plugin: Plugin, configStorage: ConfigStorage, pluginMain: any): Promise { const subscriptions: theia.Disposable[] = [];