Skip to content

Commit

Permalink
fix: extra metadata is unavailable at webpack time
Browse files Browse the repository at this point in the history
merge in the frontend config and any other metadata from the final app's
package.json, as those are not available at theia build time.

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Aug 1, 2023
1 parent 28bc470 commit 75480bd
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 58 deletions.
45 changes: 19 additions & 26 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"type": "node",
"request": "launch",
"name": "App",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd",
},
"cwd": "${workspaceFolder}/electron-app",
"args": [
".",
"--log-level=debug",
"--hostname=localhost",
"--app-project-path=${workspaceRoot}/electron-app",
"--app-project-path=${workspaceFolder}/electron-app",
"--remote-debugging-port=9222",
"--no-app-auto-install",
"--plugins=local-dir:./plugins",
Expand All @@ -26,11 +26,11 @@
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/electron-app/src-gen/backend/*.js",
"${workspaceRoot}/electron-app/src-gen/frontend/*.js",
"${workspaceRoot}/electron-app/lib/**/*.js",
"${workspaceRoot}/arduino-ide-extension/lib/**/*.js",
"${workspaceRoot}/node_modules/@theia/**/*.js"
"${workspaceFolder}/electron-app/lib/backend/electron-main.js",
"${workspaceFolder}/electron-app/lib/backend/main.js",
"${workspaceFolder}/electron-app/lib/**/*.js",
"${workspaceFolder}/arduino-ide-extension/lib/**/*.js",
"${workspaceFolder}/node_modules/@theia/**/*.js"
],
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
Expand All @@ -40,16 +40,16 @@
"type": "node",
"request": "launch",
"name": "App [Dev]",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd",
},
"cwd": "${workspaceFolder}/electron-app",
"args": [
".",
"--log-level=debug",
"--hostname=localhost",
"--app-project-path=${workspaceRoot}/electron-app",
"--app-project-path=${workspaceFolder}/electron-app",
"--remote-debugging-port=9222",
"--no-app-auto-install",
"--plugins=local-dir:./plugins",
Expand All @@ -63,11 +63,11 @@
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/electron-app/src-gen/backend/*.js",
"${workspaceRoot}/electron-app/src-gen/frontend/*.js",
"${workspaceRoot}/electron-app/lib/**/*.js",
"${workspaceRoot}/arduino-ide-extension/lib/**/*.js",
"${workspaceRoot}/node_modules/@theia/**/*.js"
"${workspaceFolder}/electron-app/lib/backend/electron-main.js",
"${workspaceFolder}/electron-app/lib/backend/main.js",
"${workspaceFolder}/electron-app/lib/**/*.js",
"${workspaceFolder}/arduino-ide-extension/lib/**/*.js",
"${workspaceFolder}/node_modules/@theia/**/*.js"
],
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
Expand All @@ -84,7 +84,7 @@
"type": "node",
"request": "launch",
"name": "Run Test [current]",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--require",
"reflect-metadata/Reflect",
Expand All @@ -95,7 +95,7 @@
"**/${fileBasenameNoExtension}.js"
],
"env": {
"TS_NODE_PROJECT": "${workspaceRoot}/tsconfig.json",
"TS_NODE_PROJECT": "${workspaceFolder}/tsconfig.json",
"IDE2_TEST": "true"
},
"sourceMaps": true,
Expand All @@ -109,19 +109,12 @@
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "launch",
"name": "Electron Packager",
"program": "${workspaceRoot}/electron/packager/index.js",
"cwd": "${workspaceFolder}/electron/packager"
}
],
"compounds": [
{
"name": "Launch Electron Backend & Frontend",
"configurations": [
"App (Electron)",
"App",
"Attach to Electron Frontend"
]
}
Expand Down
5 changes: 4 additions & 1 deletion arduino-ide-extension/src/browser/app-service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { Disposable } from '@theia/core/lib/common/disposable';
import type { AppInfo } from '../electron-common/electron-arduino';
import type { StartupTasks } from '../electron-common/startup-task';
import type { Sketch } from './contributions/contribution';

export type { AppInfo };

export const AppService = Symbol('AppService');
export interface AppService {
quit(): void;
version(): Promise<string>;
info(): Promise<AppInfo>;
registerStartupTasksHandler(
handler: (tasks: StartupTasks) => void
): Disposable;
Expand Down
15 changes: 3 additions & 12 deletions arduino-ide-extension/src/browser/contributions/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { nls } from '@theia/core/lib/common/nls';
import { isOSX, isWindows } from '@theia/core/lib/common/os';
import { inject, injectable } from '@theia/core/shared/inversify';
import moment from 'moment';
import { ConfigService } from '../../common/protocol';
import { AppService } from '../app-service';
import { ArduinoMenus } from '../menu/arduino-menus';
import {
Expand All @@ -18,8 +17,6 @@ import {
export class About extends Contribution {
@inject(ClipboardService)
private readonly clipboardService: ClipboardService;
@inject(ConfigService)
private readonly configService: ConfigService;
@inject(AppService)
private readonly appService: AppService;

Expand All @@ -42,11 +39,9 @@ export class About extends Contribution {
}

private async showAbout(): Promise<void> {
const [appVersion, cliVersion] = await Promise.all([
this.appService.version(),
this.configService.getVersion(),
]);
const buildDate = this.buildDate;
const appInfo = await this.appService.info();
const { appVersion, cliVersion, buildDate } = appInfo;

const detail = (showAll: boolean) =>
nls.localize(
'arduino/about/detail',
Expand Down Expand Up @@ -84,10 +79,6 @@ export class About extends Contribution {
return FrontendApplicationConfigProvider.get().applicationName;
}

private get buildDate(): string | undefined {
return FrontendApplicationConfigProvider.get().buildDate;
}

private ago(isoTime: string): string {
const now = moment(Date.now());
const other = moment(isoTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { RecursivePartial } from '@theia/core/lib/common/types';
export const ConfigServicePath = '/services/config-service';
export const ConfigService = Symbol('ConfigService');
export interface ConfigService {
getVersion(): Promise<Readonly<string>>;
getConfiguration(): Promise<ConfigState>;
setConfiguration(config: Config): Promise<void>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Disposable } from '@theia/core/lib/common/disposable';
import { injectable } from '@theia/core/shared/inversify';
import type { AppService } from '../browser/app-service';
import type { AppInfo, AppService } from '../browser/app-service';
import type { Sketch } from '../common/protocol/sketches-service';
import type { StartupTasks } from '../electron-common/startup-task';

Expand All @@ -10,8 +10,8 @@ export class ElectronAppService implements AppService {
window.electronArduino.quitApp();
}

version(): Promise<string> {
return window.electronArduino.appVersion();
info(): Promise<AppInfo> {
return window.electronArduino.appInfo();
}

registerStartupTasksHandler(
Expand Down
4 changes: 2 additions & 2 deletions arduino-ide-extension/src/electron-browser/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { v4 } from 'uuid';
import type { Sketch } from '../common/protocol/sketches-service';
import {
CHANNEL_APP_VERSION,
CHANNEL_APP_INFO,
CHANNEL_IS_FIRST_WINDOW,
CHANNEL_MAIN_MENU_ITEM_DID_CLICK,
CHANNEL_OPEN_PATH,
Expand Down Expand Up @@ -76,7 +76,7 @@ const api: ElectronArduino = {
ipcRenderer.invoke(CHANNEL_SHOW_OPEN_DIALOG, options),
showSaveDialog: (options: SaveDialogOptions) =>
ipcRenderer.invoke(CHANNEL_SHOW_SAVE_DIALOG, options),
appVersion: () => ipcRenderer.invoke(CHANNEL_APP_VERSION),
appInfo: () => ipcRenderer.invoke(CHANNEL_APP_INFO),
quitApp: () => ipcRenderer.send(CHANNEL_QUIT_APP),
isFirstWindow: () => ipcRenderer.invoke(CHANNEL_IS_FIRST_WINDOW),
requestReload: (options: StartupTasks) =>
Expand Down
15 changes: 13 additions & 2 deletions arduino-ide-extension/src/electron-common/electron-arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import type {
InternalMenuDto as TheiaInternalMenuDto,
MenuDto,
} from '@theia/core/lib/electron-common/electron-api';

export const appInfoPropertyLiterals = [
'appVersion',
'cliVersion',
'buildDate',
] as const;
export type AppInfoProperty = (typeof appInfoPropertyLiterals)[number];
export type AppInfo = {
readonly [P in AppInfoProperty]: string;
};

import type { Sketch } from '../common/protocol/sketches-service';
import type { StartupTasks } from './startup-task';

Expand Down Expand Up @@ -50,7 +61,7 @@ export interface ElectronArduino {
showMessageBox(options: MessageBoxOptions): Promise<MessageBoxReturnValue>;
showOpenDialog(options: OpenDialogOptions): Promise<OpenDialogReturnValue>;
showSaveDialog(options: SaveDialogOptions): Promise<SaveDialogReturnValue>;
appVersion(): Promise<string>;
appInfo(): Promise<AppInfo>;
quitApp(): void;
isFirstWindow(): Promise<boolean>;
requestReload(tasks: StartupTasks): void;
Expand All @@ -77,7 +88,7 @@ declare global {
export const CHANNEL_SHOW_MESSAGE_BOX = 'Arduino:ShowMessageBox';
export const CHANNEL_SHOW_OPEN_DIALOG = 'Arduino:ShowOpenDialog';
export const CHANNEL_SHOW_SAVE_DIALOG = 'Arduino:ShowSaveDialog';
export const CHANNEL_APP_VERSION = 'Arduino:AppVersion';
export const CHANNEL_APP_INFO = 'Arduino:AppInfo';
export const CHANNEL_QUIT_APP = 'Arduino:QuitApp';
export const CHANNEL_IS_FIRST_WINDOW = 'Arduino:IsFirstWindow';
export const CHANNEL_SCHEDULE_DELETION = 'Arduino:ScheduleDeletion';
Expand Down
7 changes: 4 additions & 3 deletions arduino-ide-extension/src/electron-main/electron-arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { createDisposableListener } from '@theia/core/lib/electron-main/event-ut
import { injectable } from '@theia/core/shared/inversify';
import { WebContents } from '@theia/electron/shared/electron';
import {
CHANNEL_APP_VERSION,
AppInfo,
CHANNEL_APP_INFO,
CHANNEL_IS_FIRST_WINDOW,
CHANNEL_MAIN_MENU_ITEM_DID_CLICK,
CHANNEL_OPEN_PATH,
Expand Down Expand Up @@ -85,8 +86,8 @@ export class ElectronArduino implements ElectronMainApplicationContribution {
return result;
}
);
ipcMain.handle(CHANNEL_APP_VERSION, async () => {
return app.appVersion;
ipcMain.handle(CHANNEL_APP_INFO, async (): Promise<AppInfo> => {
return app.appInfo;
});
ipcMain.on(CHANNEL_QUIT_APP, () => app.requestStop());
ipcMain.handle(CHANNEL_IS_FIRST_WINDOW, async (event) => {
Expand Down
Loading

0 comments on commit 75480bd

Please sign in to comment.