Skip to content

Commit 17c3a58

Browse files
committed
feat: do not use native file chooser when --no-native-window-frame is provided
Contributed on behalf of STMicroelectronics Signed-off-by: Olaf Lessenich <[email protected]>
1 parent 764838a commit 17c3a58

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

examples/playwright/configs/playwright.config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ const config: PlaywrightTestConfig = {
2525
use: {
2626
baseURL: 'http://localhost:3000',
2727
browserName: 'chromium',
28-
screenshot: 'only-on-failure',
29-
viewport: { width: 1920, height: 1080 },
30-
trace: {
31-
mode: 'retain-on-failure'
32-
}
28+
screenshot: 'only-on-failure'
3329
},
3430
preserveOutput: 'failures-only',
3531
reporter: [

examples/playwright/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
"lint": "eslint -c ./.eslintrc.js --ext .ts ./src",
1919
"lint:fix": "eslint -c ./.eslintrc.js --ext .ts ./src --fix",
2020
"watch": "tsc --watch",
21-
"ui-tests": "yarn && playwright test --config=./configs/playwright.config.ts",
22-
"ui-tests-ci": "yarn && playwright test --config=./configs/playwright.ci.config.ts",
23-
"ui-tests-headful": "yarn && playwright test --config=./configs/playwright.headful.config.ts",
21+
"rebuild": "yarn --cwd ../browser rebuild && yarn --cwd ../electron rebuild",
22+
"ui-tests": "yarn && yarn rebuild && playwright test --config=./configs/playwright.config.ts",
23+
"ui-tests-ci": "yarn && yarn rebuild && playwright test --config=./configs/playwright.ci.config.ts",
24+
"ui-tests-headful": "yarn && yarn rebuild && playwright test --config=./configs/playwright.headful.config.ts",
2425
"ui-tests-report-generate": "allure generate ./allure-results --clean -o allure-results/allure-report",
2526
"ui-tests-report": "yarn ui-tests-report-generate && allure open allure-results/allure-report"
2627
},

examples/playwright/src/theia-app-loader.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
// *****************************************************************************
1616

1717
import { Page, PlaywrightWorkerArgs, _electron as electron } from '@playwright/test';
18+
import * as path from 'path';
19+
import * as fs from 'fs';
1820
import { TheiaApp, TheiaAppMainPageObjects } from './theia-app';
1921
import { TheiaWorkspace } from './theia-workspace';
22+
import { OSUtil } from './util';
2023

2124
export interface TheiaAppFactory<T extends TheiaApp> {
2225
new(page: Page, initialWorkspace?: TheiaWorkspace, mainPageObjects?: TheiaAppMainPageObjects): T;
@@ -108,7 +111,16 @@ export class ElectronLaunchOptions {
108111
) { }
109112

110113
playwrightOptions(workspace?: TheiaWorkspace): object {
111-
const executablePath = this.electronAppPath + '/node_modules/.bin/electron';
114+
let executablePath = path.normalize(path.join(this.electronAppPath, 'node_modules/.bin/electron'));
115+
if (OSUtil.isWindows) {
116+
executablePath += '.cmd';
117+
}
118+
if (!fs.existsSync(executablePath)) {
119+
const errorMsg = `executablePath: ${executablePath} does not exist`;
120+
console.log(errorMsg);
121+
throw new Error(errorMsg);
122+
}
123+
112124
const args: string[] = [];
113125
args.push(this.electronAppPath);
114126
args.push(...this.additionalArgs);
@@ -119,6 +131,7 @@ export class ElectronLaunchOptions {
119131
if (workspace) {
120132
args.push(workspace.path);
121133
}
134+
console.log(`Launching Electron from ${executablePath} with args: ${args.join(' ')}`);
122135
return { executablePath, args };
123136
}
124137
}

packages/filesystem/src/electron-browser/file-dialog/electron-file-dialog-module.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,39 @@
1515
// *****************************************************************************
1616

1717
import { ContainerModule } from '@theia/core/shared/inversify';
18-
import { FileDialogService } from '../../browser/file-dialog/file-dialog-service';
18+
import { DefaultFileDialogService, FileDialogService } from '../../browser/file-dialog/file-dialog-service';
1919
import { ElectronFileDialogService } from './electron-file-dialog-service';
20+
import * as electronRemote from '@theia/core/electron-shared/@electron/remote';
21+
import { LocationListRenderer, LocationListRendererFactory, LocationListRendererOptions } from '../../browser/location';
22+
import { FileDialogHiddenFilesToggleRenderer, HiddenFilesToggleRendererFactory } from '../../browser/file-dialog/file-dialog-hidden-files-renderer';
23+
import { FileDialogTree } from '../../browser/file-dialog/file-dialog-tree';
24+
import { FileDialogTreeFiltersRenderer, FileDialogTreeFiltersRendererFactory, FileDialogTreeFiltersRendererOptions } from '../../browser/file-dialog';
2025

2126
export default new ContainerModule(bind => {
22-
bind(ElectronFileDialogService).toSelf().inSingletonScope();
23-
bind(FileDialogService).toService(ElectronFileDialogService);
27+
const useNativeFileDialogs: boolean = !electronRemote.app.commandLine.hasSwitch('no-native-window-frame');
28+
if (useNativeFileDialogs) {
29+
bind(ElectronFileDialogService).toSelf().inSingletonScope();
30+
bind(FileDialogService).toService(ElectronFileDialogService);
31+
} else {
32+
bind(DefaultFileDialogService).toSelf().inSingletonScope();
33+
bind(FileDialogService).toService(DefaultFileDialogService);
34+
bind(LocationListRendererFactory).toFactory(context => (options: LocationListRendererOptions) => {
35+
const childContainer = context.container.createChild();
36+
childContainer.bind(LocationListRendererOptions).toConstantValue(options);
37+
childContainer.bind(LocationListRenderer).toSelf().inSingletonScope();
38+
return childContainer.get(LocationListRenderer);
39+
});
40+
bind(FileDialogTreeFiltersRendererFactory).toFactory(context => (options: FileDialogTreeFiltersRendererOptions) => {
41+
const childContainer = context.container.createChild();
42+
childContainer.bind(FileDialogTreeFiltersRendererOptions).toConstantValue(options);
43+
childContainer.bind(FileDialogTreeFiltersRenderer).toSelf().inSingletonScope();
44+
return childContainer.get(FileDialogTreeFiltersRenderer);
45+
});
46+
bind(HiddenFilesToggleRendererFactory).toFactory(({ container }) => (fileDialogTree: FileDialogTree) => {
47+
const child = container.createChild();
48+
child.bind(FileDialogTree).toConstantValue(fileDialogTree);
49+
child.bind(FileDialogHiddenFilesToggleRenderer).toSelf().inSingletonScope();
50+
return child.get(FileDialogHiddenFilesToggleRenderer);
51+
});
52+
}
2453
});

0 commit comments

Comments
 (0)