Skip to content

Commit

Permalink
feat: do not use native file chooser when --no-native-window-frame is…
Browse files Browse the repository at this point in the history
… provided

Contributed on behalf of STMicroelectronics

Signed-off-by: Olaf Lessenich <olessenich@eclipsesource.com>
  • Loading branch information
xai committed Mar 29, 2023
1 parent 764838a commit 253ef88
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 9 deletions.
6 changes: 1 addition & 5 deletions examples/playwright/configs/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ const config: PlaywrightTestConfig = {
use: {
baseURL: 'http://localhost:3000',
browserName: 'chromium',
screenshot: 'only-on-failure',
viewport: { width: 1920, height: 1080 },
trace: {
mode: 'retain-on-failure'
}
screenshot: 'only-on-failure'
},
preserveOutput: 'failures-only',
reporter: [
Expand Down
22 changes: 22 additions & 0 deletions examples/playwright/src/tests/theia-electron-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ test.describe('Theia Electron Application', () => {
app = await TheiaElectronAppLoader.load(new ElectronLaunchOptions('../electron', '../../plugins'), ws);
});

test.afterAll(async () => {
await app.page.close();
});

test('should load and show main content panel', async () => {
expect(await app.isMainContentPanelVisible()).toBe(true);
});
Expand All @@ -52,6 +56,24 @@ test.describe('Theia Electron Application', () => {
expect(await explorerView.isDisplayed()).toBe(false);
});

test('open file via file menu and cancel', async () => {
await (await app.menuBar.openMenu('File')).clickMenuItem('Open File...');
const fileDialog = await app.page.waitForSelector('div[class="dialogBlock"]');
expect(await fileDialog.isVisible()).toBe(true);
await app.page.getByRole('button', { name: 'Cancel' }).click();
expect(await fileDialog.isVisible()).toBe(false);
});

test('open sample.txt via file menu', async () => {
await (await app.menuBar.openMenu('File')).clickMenuItem('Open File...');
const fileDialog = await app.page.waitForSelector('div[class="dialogBlock"]');
expect(await fileDialog.isVisible()).toBe(true);
await app.page.getByText('sample.txt').click();
await app.page.getByRole('button', { name: 'Open' }).click();
const span = await app.page.waitForSelector('span:has-text("content line 2")');
expect(await span.isVisible()).toBe(true);
});

test('open quick command palette', async () => {
const quickCommand = app.quickCommandPalette;
expect(await quickCommand.isOpen()).toBe(false);
Expand Down
15 changes: 14 additions & 1 deletion examples/playwright/src/theia-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
// *****************************************************************************

import { Page, PlaywrightWorkerArgs, _electron as electron } from '@playwright/test';
import * as path from 'path';
import * as fs from 'fs';
import { TheiaApp, TheiaAppMainPageObjects } from './theia-app';
import { TheiaWorkspace } from './theia-workspace';
import { OSUtil } from './util';

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

playwrightOptions(workspace?: TheiaWorkspace): object {
const executablePath = this.electronAppPath + '/node_modules/.bin/electron';
let executablePath = path.normalize(path.join(this.electronAppPath, 'node_modules/.bin/electron'));
if (OSUtil.isWindows) {
executablePath += '.cmd';
}
if (!fs.existsSync(executablePath)) {
const errorMsg = `executablePath: ${executablePath} does not exist`;
console.log(errorMsg);
throw new Error(errorMsg);
}

const args: string[] = [];
args.push(this.electronAppPath);
args.push(...this.additionalArgs);
Expand All @@ -119,6 +131,7 @@ export class ElectronLaunchOptions {
if (workspace) {
args.push(workspace.path);
}
console.log(`Launching Electron from ${executablePath} with args: ${args.join(' ')}`);
return { executablePath, args };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,39 @@
// *****************************************************************************

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

export default new ContainerModule(bind => {
bind(ElectronFileDialogService).toSelf().inSingletonScope();
bind(FileDialogService).toService(ElectronFileDialogService);
const useNativeFileDialogs: boolean = !electronRemote.app.commandLine.hasSwitch('no-native-window-frame');
if (useNativeFileDialogs) {
bind(ElectronFileDialogService).toSelf().inSingletonScope();
bind(FileDialogService).toService(ElectronFileDialogService);
} else {
bind(DefaultFileDialogService).toSelf().inSingletonScope();
bind(FileDialogService).toService(DefaultFileDialogService);
bind(LocationListRendererFactory).toFactory(context => (options: LocationListRendererOptions) => {
const childContainer = context.container.createChild();
childContainer.bind(LocationListRendererOptions).toConstantValue(options);
childContainer.bind(LocationListRenderer).toSelf().inSingletonScope();
return childContainer.get(LocationListRenderer);
});
bind(FileDialogTreeFiltersRendererFactory).toFactory(context => (options: FileDialogTreeFiltersRendererOptions) => {
const childContainer = context.container.createChild();
childContainer.bind(FileDialogTreeFiltersRendererOptions).toConstantValue(options);
childContainer.bind(FileDialogTreeFiltersRenderer).toSelf().inSingletonScope();
return childContainer.get(FileDialogTreeFiltersRenderer);
});
bind(HiddenFilesToggleRendererFactory).toFactory(({ container }) => (fileDialogTree: FileDialogTree) => {
const child = container.createChild();
child.bind(FileDialogTree).toConstantValue(fileDialogTree);
child.bind(FileDialogHiddenFilesToggleRenderer).toSelf().inSingletonScope();
return child.get(FileDialogHiddenFilesToggleRenderer);
});
}
});

0 comments on commit 253ef88

Please sign in to comment.