Skip to content
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

Wait for plugins to deploy before restoring the current language #11472

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/core/src/node/i18n/localization-backend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

import * as express from 'express';
import { inject, injectable } from 'inversify';
import { Deferred } from '../../common/promise-util';
import { BackendApplicationContribution } from '../backend-application';
import { LocalizationRegistry } from './localization-contribution';
import { LocalizationProvider } from './localization-provider';

@injectable()
export class LocalizationBackendContribution implements BackendApplicationContribution {
protected readonly initialized = new Deferred<void>();

@inject(LocalizationRegistry)
protected readonly localizationRegistry: LocalizationRegistry;
Expand All @@ -31,15 +33,20 @@ export class LocalizationBackendContribution implements BackendApplicationContri

async initialize(): Promise<void> {
await this.localizationRegistry.initialize();
this.initialized.resolve();
}

waitForInitialization(): Promise<void> {
return this.initialized.promise;
}

configure(app: express.Application): void {
app.get('/i18n/:locale', (req, res) => {
app.get('/i18n/:locale', async (req, res) => {
await this.waitForInitialization();
let locale = req.params.locale;
locale = this.localizationProvider.getAvailableLanguages().some(e => e.languageId === locale) ? locale : 'en';
this.localizationProvider.setCurrentLanguage(locale);
res.send(this.localizationProvider.loadLocalization(locale));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ import { PluginTheiaEnvironment } from '../common/plugin-theia-environment';
import { PluginTheiaDeployerParticipant } from './plugin-theia-deployer-participant';
import { WebviewBackendSecurityWarnings } from './webview-backend-security-warnings';
import { PluginUninstallationManager } from './plugin-uninstallation-manager';
import { LocalizationBackendContribution } from '@theia/core/lib/node/i18n/localization-backend-contribution';
import { PluginLocalizationBackendContribution } from './plugin-localization-backend-contribution';

export function bindMainBackend(bind: interfaces.Bind): void {
export function bindMainBackend(bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind): void {
bind(PluginApiContribution).toSelf().inSingletonScope();
bind(BackendApplicationContribution).toService(PluginApiContribution);
bind(WsRequestValidatorContribution).toService(PluginApiContribution);
Expand Down Expand Up @@ -87,4 +89,7 @@ export function bindMainBackend(bind: interfaces.Bind): void {

bind(WebviewBackendSecurityWarnings).toSelf().inSingletonScope();
bind(BackendApplicationContribution).toService(WebviewBackendSecurityWarnings);

rebind(LocalizationBackendContribution).to(PluginLocalizationBackendContribution).inSingletonScope();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// *****************************************************************************
// Copyright (C) 2021 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 { inject, injectable } from '@theia/core/shared/inversify';
import { LocalizationBackendContribution } from '@theia/core/lib/node/i18n/localization-backend-contribution';
import { PluginDeployer } from '../../common/plugin-protocol';
import { PluginDeployerImpl } from './plugin-deployer-impl';
import { Deferred } from '@theia/core/lib/common/promise-util';

@injectable()
export class PluginLocalizationBackendContribution extends LocalizationBackendContribution {
@inject(PluginDeployer)
protected readonly pluginDeployer: PluginDeployerImpl;
protected readonly pluginsDeployed = new Deferred();

override async initialize(): Promise<void> {
this.pluginDeployer.onDidDeploy(() => {
this.pluginsDeployed.resolve();
});
await super.initialize();
}

override async waitForInitialization(): Promise<void> {
await Promise.all([
super.waitForInitialization(),
this.pluginsDeployed.promise,
]);
}
}
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/plugin-ext-backend-electron-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ContainerModule } from '@theia/core/shared/inversify';
import { bindElectronBackend } from './hosted/node-electron/plugin-ext-hosted-electron-backend-module';
import { bindMainBackend } from './main/node/plugin-ext-backend-module';

export default new ContainerModule(bind => {
bindMainBackend(bind);
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bindMainBackend(bind, unbind, isBound, rebind);
bindElectronBackend(bind);
});
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/plugin-ext-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ContainerModule } from '@theia/core/shared/inversify';
import { bindHostedBackend } from './hosted/node/plugin-ext-hosted-backend-module';
import { bindMainBackend } from './main/node/plugin-ext-backend-module';

export default new ContainerModule(bind => {
bindMainBackend(bind);
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bindMainBackend(bind, unbind, isBound, rebind);
bindHostedBackend(bind);
});