Skip to content

Commit

Permalink
Updated to electron 9.x.
Browse files Browse the repository at this point in the history
Pinned the `node-abi` version as the `electron-rebuild` used
a way too old version.

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Jun 5, 2020
1 parent 06c6dd6 commit 0432864
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ app.on('ready', () => {
// Remove the default electron menus, waiting for the application to set its own.
Menu.setApplicationMenu(Menu.buildFromTemplate([{
role: 'help', submenu: [{ role: 'toggledevtools'}]
role: 'help', submenu: [{ role: 'toggleDevTools' }]
}]));
function createNewWindow(theUrl) {
Expand Down Expand Up @@ -206,7 +206,10 @@ app.on('ready', () => {
x: windowState.x,
y: windowState.y,
isMaximized: windowState.isMaximized,
...windowOptionsAdditions
...windowOptionsAdditions,
webPreferences: {
nodeIntegration: true
}
};
// Always hide the window, we will show the window when it is ready to be shown in any case.
Expand Down Expand Up @@ -263,16 +266,15 @@ app.on('ready', () => {
newWindow.on('move', saveWindowStateDelayed);
// Fired when a beforeunload handler tries to prevent the page unloading
newWindow.webContents.on('will-prevent-unload', event => {
const preventStop = 0 !== dialog.showMessageBox(newWindow, {
newWindow.webContents.on('will-prevent-unload', async event => {
const { response } = await dialog.showMessageBox(newWindow, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Are you sure you want to quit?',
detail: 'Any unsaved changes will not be saved.'
});
if (!preventStop) {
if (response === 0) { // 'Yes'
// This ignores the beforeunload callback, allowing the page to unload
event.preventDefault();
}
Expand Down Expand Up @@ -330,22 +332,14 @@ app.on('ready', () => {
})
}
const setElectronSecurityToken = port => {
return new Promise((resolve, reject) => {
electron.session.defaultSession.cookies.set({
url: \`http://localhost:\${port}/\`,
name: ElectronSecurityToken,
value: JSON.stringify(electronSecurityToken),
httpOnly: true,
}, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
})
}
const setElectronSecurityToken = async port => {
await electron.session.defaultSession.cookies.set({
url: \`http://localhost:\${port}/\`,
name: ElectronSecurityToken,
value: JSON.stringify(electronSecurityToken),
httpOnly: true
});
};
const loadMainWindow = port => {
if (!mainWindow.isDestroyed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class WebpackGenerator extends AbstractGenerator {

protected compileWebpackConfig(): string {
return `/**
* Don't touch this file. It will be renerated by theia build.
* Don't touch this file. It will be regenerated by theia build.
* To customize webpack configuration change ${this.configPath}
*/
// @ts-check
Expand Down
6 changes: 3 additions & 3 deletions dev-packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"electron-replace-ffmpeg": "electron-replace-ffmpeg.js"
},
"dependencies": {
"electron": "^4.2.11",
"electron": "^9.0.2",
"electron-download": "^4.1.1",
"electron-store": "^2.0.0",
"fix-path": "^2.1.0",
"electron-store": "^5.1.1",
"fix-path": "^3.0.0",
"native-keymap": "^2.1.2",
"node-gyp": "^3.6.0",
"unzipper": "^0.9.11",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"resolutions": {
"**/@types/node": "~10.3.6",
"**/vscode-json-languageserver/**/vscode-languageserver": "6.0.0-next.1"
"**/vscode-json-languageserver/**/vscode-languageserver": "6.0.0-next.1",
"**/node-abi": "^2.18.0"
},
"devDependencies": {
"@types/chai-string": "^1.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export class ElectronKeyboardLayoutChangeNotifier implements KeyboardLayoutChang

@postConstruct()
protected initialize(): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ipcRenderer.on('keyboardLayoutChanged', (event: Event<any>, newLayout: NativeKeyboardLayout) => this.nativeLayoutChanged.fire(newLayout));
ipcRenderer.on('keyboardLayoutChanged', (event: Electron.IpcRendererEvent, newLayout: NativeKeyboardLayout) => this.nativeLayoutChanged.fire(newLayout));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class ElectronMainMenuFactory {
role: 'hide'
},
{
role: 'hideothers'
role: 'hideOthers'
},
{
role: 'unhide'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,13 @@ export class ElectronMenuContribution implements FrontendApplicationContribution
registry.registerCommand(ElectronCommands.ZOOM_IN, {
execute: () => {
const webContents = currentWindow.webContents;
webContents.getZoomLevel(zoomLevel =>
webContents.setZoomLevel(zoomLevel + 0.5)
);
webContents.setZoomLevel(webContents.zoomLevel + 0.5);
}
});
registry.registerCommand(ElectronCommands.ZOOM_OUT, {
execute: () => {
const webContents = currentWindow.webContents;
webContents.getZoomLevel(zoomLevel =>
webContents.setZoomLevel(zoomLevel - 0.5)
);
webContents.setZoomLevel(webContents.zoomLevel - 0.5);
}
});
registry.registerCommand(ElectronCommands.RESET_ZOOM, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { FileStat } from '../../common';
import { FileAccess } from '../../common/filesystem';
import { DefaultFileDialogService, OpenFileDialogProps, SaveFileDialogProps } from '../../browser/file-dialog';

// See https://github.com/electron/electron/blob/v4.2.12/docs/api/dialog.md
// See https://github.com/electron/electron/blob/v9.0.2/docs/api/dialog.md
// These properties get extended with newer versions of Electron
type DialogProperties = 'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' |
'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory';
'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory' | 'dontAddToRecent';

//
// We are OK to use this here because the electron backend and frontend are on the same host.
Expand All @@ -47,44 +47,35 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
async showOpenDialog(props: OpenFileDialogProps, folder?: FileStat): Promise<MaybeArray<URI> | undefined> {
const rootNode = await this.getRootNode(folder);
if (rootNode) {
return new Promise<MaybeArray<URI> | undefined>(resolve => {
remote.dialog.showOpenDialog(this.toOpenDialogOptions(rootNode.uri, props), async (filePaths: string[] | undefined) => {
if (!filePaths || filePaths.length === 0) {
resolve(undefined);
return;
}

const uris = filePaths.map(path => FileUri.create(path));
const canAccess = await this.canReadWrite(uris);
const result = canAccess ? uris.length === 1 ? uris[0] : uris : undefined;
resolve(result);
});
});
const { filePaths } = await remote.dialog.showOpenDialog(this.toOpenDialogOptions(rootNode.uri, props));
if (filePaths.length === 0) {
return undefined;
}

const uris = filePaths.map(path => FileUri.create(path));
const canAccess = await this.canReadWrite(uris);
const result = canAccess ? uris.length === 1 ? uris[0] : uris : undefined;
return result;
}
return undefined;
}

async showSaveDialog(props: SaveFileDialogProps, folder?: FileStat): Promise<URI | undefined> {
const rootNode = await this.getRootNode(folder);
if (rootNode) {
return new Promise<URI | undefined>(resolve => {
remote.dialog.showSaveDialog(this.toSaveDialogOptions(rootNode.uri, props), async (filename: string | undefined) => {
if (!filename) {
resolve(undefined);
return;
}

const uri = FileUri.create(filename);
const exists = await this.fileSystem.exists(uri.toString());
if (!exists) {
resolve(uri);
return;
}

const canAccess = await this.canReadWrite(uri);
resolve(canAccess ? uri : undefined);
});
});
const { filePath } = await remote.dialog.showSaveDialog(this.toSaveDialogOptions(rootNode.uri, props));
if (!filePath) {
return undefined;
}

const uri = FileUri.create(filePath);
const exists = await this.fileSystem.exists(uri.toString());
if (!exists) {
return uri;
}

const canAccess = await this.canReadWrite(uri);
return canAccess ? uri : undefined;
}
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,12 @@ export class ElectronWebviewWidgetFactory extends WebviewWidgetFactory {
*
* @param endpoint cookie's target url
*/
protected attachElectronSecurityCookie(endpoint: string): Promise<void> {
return new Promise((resolve, reject) => {
remote.session.defaultSession!.cookies.set({
url: endpoint,
name: ElectronSecurityToken,
value: JSON.stringify(this.container.get(ElectronSecurityToken)),
httpOnly: true,
}, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
protected async attachElectronSecurityCookie(endpoint: string): Promise<void> {
await remote.session.defaultSession!.cookies.set({
url: endpoint,
name: ElectronSecurityToken,
value: JSON.stringify(this.container.get(ElectronSecurityToken)),
httpOnly: true
});
}

Expand Down
Loading

0 comments on commit 0432864

Please sign in to comment.