Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jun 20, 2023
1 parent c2e4cb8 commit 3aca353
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,31 @@ function defaultServeStatic(app) {
}
function load(raw) {
return Promise.resolve(raw.default).then(
module => container.load(module)
return Promise.resolve(raw).then(
module => container.load(module.default)
);
}
function start(port, host, argv = process.argv) {
async function start(port, host, argv = process.argv) {
if (!container.isBound(BackendApplicationServer)) {
container.bind(BackendApplicationServer).toConstantValue({ configure: defaultServeStatic });
}
return container.get(CliManager).initializeCli(argv).then(() => {
return container.get(BackendApplication).start(port, host);
});
await container.get(CliManager).initializeCli(argv);
await container.get(BackendApplication).start(port, host);
}
module.exports = (port, host, argv) => Promise.resolve()${this.compileBackendModuleImports(backendModules)}
.then(() => start(port, host, argv)).catch(error => {
module.exports = async (port, host, argv) => {
try {
${Array.from(backendModules.values(), jsModulePath => `\
await load(require('${jsModulePath}'));`).join('\n')}
await start(port, host, argv);
} catch (error) {
console.error('Failed to start the backend application:');
console.error(error);
process.exitCode = 1;
throw error;
});
}
}
`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export class FrontendGenerator extends AbstractGenerator {
}

protected compileIndexJs(frontendModules: Map<string, string>, frontendPreloadModules: Map<string, string>): string {
const compiledModuleImports = this.compileFrontendModuleImports(frontendModules, 2);
const compiledPreloadModuleImports = this.compileFrontendModuleImports(frontendPreloadModules, 2);
return `\
// @ts-check
${this.ifBrowser("require('es6-promise/auto');")}
Expand All @@ -89,23 +87,29 @@ self.MonacoEnvironment = {
}
}`)}
function preload() {
const preloadContainer = new Container();
function load(container, jsModule) {
return Promise.resolve(jsModule)
.then(containerModule => container.load(containerModule.default));
}
return Promise.resolve()${compiledPreloadModuleImports}
.then(() => {
const { Preloader } = require('@theia/core/lib/browser/preload/preloader');
const preloader = preloadContainer.get(Preloader);
return preloader.initialize();
});
function load(jsModule) {
return Promise.resolve(jsModule.default)
.then(containerModule => preloadContainer.load(containerModule));
async function preload() {
const container = new Container();
try {
${Array.from(frontendPreloadModules.values(), jsModulePath => `\
await load(container, import('${jsModulePath}'));`).join('\n')}
const { Preloader } = require('@theia/core/lib/browser/preload/preloader');
const preloader = container.get(Preloader);
await preloader.initialize();
} catch (reason) {
console.error('Failed to run preload scripts.');
if (reason) {
console.error(reason);
}
}
}
module.exports = preload().then(() => {
module.exports = async () => {
await preload();
const { FrontendApplication } = require('@theia/core/lib/browser');
const { frontendApplicationModule } = require('@theia/core/lib/browser/frontend-application-module');
const { messagingFrontendModule } = require('@theia/core/lib/${this.pck.isBrowser()
Expand All @@ -118,24 +122,22 @@ module.exports = preload().then(() => {
container.load(messagingFrontendModule);
container.load(loggerFrontendModule);
return Promise.resolve()${compiledModuleImports}
.then(start).catch(reason => {
console.error('Failed to start the frontend application.');
if (reason) {
console.error(reason);
}
});
function load(jsModule) {
return Promise.resolve(jsModule.default)
.then(containerModule => container.load(containerModule));
try {
${Array.from(frontendModules.values(), jsModulePath => `\
await load(container, import('${jsModulePath}'));`).join('\n')}
await start();
} catch (reason) {
console.error('Failed to start the frontend application.');
if (reason) {
console.error(reason);
}
}
function start() {
(window['theia'] = window['theia'] || {}).container = container;
return container.get(FrontendApplication).start();
}
});
};
`;
}

