diff --git a/package.json b/package.json index 77b05e63f2..2ea9e4ed06 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "download:kubectl": "yarn run ts-node build/download_kubectl.ts", "download:helm": "yarn run ts-node build/download_helm.ts", "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": { "bundledKubectlVersion": "1.17.4", @@ -261,7 +261,7 @@ "css-element-queries": "^1.2.3", "css-loader": "^3.5.3", "dompurify": "^2.0.11", - "electron": "^7.3.2", + "electron": "^9.1.0", "electron-builder": "^22.7.0", "electron-notarize": "^0.3.0", "electron-rebuild": "^1.11.0", diff --git a/src/main/index.ts b/src/main/index.ts index 84b50f78ad..f96caf2709 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -25,6 +25,12 @@ let windowManager: WindowManager; let clusterManager: ClusterManager; let proxyServer: LensProxy; +const vmURL = formatUrl({ + pathname: path.join(__dirname, `${appName}.html`), + protocol: "file", + slashes: true, +}) + mangleProxyEnv() if (app.commandLine.getSwitchValue("proxy-server") !== "") { process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server") @@ -76,18 +82,13 @@ async function main() { } // manage lens windows - const vmURL = formatUrl({ - pathname: path.join(__dirname, `${appName}.html`), - protocol: "file", - slashes: true, - }) - windowManager = new WindowManager(); + windowManager = new WindowManager({showSplash: true}); windowManager.loadURL(vmURL) } // Events +app.on("ready", main) -app.on("ready", main); app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q @@ -97,8 +98,17 @@ app.on('window-all-closed', function () { windowManager = null 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 if (clusterManager) clusterManager.stop() if (proxyServer) proxyServer.close() diff --git a/src/main/menu.ts b/src/main/menu.ts index ebbcfa42bf..7db041112b 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -1,6 +1,6 @@ import { PromiseIpc } from "electron-promise-ipc"; 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 @@ -18,21 +18,19 @@ function setClusterSettingsEnabled(enabled: boolean) { Menu.getApplicationMenu().items[menuIndex].submenu.items[1].enabled = enabled } -function showAbout(_menuitem: MenuItem, browserWindow: BrowserWindow) { - const appDetails = [ - `Version: ${app.getVersion()}`, +export function showAbout(_menuitem: MenuItem, browserWindow: BrowserWindow) { + const appInfo = [ + `${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, { - title, + title: `${isWindows ? " ".repeat(2) : ""}${appName}`, type: "info", buttons: ["Close"], message: `Lens`, - detail: appDetails.join("\r\n") + detail: appInfo.join("\r\n") }) } @@ -84,8 +82,7 @@ export default function initMenu(opts: Partial = {}) { } ] } - } - else { + } else { fileMenu = { label: 'File', submenu: [ diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index e6f4ab3c3c..ab16669d50 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -17,7 +17,7 @@ export class WindowManager { protected disposers: Function[] = []; constructor(protected params: WindowManagerParams = {}) { - this.params = { showSplash: true, ...params }; + this.params = { showSplash: false, ...params }; // Manage main window size and position with state persistence 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) - 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 { @@ -96,23 +115,11 @@ export class WindowManager { nodeIntegration: true } }) - // view.setBackgroundColor("#878686"); - // view.setAutoResize({ horizontal: true, vertical: true }); - // view.webContents.loadURL("data:text/html;charset=utf-8,TEST") this.views.set(clusterId, 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() { this.disposers.forEach(dispose => dispose()); this.disposers.length = 0; diff --git a/yarn.lock b/yarn.lock index 61196f3bc0..b5448bc5d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4649,10 +4649,10 @@ electron@*: "@types/node" "^12.0.12" extract-zip "^1.0.3" -electron@^7.3.2: - version "7.3.2" - resolved "https://registry.yarnpkg.com/electron/-/electron-7.3.2.tgz#184b69fe9089693e179b3b34effa975dfc8e505d" - integrity sha512-5uSWVfCJogiPiU0G+RKi4ECnNs0gPNjAwYVE9KR7RXaOJYcpNIC5RFejaaUnuRoBssJ5B1n/5WU6wDUxvPajWQ== +electron@^9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/electron/-/electron-9.1.0.tgz#ca77600c9e4cd591298c340e013384114d3d8d05" + integrity sha512-VRAF8KX1m0py9I9sf0kw1kWfeC87mlscfFcbcRdLBsNJ44/GrJhi3+E8rKbpHUeZNQxsPaVA5Zu5Lxb6dV/scQ== dependencies: "@electron/get" "^1.0.1" "@types/node" "^12.0.12"