Skip to content

Commit

Permalink
refactor Electron IPC connections
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-marechal committed Apr 6, 2022
1 parent 3893fde commit e8b5605
Show file tree
Hide file tree
Showing 46 changed files with 2,398 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const serverAddress = main.start(serverModule());
serverAddress.then(({ port, address }) => {
if (process && process.send) {
process.send({ port, address });
process.send({ channel: 'backend-start', port, address });
}
});
Expand Down
6 changes: 3 additions & 3 deletions doc/Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ This version updates the Monaco code used in Theia to the state of VSCode 1.65.2

#### ASM to ESM

Two kinds of changes may be required to consume Monaco using ESM modules.
Two kinds of changes may be required to consume Monaco using ESM modules.

- If your application uses its own Webpack config rather than that generated by the @theia/dev-packages, you
will need to update that config to remove the `CopyWebpackPlugin` formerly used to place Monaco
code in the build folder and to build a separate entrypoint for the `editor.worker`. See [the changes here](https://github.com/eclipse-theia/theia/pull/10736/files#diff-b4677f3ff57d8b952eeefc10493ed3600d2737f9b5c9b0630b172472acb9c3a2)
- If your application uses its own frontend generator, you should modify the code that generates the `index.html` to load the `script` containing the bundle into the `body` element rather than the head. See [changes here](https://github.com/eclipse-theia/theia/pull/10947/files)
- References to the `window.monaco` object should be replaced with imports from `@theia/monaco-editor-core`. In most cases, simply adding an import `import * as monaco from
'@theia/monaco-editor-core'` will suffice. More complex use cases may require imports from specific parts of Monaco. Please see
- References to the `window.monaco` object should be replaced with imports from `@theia/monaco-editor-core`. In most cases, simply adding an import `import * as monaco from
'@theia/monaco-editor-core'` will suffice. More complex use cases may require imports from specific parts of Monaco. Please see
[the PR](https://github.com/eclipse-theia/theia/pull/10736) for details, and please post any questions or problems there.

Using ESM modules, it is now possible to follow imports to definitions and to the Monaco source code. This should aid in tracking down issues related to changes in Monaco discussed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// *****************************************************************************
// Copyright (C) 2022 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { serviceIdentifier } from "@theia/core/lib/common";

export const TEST_CONNECTION_PATH = '/services/test-connection';

export const TestConnection = serviceIdentifier<TestConnection>('TestConnection');
export interface TestConnection {
runTest(): Promise<string[]>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// *****************************************************************************
// Copyright (C) 2022 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { BrowserWindow } from '@theia/electron/shared/electron';
import { injectable } from 'inversify';
import { TestConnection } from '../../electron-common/ipc/electron-test-connection';

@injectable()
export class TestConnectionImpl implements TestConnection {

async runTest(): Promise<string[]> {
return BrowserWindow.getAllWindows().map(browserWindow => browserWindow.getTitle());
}
}
33 changes: 33 additions & 0 deletions examples/api-samples/src/electron-main/ipc/sample-ipc-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// *****************************************************************************
// Copyright (C) 2022 Ericsson// *****************************************************************************
// Copyright (C) 2020 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { ServiceContribution } from '@theia/core/lib/common';
import { ElectronMainAndBackend } from '@theia/core/lib/electron-common';
import { ContainerModule } from '@theia/core/shared/inversify';
import { TestConnection } from '../../electron-common/ipc/electron-test-connection';
import { TEST_CONNECTION_PATH } from '../../electron-common/ipc/electron-test-connection';
import { TestConnectionImpl } from './electron-test-connection';

export default new ContainerModule(bind => {
bind(TestConnection).to(TestConnectionImpl).inSingletonScope();
bind(ServiceContribution)
.toDynamicValue(ctx => ({
[TEST_CONNECTION_PATH]: () => ctx.container.get(TestConnection)
}))
.inSingletonScope()
.whenTargetNamed(ElectronMainAndBackend);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// *****************************************************************************
// Copyright (C) 2022 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import { ProxyProvider } from '@theia/core';
import { ElectronMainAndBackend } from '@theia/core/lib/electron-common';
import { ContainerModule } from '@theia/core/shared/inversify';
import { TestConnection, TEST_CONNECTION_PATH } from '../../electron-common/ipc/electron-test-connection';

export default new ContainerModule(bind => {
bind(TestConnection)
.toDynamicValue(ctx => ctx.container.getNamed(ProxyProvider, ElectronMainAndBackend).getProxy(TEST_CONNECTION_PATH))
.inSingletonScope();
});
1 change: 1 addition & 0 deletions license-check-baseline.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"npm/npmjs/-/doctrine/2.1.0": "Approved: https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/1987",
"npm/npmjs/-/eslint-plugin-deprecation/1.2.1": "Approved as 'works-with': https://dev.eclipse.org/ipzilla/show_bug.cgi?id=22573",
"npm/npmjs/-/jschardet/2.3.0": "Approved for Eclipse Theia: https://dev.eclipse.org/ipzilla/show_bug.cgi?id=22481",
"npm/npmjs/-/jsdom/11.12.0": "Approved as 'works-with': https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23640https://dev.eclipse.org/ipzilla/show_bug.cgi?id=23640",
Expand Down
Loading

0 comments on commit e8b5605

Please sign in to comment.