Skip to content

Commit

Permalink
#2190 create plugin api after plugin initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Jun 28, 2018
1 parent 3fbd5e5 commit 1a20ce3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
29 changes: 20 additions & 9 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class HostedPluginSupport {

private theiaReadyPromise: Promise<any>;

private backendApiInitialized = false;
private frontendApiInitialized = false;

constructor(
@inject(PreferenceServiceImpl) private readonly preferenceServiceImpl: PreferenceServiceImpl
) {
Expand Down Expand Up @@ -75,7 +78,6 @@ export class HostedPluginSupport {
if (pluginModel.entryPoint!.frontend) {
this.logger.info(`Loading frontend hosted plugin: ${pluginModel.name}`);
this.worker = new PluginWorker();
setUpPluginApi(this.worker.rpc, container);

this.theiaReadyPromise.then(() => {
const hostedExtManager = this.worker.rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
Expand All @@ -84,19 +86,23 @@ export class HostedPluginSupport {
model: pluginModel,
lifecycle: pluginLifecycle
};
const frontendInitPath = pluginLifecycle.frontendInitPath;
let frontendInitPath = pluginLifecycle.frontendInitPath;
if (frontendInitPath) {
hostedExtManager.$initialize(frontendInitPath, pluginMetadata);
hostedExtManager.$loadPlugin(frontendInitPath, plugin);
} else {
hostedExtManager.$loadPlugin('', plugin);
frontendInitPath = '';
}
// we should create only one instance of the plugin api per connection
if (!this.frontendApiInitialized) {
setUpPluginApi(this.worker.rpc, container);
this.frontendApiInitialized = true;
}
hostedExtManager.$loadPlugin(frontendInitPath, plugin);
});
}
if (pluginModel.entryPoint!.backend) {
this.logger.info(`Loading backend hosted plugin: ${pluginModel.name}`);
const rpc = this.createServerRpc();
setUpPluginApi(rpc, container);

this.theiaReadyPromise.then(() => {
const hostedExtManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
Expand All @@ -105,21 +111,26 @@ export class HostedPluginSupport {
model: pluginModel,
lifecycle: pluginLifecycle
};
const backendInitPath = pluginLifecycle.backendInitPath;
let backendInitPath = pluginLifecycle.backendInitPath;
if (backendInitPath) {
hostedExtManager.$initialize(backendInitPath, pluginMetadata);
hostedExtManager.$loadPlugin(backendInitPath, plugin);
} else {
hostedExtManager.$loadPlugin('', plugin);
backendInitPath = '';
}
// we should create only one instance of the plugin api per connection
if (!this.backendApiInitialized) {
setUpPluginApi(rpc, container);
this.backendApiInitialized = true;
}
hostedExtManager.$loadPlugin(backendInitPath, plugin);
});
}
}

private createServerRpc(): RPCProtocol {
return new RPCProtocolImpl({
onMessage: this.watcher.onPostMessageEvent,
send: message => { this.logger.info('sending to ', this.server, 'the message', message); this.server.onMessage(JSON.stringify(message)); }
send: message => { this.server.onMessage(JSON.stringify(message)); }
});
}
}
1 change: 1 addition & 0 deletions packages/plugin-ext/src/hosted/node/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class HostedPluginSupport {
});
const hostedPluginManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
hostedPluginManager.$stopPlugin('').then(() => {
emitter.dispose();
childProcess.kill();
});
}
Expand Down

0 comments on commit 1a20ce3

Please sign in to comment.