Skip to content

Commit

Permalink
Add command line switch --no-native-window-frame
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
xai committed Feb 22, 2023
1 parent fd9a878 commit 50122d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/playwright/src/theia-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/electron-main/electron-main-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ export class ElectronMainApplication {
}

async start(config: FrontendApplicationConfig): Promise<void> {
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();
Expand All @@ -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()
});
}
Expand Down Expand Up @@ -305,13 +306,19 @@ export class ElectronMainApplication {

async openDefaultWindow(): Promise<BrowserWindow> {
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;
}

protected async openWindowWithWorkspace(workspacePath: string): Promise<BrowserWindow> {
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;
}
Expand Down

0 comments on commit 50122d7

Please sign in to comment.