Skip to content

Commit

Permalink
eclipse-che/che#9063 add simple worker script and frontend module
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Mar 14, 2018
1 parent 4ace0db commit 2a48ec6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/isolated-extension-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"theiaExtensions": [
{
"backend": "lib/node/extension-api-backend-module"
"backend": "lib/node/extension-api-backend-module",
"frontend": "lib/browser/extension-api-frontend-module"
}
],
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2015-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
import { ContainerModule } from "inversify";
import { FrontendApplicationContribution, FrontendApplication } from "@theia/core/lib/browser";
import { MaybePromise } from "@theia/core/lib/common";

export default new ContainerModule(bind => {
bind(FrontendApplicationContribution).toDynamicValue(ctx => ({
onStart(app: FrontendApplication): MaybePromise<void> {
const worker = new Worker('/webworker/worker-main.ts');
worker.addEventListener('message', message => {
console.log(message);
});
}
}));
});
37 changes: 37 additions & 0 deletions packages/isolated-extension-api/src/worker/worker-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { RPCProtocolImpl, createExtensionProxyIdentifier } from '../api/rpc-protocol';
import { Emitter } from '@theia/core/lib/common/event';
import { Disposable } from '@theia/core/lib/common/disposable';
export interface MainThreadCommandsShape extends Disposable {
$registerCommand(id: string): void;
$unregisterCommand(id: string): void;
$executeCommand<T>(id: string, args: any[]): Thenable<T>;
$getCommands(): Thenable<string[]>;
}

const emmitter = new Emitter();
const rpc = new RPCProtocolImpl({
onMessage: emmitter.event,
send: (m: {}) => {
postMessage(m);
}
});
addEventListener('message', (message: any) => {
emmitter.fire(message.data);
});

const ExtHostCommands = createExtensionProxyIdentifier<MainThreadCommandsShape>("MainThreadCommands");

const proxy = rpc.getProxy(ExtHostCommands);

proxy.$registerCommand('foo');

0 comments on commit 2a48ec6

Please sign in to comment.