-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor core messaging and RPC (electron-only so far) #11076
Changes from all commits
6ef83cd
4376020
7d48ba3
ecd3d2b
3bf1513
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,7 +20,6 @@ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify' | |||||||||||||||||
import { isOSX } from '@theia/core/lib/common/os'; | ||||||||||||||||||
import { CommonMenus } from '@theia/core/lib/browser'; | ||||||||||||||||||
import { | ||||||||||||||||||
Emitter, | ||||||||||||||||||
Command, | ||||||||||||||||||
MenuPath, | ||||||||||||||||||
MessageService, | ||||||||||||||||||
|
@@ -31,7 +30,7 @@ import { | |||||||||||||||||
} from '@theia/core/lib/common'; | ||||||||||||||||||
import { ElectronMainMenuFactory } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory'; | ||||||||||||||||||
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider'; | ||||||||||||||||||
import { SampleUpdater, UpdateStatus, SampleUpdaterClient } from '../../common/updater/sample-updater'; | ||||||||||||||||||
import { SampleUpdater, UpdateStatus } from '../../common/updater/sample-updater'; | ||||||||||||||||||
|
||||||||||||||||||
export namespace SampleUpdaterCommands { | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -68,18 +67,6 @@ export namespace SampleUpdaterMenu { | |||||||||||||||||
export const MENU_PATH: MenuPath = [...CommonMenus.FILE_SETTINGS_SUBMENU, '3_settings_submenu_update']; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
@injectable() | ||||||||||||||||||
export class SampleUpdaterClientImpl implements SampleUpdaterClient { | ||||||||||||||||||
|
||||||||||||||||||
protected readonly onReadyToInstallEmitter = new Emitter<void>(); | ||||||||||||||||||
readonly onReadyToInstall = this.onReadyToInstallEmitter.event; | ||||||||||||||||||
|
||||||||||||||||||
notifyReadyToInstall(): void { | ||||||||||||||||||
this.onReadyToInstallEmitter.fire(); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
-71
to
-81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very important change with the new RPC/proxy API: we no longer setup "clients" to get notifications back from the remote: we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is actually an improvement. How is this better than the old way of setting up service objects on both ends? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fear this might make initialization of service objects more complicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how this makes things more complicated. I keep deleting code to use this new API. |
||||||||||||||||||
|
||||||||||||||||||
// Dynamic menus aren't yet supported by electron: https://github.com/eclipse-theia/theia/issues/446 | ||||||||||||||||||
@injectable() | ||||||||||||||||||
export class ElectronMenuUpdater { | ||||||||||||||||||
|
@@ -113,14 +100,11 @@ export class SampleUpdaterFrontendContribution implements CommandContribution, M | |||||||||||||||||
@inject(SampleUpdater) | ||||||||||||||||||
protected readonly updater: SampleUpdater; | ||||||||||||||||||
|
||||||||||||||||||
@inject(SampleUpdaterClientImpl) | ||||||||||||||||||
protected readonly updaterClient: SampleUpdaterClientImpl; | ||||||||||||||||||
|
||||||||||||||||||
protected readyToUpdate = false; | ||||||||||||||||||
|
||||||||||||||||||
@postConstruct() | ||||||||||||||||||
protected init(): void { | ||||||||||||||||||
this.updaterClient.onReadyToInstall(async () => { | ||||||||||||||||||
this.updater.onReadyToInstall(async () => { | ||||||||||||||||||
Comment on lines
-116
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's an example of directly using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally don't mind boilerplate code if it's simpler to understand than the alternative. Typing is not the problem in software construction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typing prevents mistakes. This apart, the previous required boilerplate code for the The new API allows servers to expose their events through proxies. For requests going the other way from the main RPC setup you can just create a new dedicated proxy. Just as an example, the most egregious implementation I've seen using clients must be this one: theia/packages/terminal/src/browser/terminal-frontend-contribution.ts Lines 199 to 206 in fd14c0b
Here In my latest changes I replaced the idea of the client on the server side by a proxy from the frontend implementing storage methods. The server just does |
||||||||||||||||||
this.readyToUpdate = true; | ||||||||||||||||||
this.menuUpdater.update(); | ||||||||||||||||||
this.handleUpdatesAvailable(); | ||||||||||||||||||
|
@@ -138,7 +122,7 @@ export class SampleUpdaterFrontendContribution implements CommandContribution, M | |||||||||||||||||
} | ||||||||||||||||||
case UpdateStatus.NotAvailable: { | ||||||||||||||||||
const { applicationName } = FrontendApplicationConfigProvider.get(); | ||||||||||||||||||
this.messageService.info(`[Not Available]: You’re all good. You’ve got the latest version of ${applicationName}.`, { timeout: 3000 }); | ||||||||||||||||||
this.messageService.info(`[Not Available]: You're all good. You've got the latest version of ${applicationName}.`, { timeout: 3000 }); | ||||||||||||||||||
break; | ||||||||||||||||||
} | ||||||||||||||||||
case UpdateStatus.InProgress: { | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ***************************************************************************** | ||
// 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, servicePath } from '@theia/core/lib/common'; | ||
|
||
export const ELECTRON_MAIN_AND_BACKEND_IPC_SAMPLE_PATH = servicePath<ElectronMainAndBackendIpcSample>('/services/test-connection'); | ||
export const ElectronMainAndBackendIpcSample = serviceIdentifier<ElectronMainAndBackendIpcSample>('TestConnection'); | ||
export interface ElectronMainAndBackendIpcSample { | ||
getBrowserWindowTitles(): Promise<string[]> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// ***************************************************************************** | ||
// 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 { ElectronMainAndBackendIpcSample, ELECTRON_MAIN_AND_BACKEND_IPC_SAMPLE_PATH } from '../../electron-common/ipc/electron-ipc'; | ||
import { ElectronMainAndBackendIpcSampleImpl } from './electron-main-ipc-impl'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(ElectronMainAndBackendIpcSample).to(ElectronMainAndBackendIpcSampleImpl).inSingletonScope(); | ||
bind(ServiceContribution) | ||
.toDynamicValue(ctx => ({ | ||
[ELECTRON_MAIN_AND_BACKEND_IPC_SAMPLE_PATH]: () => ctx.container.get(ElectronMainAndBackendIpcSample) | ||
})) | ||
.inSingletonScope() | ||
.whenTargetNamed(ElectronMainAndBackend); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mean by "drive by fix". Yes, it's a good fix, but unrelated to the problem at hand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough on this one.