1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

upgrade electron to latest version

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-07-09 17:24:13 +03:00
parent a440f60ea3
commit ce1cccc965
5 changed files with 57 additions and 43 deletions

View File

@ -34,7 +34,7 @@
"download:kubectl": "yarn run ts-node build/download_kubectl.ts", "download:kubectl": "yarn run ts-node build/download_kubectl.ts",
"download:helm": "yarn run ts-node build/download_helm.ts", "download:helm": "yarn run ts-node build/download_helm.ts",
"lint": "eslint $@ --ext js,ts,tsx --max-warnings=0 src/", "lint": "eslint $@ --ext js,ts,tsx --max-warnings=0 src/",
"rebuild": "electron-rebuild -f -w node-pty" "rebuild-pty": "electron-rebuild -f -w node-pty"
}, },
"config": { "config": {
"bundledKubectlVersion": "1.17.4", "bundledKubectlVersion": "1.17.4",
@ -261,7 +261,7 @@
"css-element-queries": "^1.2.3", "css-element-queries": "^1.2.3",
"css-loader": "^3.5.3", "css-loader": "^3.5.3",
"dompurify": "^2.0.11", "dompurify": "^2.0.11",
"electron": "^7.3.2", "electron": "^9.1.0",
"electron-builder": "^22.7.0", "electron-builder": "^22.7.0",
"electron-notarize": "^0.3.0", "electron-notarize": "^0.3.0",
"electron-rebuild": "^1.11.0", "electron-rebuild": "^1.11.0",

View File

@ -25,6 +25,12 @@ let windowManager: WindowManager;
let clusterManager: ClusterManager; let clusterManager: ClusterManager;
let proxyServer: LensProxy; let proxyServer: LensProxy;
const vmURL = formatUrl({
pathname: path.join(__dirname, `${appName}.html`),
protocol: "file",
slashes: true,
})
mangleProxyEnv() mangleProxyEnv()
if (app.commandLine.getSwitchValue("proxy-server") !== "") { if (app.commandLine.getSwitchValue("proxy-server") !== "") {
process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server") process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server")
@ -76,18 +82,13 @@ async function main() {
} }
// manage lens windows // manage lens windows
const vmURL = formatUrl({ windowManager = new WindowManager({showSplash: true});
pathname: path.join(__dirname, `${appName}.html`),
protocol: "file",
slashes: true,
})
windowManager = new WindowManager();
windowManager.loadURL(vmURL) windowManager.loadURL(vmURL)
} }
// Events // Events
app.on("ready", main)
app.on("ready", main);
app.on('window-all-closed', function () { app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar // On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q // to stay active until the user quits explicitly with Cmd + Q
@ -97,8 +98,17 @@ app.on('window-all-closed', function () {
windowManager = null windowManager = null
if (clusterManager) clusterManager.stop() if (clusterManager) clusterManager.stop()
} }
}); })
app.on("will-quit", async event => {
app.on("activate", () => {
if (!windowManager) {
windowManager = new WindowManager()
windowManager.loadURL(vmURL)
}
})
// fixme: app can't quit normally (Cmd+W/Q not working)
app.on("will-quit", async (event) => {
event.preventDefault(); // To allow mixpanel sending to be executed event.preventDefault(); // To allow mixpanel sending to be executed
if (clusterManager) clusterManager.stop() if (clusterManager) clusterManager.stop()
if (proxyServer) proxyServer.close() if (proxyServer) proxyServer.close()

View File

@ -1,6 +1,6 @@
import { PromiseIpc } from "electron-promise-ipc"; import { PromiseIpc } from "electron-promise-ipc";
import { app, BrowserWindow, dialog, Menu, MenuItem, MenuItemConstructorOptions, shell, webContents } from "electron" import { app, BrowserWindow, dialog, Menu, MenuItem, MenuItemConstructorOptions, shell, webContents } from "electron"
import { isMac, issuesTrackerUrl, isWindows, slackUrl } from "../common/vars"; import { appName, isMac, issuesTrackerUrl, isWindows, slackUrl } from "../common/vars";
// todo: refactor + split menu sections to separated files, e.g. menus/file.menu.ts // todo: refactor + split menu sections to separated files, e.g. menus/file.menu.ts
@ -18,21 +18,19 @@ function setClusterSettingsEnabled(enabled: boolean) {
Menu.getApplicationMenu().items[menuIndex].submenu.items[1].enabled = enabled Menu.getApplicationMenu().items[menuIndex].submenu.items[1].enabled = enabled
} }
function showAbout(_menuitem: MenuItem, browserWindow: BrowserWindow) { export function showAbout(_menuitem: MenuItem, browserWindow: BrowserWindow) {
const appDetails = [ const appInfo = [
`Version: ${app.getVersion()}`, `${appName}: ${app.getVersion()}`,
`Electron: ${process.versions.electron}`,
`Chrome: ${process.versions.chrome}`,
`Copyright 2020 Lakend Labs, Inc.`,
] ]
appDetails.push(`Copyright 2020 Lakend Labs, Inc.`)
let title = "Lens"
if (isWindows) {
title = ` ${title}`
}
dialog.showMessageBoxSync(browserWindow, { dialog.showMessageBoxSync(browserWindow, {
title, title: `${isWindows ? " ".repeat(2) : ""}${appName}`,
type: "info", type: "info",
buttons: ["Close"], buttons: ["Close"],
message: `Lens`, message: `Lens`,
detail: appDetails.join("\r\n") detail: appInfo.join("\r\n")
}) })
} }
@ -84,8 +82,7 @@ export default function initMenu(opts: Partial<MenuOptions> = {}) {
} }
] ]
} }
} } else {
else {
fileMenu = { fileMenu = {
label: 'File', label: 'File',
submenu: [ submenu: [

View File

@ -17,7 +17,7 @@ export class WindowManager {
protected disposers: Function[] = []; protected disposers: Function[] = [];
constructor(protected params: WindowManagerParams = {}) { constructor(protected params: WindowManagerParams = {}) {
this.params = { showSplash: true, ...params }; this.params = { showSplash: false, ...params };
// Manage main window size and position with state persistence // Manage main window size and position with state persistence
this.windowState = windowStateKeeper({ this.windowState = windowStateKeeper({
@ -83,9 +83,28 @@ export class WindowManager {
); );
} }
setView(clusterId: ClusterId) { async loadURL(url: string) {
if (this.params.showSplash) {
this.splashWindow.show();
}
await this.mainWindow.loadURL(url);
this.mainWindow.show();
this.splashWindow.hide();
this.setView("cluster-id-blabla");
}
async setView(clusterId: ClusterId) {
const view = this.getView(clusterId) const view = this.getView(clusterId)
this.mainWindow.setBrowserView(view); this.mainWindow.addBrowserView(view);
// await view.webContents.loadURL("http://ya.ru");
// view.setBounds({
// x: 10,
// y: 10,
// width: this.windowState.width - 20,
// height: this.windowState.height - 20,
// })
// view.setAutoResize({ horizontal: true, vertical: true });
} }
getView(clusterId: ClusterId): BrowserView { getView(clusterId: ClusterId): BrowserView {
@ -96,23 +115,11 @@ export class WindowManager {
nodeIntegration: true nodeIntegration: true
} }
}) })
// view.setBackgroundColor("#878686");
// view.setAutoResize({ horizontal: true, vertical: true });
// view.webContents.loadURL("data:text/html;charset=utf-8,<b>TEST</b>")
this.views.set(clusterId, view); this.views.set(clusterId, view);
} }
return view; return view;
} }
async loadURL(url: string) {
if (this.params.showSplash) {
this.splashWindow.show();
}
await this.mainWindow.loadURL(url);
this.mainWindow.show();
this.splashWindow.hide();
}
destroy() { destroy() {
this.disposers.forEach(dispose => dispose()); this.disposers.forEach(dispose => dispose());
this.disposers.length = 0; this.disposers.length = 0;

View File

@ -4649,10 +4649,10 @@ electron@*:
"@types/node" "^12.0.12" "@types/node" "^12.0.12"
extract-zip "^1.0.3" extract-zip "^1.0.3"
electron@^7.3.2: electron@^9.1.0:
version "7.3.2" version "9.1.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-7.3.2.tgz#184b69fe9089693e179b3b34effa975dfc8e505d" resolved "https://registry.yarnpkg.com/electron/-/electron-9.1.0.tgz#ca77600c9e4cd591298c340e013384114d3d8d05"
integrity sha512-5uSWVfCJogiPiU0G+RKi4ECnNs0gPNjAwYVE9KR7RXaOJYcpNIC5RFejaaUnuRoBssJ5B1n/5WU6wDUxvPajWQ== integrity sha512-VRAF8KX1m0py9I9sf0kw1kWfeC87mlscfFcbcRdLBsNJ44/GrJhi3+E8rKbpHUeZNQxsPaVA5Zu5Lxb6dV/scQ==
dependencies: dependencies:
"@electron/get" "^1.0.1" "@electron/get" "^1.0.1"
"@types/node" "^12.0.12" "@types/node" "^12.0.12"