Expand Down Expand Up @@ -196,13 +198,19 @@ async function start() {
await application.start(config);
}
module.exports = Promise.resolve()${this.compileElectronMainModuleImports(electronMainModules)}
.then(start).catch(reason => {
module.exports = async () => {
try {
${Array.from(electronMainModules?.values() ?? [], jsModulePath => `\
await load(container, import('${jsModulePath}'));`).join('\n')}
await start();
} catch (reason) {
console.error('Failed to start the electron application.');
if (reason) {
console.error(reason);
}
});
}
};
`;
}

Expand Down
40 changes: 8 additions & 32 deletions dev-packages/application-package/src/application-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,59 +137,35 @@ export class ApplicationPackage {
}

get frontendPreloadModules(): Map<string, string> {
if (!this._frontendPreloadModules) {
this._frontendPreloadModules = this.computeModules('frontendPreload');
}
return this._frontendPreloadModules;
return this._frontendPreloadModules ??= this.computeModules('frontendPreload');
}

get frontendModules(): Map<string, string> {
if (!this._frontendModules) {
this._frontendModules = this.computeModules('frontend');
}
return this._frontendModules;
return this._frontendModules ??= this.computeModules('frontend');
}

get frontendElectronModules(): Map<string, string> {
if (!this._frontendElectronModules) {
this._frontendElectronModules = this.computeModules('frontendElectron', 'frontend');
}
return this._frontendElectronModules;
return this._frontendElectronModules ??= this.computeModules('frontendElectron', 'frontend');
}

get secondaryWindowModules(): Map<string, string> {
if (!this._secondaryWindowModules) {
this._secondaryWindowModules = this.computeModules('secondaryWindow');
}
return this._secondaryWindowModules;
return this._secondaryWindowModules ??= this.computeModules('secondaryWindow');
}

get backendModules(): Map<string, string> {
if (!this._backendModules) {
this._backendModules = this.computeModules('backend');
}
return this._backendModules;
return this._backendModules ??= this.computeModules('backend');
}

get backendElectronModules(): Map<string, string> {
if (!this._backendElectronModules) {
this._backendElectronModules = this.computeModules('backendElectron', 'backend');
}
return this._backendElectronModules;
return this._backendElectronModules ??= this.computeModules('backendElectron', 'backend');
}

get electronMainModules(): Map<string, string> {
if (!this._electronMainModules) {
this._electronMainModules = this.computeModules('electronMain');
}
return this._electronMainModules;
return this._electronMainModules ??= this.computeModules('electronMain');
}

get preloadModules(): Map<string, string> {
if (!this._preloadModules) {
this._preloadModules = this.computeModules('preload');
}
return this._preloadModules;
return this._preloadModules ??= this.computeModules('preload');
}

protected computeModules<P extends keyof Extension, S extends keyof Extension = P>(primary: P, secondary?: S): Map<string, string> {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/preload/preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import { Endpoint } from '../endpoint';
import { MaybePromise } from '../../common/types';
import { inject, injectable, named } from 'inversify';
import { inject, injectable, interfaces, named } from 'inversify';
import { ContributionProvider } from '../../common/contribution-provider';

export const PreloadContribution = Symbol('PreloadContribution');
export const PreloadContribution = Symbol('PreloadContribution') as symbol & interfaces.Abstract<PreloadContribution>;

export interface PreloadContribution {
initialize(): MaybePromise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ export class ThemePreloadContribution implements PreloadContribution {
initialize(): void {
// The default light background color is based on the `colors#editor.background` value from
// `packages/monaco/data/monaco-themes/vscode/dark_vs.json` and the dark background comes from the `light_vs.json`.
const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const dark = window.matchMedia?.('(prefers-color-scheme: dark)').matches;
const value = window.localStorage.getItem(DEFAULT_BACKGROUND_COLOR_STORAGE_KEY) || (dark ? '#1E1E1E' : '#FFFFFF');
const documentElement = document.documentElement;
documentElement.style.setProperty('--theia-editor-background', value);
document.documentElement.style.setProperty('--theia-editor-background', value);
}

}

0 comments on commit 3aca353

Please sign in to comment.