From ec7b8661d9c37ebccb0935c4cf432fbf9634f3b7 Mon Sep 17 00:00:00 2001 From: Roman Date: Sat, 13 Jun 2020 06:53:47 +0300 Subject: [PATCH] more configuration tweaks --- package.json | 16 ++--- src/common/system-ca.ts | 11 +-- src/main/index.ts | 142 ++++--------------------------------- src/main/index_backup.ts | 134 ++++++++++++++++++++++++++++++++++ src/renderer/index.html | 20 ++++++ src/renderer/template.html | 14 ---- tsconfig.json | 2 +- types/mocks.d.ts | 4 +- webpack.dll.ts | 12 ++-- webpack.main.ts | 3 +- webpack.renderer.ts | 11 ++- yarn.lock | 12 ---- 12 files changed, 198 insertions(+), 183 deletions(-) create mode 100644 src/main/index_backup.ts create mode 100755 src/renderer/index.html delete mode 100755 src/renderer/template.html 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 @@ + + + + + Lens - The Kubernetes IDE + + + + +We are using node , +Chrome , +and Electron . + +
+
+ + + + + \ No newline at end of file diff --git a/src/renderer/template.html b/src/renderer/template.html deleted file mode 100755 index fd88c568f0..0000000000 --- a/src/renderer/template.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Lens - The Kubernetes IDE - - - - -
-
- - - \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 3eeb75d7f8..4fe65239b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "module": "CommonJS", "lib": ["ESNext", "DOM", "DOM.Iterable"], "moduleResolution": "Node", - "sourceMap": false, + "sourceMap": true, "strict": false, "noImplicitAny": true, "noUnusedLocals": false, diff --git a/types/mocks.d.ts b/types/mocks.d.ts index 8169f88915..cd376447d5 100644 --- a/types/mocks.d.ts +++ b/types/mocks.d.ts @@ -1,5 +1,3 @@ declare module "electron-promise-ipc" -declare module "fix-path" declare module "mac-ca" -declare module "win-ca/*" -declare module "ssl-root-cas" +declare module "win-ca" diff --git a/webpack.dll.ts b/webpack.dll.ts index 925ce8a627..ac434169dc 100755 --- a/webpack.dll.ts +++ b/webpack.dll.ts @@ -2,8 +2,8 @@ import path from "path"; import webpack from "webpack"; import { isDevelopment, outDir } from "./src/common/vars"; -export const libName = "dll" -export const manifestPath = path.resolve(outDir, `${libName}.manifest.json`); +export const fileName = "dll" +export const manifestPath = path.resolve(outDir, `${fileName}.manifest.json`); export const externalPackages = [ "react", "react-dom", @@ -16,15 +16,15 @@ export default function (): webpack.Configuration { mode: isDevelopment ? "development" : "production", cache: isDevelopment, entry: { - [libName]: externalPackages + [fileName]: externalPackages }, output: { - library: libName, - libraryTarget: "commonjs" + library: fileName, + libraryTarget: "commonjs2" }, plugins: [ new webpack.DllPlugin({ - name: libName, + name: fileName, path: manifestPath, }) ], diff --git a/webpack.main.ts b/webpack.main.ts index c62e1b6c21..a9b92093c9 100755 --- a/webpack.main.ts +++ b/webpack.main.ts @@ -1,11 +1,12 @@ import path from "path"; import webpack from "webpack"; -import { isProduction, mainDir, outDir } from "./src/common/vars"; +import { isDevelopment, isProduction, mainDir, outDir } from "./src/common/vars"; export default function (): webpack.Configuration { return { target: "electron-main", mode: isProduction ? "production" : "development", + cache: isDevelopment, entry: { main: path.resolve(mainDir, "index.ts"), }, diff --git a/webpack.renderer.ts b/webpack.renderer.ts index 00bed6b47a..208b061b9a 100755 --- a/webpack.renderer.ts +++ b/webpack.renderer.ts @@ -4,26 +4,25 @@ import HtmlWebpackPlugin from "html-webpack-plugin"; import MiniCssExtractPlugin from "mini-css-extract-plugin"; import TerserWebpackPlugin from "terser-webpack-plugin"; import { isDevelopment, isProduction, outDir, rendererDir } from "./src/common/vars"; -import { manifestPath, externalPackages } from "./webpack.dll"; +import { externalPackages, manifestPath } from "./webpack.dll"; export default function (): webpack.Configuration { - const tsConfigFile = path.resolve("./tsconfig.json"); - const htmlTemplate = path.resolve(rendererDir, "template.html"); + const htmlTemplate = path.resolve(rendererDir, "index.html"); const sassCommonVars = path.resolve(rendererDir, "components/vars.scss"); + const tsConfigFile = path.resolve("tsconfig.json"); return { target: "electron-renderer", mode: isProduction ? "production" : "development", - devtool: isProduction ? "source-map" : "cheap-eval-source-map", - cache: isDevelopment, + devtool: isProduction ? "source-map" : "cheap-module-eval-source-map", externals: externalPackages, + cache: isDevelopment, entry: { renderer: path.resolve(rendererDir, "index.tsx"), // renderer_vue: path.resolve(rendererDir, "_vue/index.js"), }, output: { path: outDir, - publicPath: '/', filename: '[name].js', chunkFilename: 'chunks/[name].js', }, diff --git a/yarn.lock b/yarn.lock index 5bef673307..6c9161ed99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -942,11 +942,6 @@ exec-sh "^0.3.2" minimist "^1.2.0" -"@coolaj86/urequest@^1.3.6": - version "1.3.7" - resolved "https://registry.yarnpkg.com/@coolaj86/urequest/-/urequest-1.3.7.tgz#66a1d66378dd6534e9c8e68948bf09acf32bab77" - integrity sha512-PPrVYra9aWvZjSCKl/x1pJ9ZpXda1652oJrPBYy5rQumJJMkmTBN3ux+sK2xAUwVvv2wnewDlaQaHLxLwSHnIA== - "@develar/schema-utils@~2.6.5": version "2.6.5" resolved "https://registry.yarnpkg.com/@develar/schema-utils/-/schema-utils-2.6.5.tgz#3ece22c5838402419a6e0425f85742b961d9b6c6" @@ -10102,13 +10097,6 @@ sshpk@^1.7.0: safer-buffer "^2.0.2" tweetnacl "~0.14.0" -ssl-root-cas@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/ssl-root-cas/-/ssl-root-cas-1.3.1.tgz#6b0566f7de4f0e6be99fbd93dbfbe5c7ab33b949" - integrity sha512-KR8J210Wfvjh+iNE9jcQEgbG0VG2713PHreItx6aNCPnkFO8XChz1cJ4iuCGeBj0+8wukLmgHgJqX+O5kRjPkQ== - dependencies: - "@coolaj86/urequest" "^1.3.6" - ssri@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.1.tgz#2a3c41b28dd45b62b63676ecb74001265ae9edd8"