From 50122d7fdc5b64b49fb9897f52278f73ad4e0c5c Mon Sep 17 00:00:00 2001 From: Olaf Lessenich Date: Fri, 10 Feb 2023 11:58:54 +0100 Subject: [PATCH] Add command line switch --no-native-window-frame This patch adds a command line switch `--no-native-window-frame` that prevents the app loader from using native menus in electron. We need this functionality for testing menu actions using electron playwright. When initialized with --no-native-window-frame, the app loader enforces the rendering of HTML menus that playwright can access. Contributed on behalf of STMicroelectronics Signed-off-by: Olaf Lessenich --- examples/playwright/src/theia-app-loader.ts | 2 +- .../src/electron-main/electron-main-application.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/playwright/src/theia-app-loader.ts b/examples/playwright/src/theia-app-loader.ts index bea923a8da7bd..d846324ff5f6a 100644 --- a/examples/playwright/src/theia-app-loader.ts +++ b/examples/playwright/src/theia-app-loader.ts @@ -104,7 +104,7 @@ export class ElectronLaunchOptions { constructor( protected readonly electronAppPath: string, protected readonly pluginsPath?: string, - protected readonly additionalArgs: string[] = ['--no-cluster'] + protected readonly additionalArgs: string[] = ['--no-cluster', '--no-native-window-frame'] ) { } playwrightOptions(workspace?: TheiaWorkspace): object { diff --git a/packages/core/src/electron-main/electron-main-application.ts b/packages/core/src/electron-main/electron-main-application.ts index 1a4d6d560fb92..9303030d8529d 100644 --- a/packages/core/src/electron-main/electron-main-application.ts +++ b/packages/core/src/electron-main/electron-main-application.ts @@ -197,7 +197,8 @@ export class ElectronMainApplication { } async start(config: FrontendApplicationConfig): Promise { - this.useNativeWindowFrame = this.getTitleBarStyle(config) === 'native'; + const args = this.processArgv.getProcessArgvWithoutBin(process.argv); + this.useNativeWindowFrame = this.getTitleBarStyle(config) === 'native' && !args.includes('--no-native-window-frame'); this._config = config; this.hookApplicationEvents(); const port = await this.startBackend(); @@ -207,7 +208,7 @@ export class ElectronMainApplication { await this.startContributions(); await this.launch({ secondInstance: false, - argv: this.processArgv.getProcessArgvWithoutBin(process.argv), + argv: args, cwd: process.cwd() }); } @@ -305,6 +306,9 @@ export class ElectronMainApplication { async openDefaultWindow(): Promise { const [uri, electronWindow] = await Promise.all([this.createWindowUri(), this.createWindow()]); + if (!this.useNativeWindowFrame) { + electronWindow.setMenuBarVisibility(false); + } electronWindow.loadURL(uri.withFragment(DEFAULT_WINDOW_HASH).toString(true)); return electronWindow; } @@ -312,6 +316,9 @@ export class ElectronMainApplication { protected async openWindowWithWorkspace(workspacePath: string): Promise { const options = await this.getLastWindowOptions(); const [uri, electronWindow] = await Promise.all([this.createWindowUri(), this.createWindow(options)]); + if (!this.useNativeWindowFrame) { + electronWindow.setMenuBarVisibility(false); + } electronWindow.loadURL(uri.withFragment(encodeURI(workspacePath)).toString(true)); return electronWindow; }