How to use the @theia/core/lib/common/event.Emitter function in @theia/core

To help you get started, we’ve selected a few @theia/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / plugin-ext / src / hosted / node / hosted-plugin-process.ts View on Github external
public terminatePluginServer(): void {
        if (this.childProcess === undefined) {
            return;
        }

        this.terminatingPluginServer = true;
        // tslint:disable-next-line:no-shadowed-variable
        const cp = this.childProcess;
        this.childProcess = undefined;

        const emitter = new Emitter();
        cp.on('message', message => {
            emitter.fire(JSON.parse(message));
        });
        const rpc = new RPCProtocolImpl({
            onMessage: emitter.event,
            send: (m: {}) => {
                if (cp.send) {
                    cp.send(JSON.stringify(m));
                }
            }
        });
        const hostedPluginManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
        hostedPluginManager.$stopPlugin('').then(() => {
            emitter.dispose();
            cp.kill();
        });
github eclipse-theia / theia / packages / plugin-ext / src / plugin / in-plugin-filesystem-watcher-proxy.ts View on Github external
constructor(
        subscriberData: SubscriberData,
        private isIgnoreCreateEvents: boolean = false,
        private isIgnoreChangeEvents: boolean = false,
        private isIgnoreDeleteEvents: boolean = false
    ) {
        this.onDidCreateEmitter = new Emitter();
        this.onDidChangeEmitter = new Emitter();
        this.onDidDeleteEmitter = new Emitter();

        this.subscriberData = subscriberData;
        subscriberData.event((event: FileSystemEvent) => {
            // Here ignore event flags are not analyzed because all the logic is
            // moved to server side to avoid unneded data transfer via network.
            // The flags are present just to be read only accesible for user.
            switch (event.type) {
                case 'updated':
                    this.onDidChangeEmitter.fire(event.uri);
                    break;
                case 'created':
                    this.onDidCreateEmitter.fire(event.uri);
                    break;
                case 'deleted':
                    this.onDidDeleteEmitter.fire(event.uri);
                    break;
github eclipse-theia / theia / packages / plugin-ext / src / hosted / browser / worker / worker-main.ts View on Github external
import { PreferenceRegistryExtImpl } from '../../../plugin/preference-registry';
import { ExtPluginApi } from '../../../common/plugin-ext-api-contribution';
import { createDebugExtStub } from './debug-stub';
import { EditorsAndDocumentsExtImpl } from '../../../plugin/editors-and-documents';
import { WorkspaceExtImpl } from '../../../plugin/workspace';
import { MessageRegistryExt } from '../../../plugin/message-registry';
import { WorkerEnvExtImpl } from './worker-env-ext';
import { ClipboardExt } from '../../../plugin/clipboard-ext';

// tslint:disable-next-line:no-any
const ctx = self as any;

const pluginsApiImpl = new Map();
const pluginsModulesNames = new Map();

const emitter = new Emitter();
const rpc = new RPCProtocolImpl({
    onMessage: emitter.event,
    send: (m: {}) => {
        ctx.postMessage(m);
    }
});
// tslint:disable-next-line:no-any
addEventListener('message', (message: any) => {
    emitter.fire(message.data);
});
function initialize(contextPath: string, pluginMetadata: PluginMetadata): void {
    ctx.importScripts('/context/' + contextPath);
}
const envExt = new WorkerEnvExtImpl(rpc);
const editorsAndDocuments = new EditorsAndDocumentsExtImpl(rpc);
const messageRegistryExt = new MessageRegistryExt(rpc);
github eclipse-theia / theia / packages / plugin-ext / src / plugin / in-plugin-filesystem-watcher-proxy.ts View on Github external
createFileSystemWatcher(
        globPattern: theia.GlobPattern,
        ignoreCreateEvents?: boolean,
        ignoreChangeEvents?: boolean,
        ignoreDeleteEvents?: boolean): theia.FileSystemWatcher {

        const perSubscriberEventEmitter = new Emitter();
        const subscriberPrivateData: SubscriberData = {
            event: perSubscriberEventEmitter.event
        };
        const fileWatcherSubscriberOptions: FileWatcherSubscriberOptions = { globPattern, ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents };
        // ids are generated by server side to be able handle several subscribers.
        this.proxy.$registerFileSystemWatcher(fileWatcherSubscriberOptions).then((id: string) => {
            // this is safe, because actual subscription happens on server side and response is
            // sent right after actual subscription, so no events are possible in between.
            this.subscribers.set(id, perSubscriberEventEmitter);
            subscriberPrivateData.unsubscribe = () => this.proxy.$unregisterFileSystemWatcher(id);
        });
        return new FileSystemWatcher(subscriberPrivateData, ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents);
    }
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / menus / menus-contribution-handler.ts View on Github external
protected registerTitleAction(location: string, action: Menu, handler: CommandHandler): Disposable {
        const toDispose = new DisposableCollection();
        const id = this.createSyntheticCommandId(action.command, { prefix: `__plugin.${location.replace('/', '.')}.action.` });
        const command: Command = { id };
        toDispose.push(this.commands.registerCommand(command, handler));

        const { when } = action;
        const whenKeys = when && this.contextKeyService.parseKeys(when);
        let onDidChange;
        if (whenKeys && whenKeys.size) {
            const onDidChangeEmitter = new Emitter();
            toDispose.push(onDidChangeEmitter);
            onDidChange = onDidChangeEmitter.event;
            this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners + 1;
            toDispose.push(this.contextKeyService.onDidChange(event => {
                if (event.affects(whenKeys)) {
                    onDidChangeEmitter.fire(undefined);
                }
            }));
            toDispose.push(Disposable.create(() => {
                this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners - 1;
            }));
        }

        // handle group and priority
        // if group is empty or white space is will be set to navigation
        // ' ' => ['navigation', 0]
github eclipse-theia / theia / packages / plugin-ext / src / plugin / in-plugin-filesystem-watcher-proxy.ts View on Github external
constructor(
        subscriberData: SubscriberData,
        private isIgnoreCreateEvents: boolean = false,
        private isIgnoreChangeEvents: boolean = false,
        private isIgnoreDeleteEvents: boolean = false
    ) {
        this.onDidCreateEmitter = new Emitter();
        this.onDidChangeEmitter = new Emitter();
        this.onDidDeleteEmitter = new Emitter();

        this.subscriberData = subscriberData;
        subscriberData.event((event: FileSystemEvent) => {
            // Here ignore event flags are not analyzed because all the logic is
            // moved to server side to avoid unneded data transfer via network.
            // The flags are present just to be read only accesible for user.
            switch (event.type) {
                case 'updated':
                    this.onDidChangeEmitter.fire(event.uri);
                    break;
                case 'created':
                    this.onDidCreateEmitter.fire(event.uri);
                    break;
                case 'deleted':
                    this.onDidDeleteEmitter.fire(event.uri);
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / plugin-worker.ts View on Github external
constructor() {
        const emitter = new Emitter();
        this.worker = new (require('../../hosted/browser/worker/worker-main'));
        this.worker.onmessage = message => {
            emitter.fire(message.data);
        };
        this.worker.onerror = e => console.error(e);

        this.rpc = new RPCProtocolImpl({
            onMessage: emitter.event,
            send: (m: {}) => {
                this.worker.postMessage(m);
            }
        });

    }
}
github eclipse-theia / theia / packages / plugin-ext / src / hosted / node / hosted-plugin.ts View on Github external
private terminatePluginServer(childProcess: cp.ChildProcess) {
        const emitter = new Emitter();
        childProcess.on('message', message => {
            emitter.fire(JSON.parse(message));
        });
        const rpc = new RPCProtocolImpl({
            onMessage: emitter.event,
            send: (m: {}) => {
                if (childProcess.send) {
                    childProcess.send(JSON.stringify(m));
                }
            }
        });
        const hostedPluginManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
        hostedPluginManager.$stopPlugin('').then(() => {
            emitter.dispose();
            childProcess.kill();
        });