diff --git a/package.json b/package.json index 8350c0aa2b..d1fd2e4331 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,16 @@ "productName": "Lens", "description": "Lens - The Kubernetes IDE", "version": "3.5.0-beta.1", - "main": "src/main", + "main": "dist/main.js", "scripts": { - "dev": "DEBUG=true concurrently yarn:dev:*", - "dev:main": "webpack-cli --watch --cache --config webpack.main.ts", - "dev:render": "webpack-cli --watch --cache --config webpack.renderer.ts", - "compile": "concurrently 'yarn download-bins' 'yarn i18n:compile' 'yarn make-dll' && concurrently yarn:compile:*", + "dev": "yarn compile:dll && concurrently yarn:dev:* && yarn dev-run", + "dev-run": "electron .", + "dev:main": "DEBUG=true webpack --watch --config webpack.main.ts", + "dev:renderer": "DEBUG=true webpack --watch --config webpack.renderer.ts", + "compile": "concurrently 'yarn download-bins' 'yarn i18n:compile' 'yarn compile:dll' && concurrently yarn:compile:*", "compile:main": "webpack -p --progress --config webpack.main.ts", "compile:renderer": "webpack -p --progress --config webpack.renderer.ts", - "make-dll": "webpack --config webpack.dll.ts", + "compile:dll": "webpack --config webpack.dll.ts", "build:linux": "yarn compile && electron-builder --linux --dir -c.productName=LensDev", "build:mac": "yarn compile && electron-builder --mac --dir -c.productName=LensDev", "build:win": "yarn compile && electron-builder --win --dir -c.productName=LensDev", @@ -20,7 +21,7 @@ "dist": "yarn compile && electron-builder -p onTag", "dist:win": "yarn compile && electron-builder -p onTag --x64 --ia32", "dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null", - "postinstall": "patch-package && concurrently 'electron-builder install-app-deps' 'yarn make-dll'", + "postinstall": "patch-package && concurrently 'electron-builder install-app-deps' 'yarn compile:dll'", "i18n:extract": "lingui extract", "i18n:compile": "lingui compile", "download-bins": "concurrently yarn:download:*", @@ -183,7 +184,6 @@ "request-promise-native": "^1.0.8", "semver": "^7.3.2", "shell-env": "^3.0.0", - "ssl-root-cas": "^1.3.1", "tar": "^6.0.2", "tcp-port-used": "^1.0.1", "tempy": "^0.5.0", diff --git a/src/common/system-ca.ts b/src/common/system-ca.ts index a2b972c964..ec8cd2f7ec 100644 --- a/src/common/system-ca.ts +++ b/src/common/system-ca.ts @@ -1,7 +1,8 @@ -import "mac-ca" -import winca from "win-ca/api" -import { isWindows } from "./vars"; +import { isMac, isWindows } from "./vars"; -if (isWindows) { - winca.inject("+") // see: https://github.com/ukoloff/win-ca#caveats +if (isMac) { + // require("mac-ca"); // fixme: crashes +} +if (isWindows) { + require("win-ca").inject("+") // see: https://github.com/ukoloff/win-ca#caveats } diff --git a/src/main/index.ts b/src/main/index.ts index 1646be9d61..25e7b2fc2c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,134 +1,22 @@ // Main process import "../common/system-ca" -import "../common/prometheus-providers" -import { app, dialog, protocol } from "electron" -import { PromiseIpc } from "electron-promise-ipc" -import path from "path" -import { format as formatUrl } from "url" -import logger from "./logger" -import initMenu from "./menu" -import * as proxy from "./proxy" -import { WindowManager } from "./window-manager"; -import { clusterStore } from "../common/cluster-store" -import { tracker } from "./tracker" -import { ClusterManager } from "./cluster-manager"; -import AppUpdater from "./app-updater" -import { shellSync } from "./shell-sync" -import { getFreePort } from "./port" -import { mangleProxyEnv } from "./proxy-env" -import { findMainWebContents } from "./webcontents" -import { registerStaticProtocol } from "../common/register-static"; -import { isDevelopment, isMac } from "../common/vars"; +import { app, BrowserWindow } from "electron" -mangleProxyEnv() -if (app.commandLine.getSwitchValue("proxy-server") !== "") { - process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server") -} -const promiseIpc = new PromiseIpc({ timeout: 2000 }) +console.log('MAIN', process.resourcesPath) -let windowManager: WindowManager = null; -let clusterManager: ClusterManager = null; -const vmURL = isDevelopment ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` : formatUrl({ - pathname: path.join(__dirname, "index.html"), - protocol: "file", - slashes: true, -}) +app.whenReady().then(function start() { + console.log('APP READY') -async function main() { - await shellSync() + var window = new BrowserWindow({ + width: 600, + height: 500, + webPreferences: { + devTools: true, + nodeIntegration: true, + } + }); - const updater = new AppUpdater() - updater.start(); - - tracker.event("app", "start"); - - registerStaticProtocol(); - protocol.registerFileProtocol('store', (request, callback) => { - const url = request.url.substr(8) - callback(path.normalize(`${app.getPath("userData")}/${url}`)) - }, (error) => { - if (error) console.error('Failed to register protocol') - }) - - let port: number = null - // find free port - try { - port = await getFreePort() - } catch (error) { - logger.error(error) - await dialog.showErrorBox("Lens Error", "Could not find a free port for the cluster proxy") - app.quit(); - } - - // create cluster manager - clusterManager = new ClusterManager(clusterStore.getAllClusterObjects(), port) - - // run proxy - try { - proxy.listen(port, clusterManager) - } catch (error) { - logger.error(`Could not start proxy (127.0.0:${port}): ${error.message}`) - await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${port}): ${error.message || "unknown error"}`) - app.quit(); - } - - // boot windowmanager - windowManager = new WindowManager(); - windowManager.showMain(vmURL) - - initMenu({ - logoutHook: async () => { - // IPC send needs webContents as we're sending it to renderer - promiseIpc.send('logout', findMainWebContents(), {}).then((data: any) => { - logger.debug("logout IPC sent"); - }) - }, - showPreferencesHook: async () => { - // IPC send needs webContents as we're sending it to renderer - promiseIpc.send('navigate', findMainWebContents(), { name: 'preferences-page' }).then((data: any) => { - logger.debug("navigate: preferences IPC sent"); - }) - }, - addClusterHook: async () => { - promiseIpc.send('navigate', findMainWebContents(), { name: "add-cluster-page" }).then((data: any) => { - logger.debug("navigate: add-cluster-page IPC sent"); - }) - }, - showWhatsNewHook: async () => { - promiseIpc.send('navigate', findMainWebContents(), { name: "whats-new-page" }).then((data: any) => { - logger.debug("navigate: whats-new-page IPC sent"); - }) - }, - clusterSettingsHook: async () => { - promiseIpc.send('navigate', findMainWebContents(), { name: "cluster-settings-page" }).then((data: any) => { - logger.debug("navigate: cluster-settings-page IPC sent"); - }) - }, - }, promiseIpc) -} - -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 - if (!isMac) { - app.quit(); - } - else { - windowManager = null - if (clusterManager) clusterManager.stop() - } -}) -app.on("activate", () => { - if (!windowManager) { - logger.debug("activate main window") - windowManager = new WindowManager(false) - windowManager.showMain(vmURL) - } -}) -app.on("will-quit", async (event) => { - event.preventDefault(); // To allow mixpanel sending to be executed - if (clusterManager) clusterManager.stop() - app.exit(0); -}) + window.loadFile("index.html"); + window.show(); +}); diff --git a/src/main/index_backup.ts b/src/main/index_backup.ts new file mode 100644 index 0000000000..1646be9d61 --- /dev/null +++ b/src/main/index_backup.ts @@ -0,0 +1,134 @@ +// Main process + +import "../common/system-ca" +import "../common/prometheus-providers" +import { app, dialog, protocol } from "electron" +import { PromiseIpc } from "electron-promise-ipc" +import path from "path" +import { format as formatUrl } from "url" +import logger from "./logger" +import initMenu from "./menu" +import * as proxy from "./proxy" +import { WindowManager } from "./window-manager"; +import { clusterStore } from "../common/cluster-store" +import { tracker } from "./tracker" +import { ClusterManager } from "./cluster-manager"; +import AppUpdater from "./app-updater" +import { shellSync } from "./shell-sync" +import { getFreePort } from "./port" +import { mangleProxyEnv } from "./proxy-env" +import { findMainWebContents } from "./webcontents" +import { registerStaticProtocol } from "../common/register-static"; +import { isDevelopment, isMac } from "../common/vars"; + +mangleProxyEnv() +if (app.commandLine.getSwitchValue("proxy-server") !== "") { + process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server") +} +const promiseIpc = new PromiseIpc({ timeout: 2000 }) + +let windowManager: WindowManager = null; +let clusterManager: ClusterManager = null; +const vmURL = isDevelopment ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` : formatUrl({ + pathname: path.join(__dirname, "index.html"), + protocol: "file", + slashes: true, +}) + +async function main() { + await shellSync() + + const updater = new AppUpdater() + updater.start(); + + tracker.event("app", "start"); + + registerStaticProtocol(); + protocol.registerFileProtocol('store', (request, callback) => { + const url = request.url.substr(8) + callback(path.normalize(`${app.getPath("userData")}/${url}`)) + }, (error) => { + if (error) console.error('Failed to register protocol') + }) + + let port: number = null + // find free port + try { + port = await getFreePort() + } catch (error) { + logger.error(error) + await dialog.showErrorBox("Lens Error", "Could not find a free port for the cluster proxy") + app.quit(); + } + + // create cluster manager + clusterManager = new ClusterManager(clusterStore.getAllClusterObjects(), port) + + // run proxy + try { + proxy.listen(port, clusterManager) + } catch (error) { + logger.error(`Could not start proxy (127.0.0:${port}): ${error.message}`) + await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${port}): ${error.message || "unknown error"}`) + app.quit(); + } + + // boot windowmanager + windowManager = new WindowManager(); + windowManager.showMain(vmURL) + + initMenu({ + logoutHook: async () => { + // IPC send needs webContents as we're sending it to renderer + promiseIpc.send('logout', findMainWebContents(), {}).then((data: any) => { + logger.debug("logout IPC sent"); + }) + }, + showPreferencesHook: async () => { + // IPC send needs webContents as we're sending it to renderer + promiseIpc.send('navigate', findMainWebContents(), { name: 'preferences-page' }).then((data: any) => { + logger.debug("navigate: preferences IPC sent"); + }) + }, + addClusterHook: async () => { + promiseIpc.send('navigate', findMainWebContents(), { name: "add-cluster-page" }).then((data: any) => { + logger.debug("navigate: add-cluster-page IPC sent"); + }) + }, + showWhatsNewHook: async () => { + promiseIpc.send('navigate', findMainWebContents(), { name: "whats-new-page" }).then((data: any) => { + logger.debug("navigate: whats-new-page IPC sent"); + }) + }, + clusterSettingsHook: async () => { + promiseIpc.send('navigate', findMainWebContents(), { name: "cluster-settings-page" }).then((data: any) => { + logger.debug("navigate: cluster-settings-page IPC sent"); + }) + }, + }, promiseIpc) +} + +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 + if (!isMac) { + app.quit(); + } + else { + windowManager = null + if (clusterManager) clusterManager.stop() + } +}) +app.on("activate", () => { + if (!windowManager) { + logger.debug("activate main window") + windowManager = new WindowManager(false) + windowManager.showMain(vmURL) + } +}) +app.on("will-quit", async (event) => { + event.preventDefault(); // To allow mixpanel sending to be executed + if (clusterManager) clusterManager.stop() + app.exit(0); +}) diff --git a/src/renderer/index.html b/src/renderer/index.html new file mode 100755 index 0000000000..34e72ece0d --- /dev/null +++ b/src/renderer/index.html @@ -0,0 +1,20 @@ + + +
+ +