Skip to content

Commit

Permalink
Add activatePlugin and didStart to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko authored and westbury committed Jul 27, 2020
1 parent ed0a065 commit df213c3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export interface PluginManagerExt {
$updateStoragePath(path: string | undefined): Promise<void>;

$activateByEvent(event: string): Promise<void>;

$activatePlugin(id: string): Promise<void>;
}

export interface CommandRegistryMain {
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ export class HostedPluginSupport {
protected readonly onDidChangePluginsEmitter = new Emitter<void>();
readonly onDidChangePlugins = this.onDidChangePluginsEmitter.event;

protected readonly deferredDidStart = new Deferred<void>();
/**
* Resolves when the initial plugins are started.
*/
get didStart(): Promise<void> {
return this.deferredDidStart.promise;
}

@postConstruct()
protected init(): void {
this.theiaReadyPromise = Promise.all([this.preferenceServiceImpl.ready, this.workspaceService.roots]);
Expand Down Expand Up @@ -241,6 +249,9 @@ export class HostedPluginSupport {
return;
}
await this.startPlugins(contributionsByHost, toDisconnect);

this.deferredDidStart.resolve();

this.restoreWebviews();
}

Expand Down Expand Up @@ -576,6 +587,14 @@ export class HostedPluginSupport {
}
}

async activatePlugin(id: string): Promise<void> {
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`;
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
'onWebviewPanel'
]);

private configStorage: ConfigStorage | undefined;
private readonly registry = new Map<string, Plugin>();
private readonly activations = new Map<string, (() => Promise<void>)[] | undefined>();
/** promises to whether loading each plugin has been successful */
Expand Down Expand Up @@ -158,6 +159,8 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
}

async $start(params: PluginManagerStartParams): Promise<void> {
this.configStorage = params.configStorage;

const [plugins, foreignPlugins] = await this.host.init(params.plugins);
// add foreign plugins
for (const plugin of foreignPlugins) {
Expand Down Expand Up @@ -256,6 +259,10 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
}

async $updateStoragePath(path: string | undefined): Promise<void> {
if (this.configStorage) {
this.configStorage.hostStoragePath = path;
}

this.pluginContextsMap.forEach((pluginContext: theia.PluginContext, pluginId: string) => {
pluginContext.storagePath = path ? join(path, pluginId) : undefined;
});
Expand All @@ -272,6 +279,13 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
}
}

async $activatePlugin(id: string): Promise<void> {
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<void> {
const subscriptions: theia.Disposable[] = [];
Expand Down

0 comments on commit df213c3

Please sign in to comment.