зеркало из
1
0
Форкнуть 0

Fix window state persistence and port number regression (#434)

This commit is contained in:
Paul Montgomery 2021-04-16 13:28:54 -07:00 коммит произвёл GitHub
Родитель 31d0381461
Коммит 762ed3b9fa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 34 добавлений и 6 удалений

10
package-lock.json сгенерированный
Просмотреть файл

@ -6442,6 +6442,16 @@
"integrity": "sha512-NK9DBBYEBb5f9D7zXI0hiE941gq3wkBeQmXs1ingigA/jnTg5mhwY2Z5egwA+ZI8OLGKCx0h1Cl8/xeuIBuLlg==",
"dev": true
},
"electron-window-state": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-5.0.3.tgz",
"integrity": "sha512-1mNTwCfkolXl3kMf50yW3vE2lZj0y92P/HYWFBrb+v2S/pCka5mdwN3cagKm458A7NjndSwijynXgcLWRodsVg==",
"dev": true,
"requires": {
"jsonfile": "^4.0.0",
"mkdirp": "^0.5.1"
}
},
"elliptic": {
"version": "6.5.4",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",

Просмотреть файл

@ -77,6 +77,7 @@
"brace": "0.11.1",
"cors": "2.8.5",
"date-fns": "2.14.0",
"electron-window-state": "5.0.3",
"express": "4.16.4",
"i18next": "11.10.1",
"immutable": "4.0.0-rc.12",

Просмотреть файл

@ -3,6 +3,7 @@
* Licensed under the MIT License
**********************************************************/
import { app, Menu, BrowserWindow, dialog, ipcMain } from 'electron';
import * as windowState from 'electron-window-state';
import * as path from 'path';
import { generateMenu } from './factories/menuFactory';
import { PLATFORMS, MESSAGE_CHANNELS } from './constants';
@ -89,10 +90,14 @@ class Main {
}
private static createMainWindow(): void {
const mainWindowState = windowState({
defaultHeight: 1200,
defaultWidth: 900
});
Main.mainWindow = new BrowserWindow({
height: 1200,
width: 900,
webPreferences: {
height: mainWindowState.height,
width: mainWindowState.width,
webPreferences: { // tslint:disable-line:object-literal-sort-keys
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
nodeIntegration: false,
@ -100,7 +105,19 @@ class Main {
},
});
mainWindowState.manage(Main.mainWindow);
Main.mainWindow.loadFile(Main.target);
try {
const customPort = parseInt(process.env.AZURE_IOT_EXPLORER_PORT); // tslint:disable-line:radix
if (customPort) {
Main.mainWindow.webContents.executeJavaScript(`localStorage.setItem("CUSTOM_CONTROLLER_PORT", ${customPort});`);
} else {
Main.mainWindow.webContents.executeJavaScript(`localStorage.setItem("CUSTOM_CONTROLLER_PORT", ${customPort});`);
}
} catch {
// nothing
}
Main.mainWindow.on('closed', Main.onWindowClosed);
Main.setErrorBoundary();
@ -112,10 +129,10 @@ class Main {
private static registerHandler(channel: string, handler: (...args: any[]) => any) {
ipcMain.handle(channel, async (...args) => {
try {
return {result: await Promise.resolve(handler(...args))};
return { result: await Promise.resolve(handler(...args)) };
} catch (e) {
const error = formatError(e);
return {error};
const error = formatError(e);
return { error };
}
});
}