From 4e18c992d8afbc82f4ef226995112014029ca951 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 17 Jun 2020 16:39:39 +0300 Subject: [PATCH] reverting dashboard rendering to webview, part 3 --- package.json | 1 - src/common/vars.ts | 4 ++++ src/main/cluster.ts | 17 ++++++++--------- src/main/index.ts | 9 ++------- src/main/window-manager.ts | 2 -- webpack.main.ts | 2 +- webpack.renderer.ts | 27 ++++++++++++++++----------- yarn.lock | 30 +----------------------------- 8 files changed, 32 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 2318781305..9dc9e4cc85 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,6 @@ "dompurify": "^2.0.11", "electron-builder": "^22.7.0", "electron-notarize": "^0.3.0", - "electron-reloader": "^1.0.1", "electron-serve": "^1.0.0", "file-loader": "^6.0.0", "flex.box": "^3.4.4", diff --git a/src/common/vars.ts b/src/common/vars.ts index 5d10085d0d..5a47e115b3 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -1,6 +1,10 @@ // App's common configuration for any process (main, renderer, build pipeline, etc.) import path from "path"; +// Temp +export const reactAppName = "app_react" +export const vueAppName = "app_vue" + // Flags export const isMac = process.platform === "darwin" export const isWindows = process.platform === "win32" diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 5adb9a9401..e9aee0c28e 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -180,15 +180,14 @@ export class Cluster implements ClusterInfo { } } - protected async k8sRequest(path: string, opts: request.RequestPromiseOptions = {}) { - const prefix = apiPrefix.KUBE_BASE; - const url = `http://127.0.0.1:${this.port}${prefix}${path}`; - opts.json = true; - opts.timeout = 10000; - opts.headers = Object.assign({}, opts.headers, { - host: `${this.id}.localhost:${this.port}`, - }); - return request(url, opts); + protected async k8sRequest(path: string, opts?: request.RequestPromiseOptions) { + const options = Object.assign({ + json: true, + timeout: 10000 + }, (opts || {})) + if (!options.headers) { options.headers = {} } + options.headers.host = `${this.id}.localhost:${this.port}` + return request(`http://127.0.0.1:${this.port}${apiPrefix.KUBE_BASE}${path}`, options) } protected async getConnectionStatus() { diff --git a/src/main/index.ts b/src/main/index.ts index 48a26db814..b6fc87c820 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -19,7 +19,7 @@ import { getFreePort } from "./port" import { mangleProxyEnv } from "./proxy-env" import { findMainWebContents } from "./webcontents" import { registerStaticProtocol } from "../common/register-static"; -import { isMac } from "../common/vars"; +import { isMac, vueAppName } from "../common/vars"; mangleProxyEnv() if (app.commandLine.getSwitchValue("proxy-server") !== "") { @@ -31,7 +31,7 @@ let windowManager: WindowManager = null; let clusterManager: ClusterManager = null; const vmURL = formatUrl({ - pathname: path.join(__dirname, "index.html"), + pathname: path.join(__dirname, `${vueAppName}.html`), protocol: "file", slashes: true, }) @@ -132,8 +132,3 @@ app.on("will-quit", async (event) => { if (clusterManager) clusterManager.stop() app.exit(0); }) - -// todo: auto-restart app in dev-mode -// if (isDevelopment) { -// require('electron-reloader')(module); -// } diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 7f48cdeea8..513dfdf215 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -2,7 +2,6 @@ import { BrowserWindow, shell } from "electron" import { PromiseIpc } from "electron-promise-ipc" import windowStateKeeper from "electron-window-state" import { tracker } from "./tracker"; -import { isDevelopment } from "../common/vars"; import { getStaticUrl } from "../common/register-static"; export class WindowManager { @@ -45,7 +44,6 @@ export class WindowManager { backgroundColor: "#1e2124", titleBarStyle: "hidden", webPreferences: { - devTools: isDevelopment, nodeIntegration: true, webviewTag: true }, diff --git a/webpack.main.ts b/webpack.main.ts index c012d2ec0a..9bfbef3675 100755 --- a/webpack.main.ts +++ b/webpack.main.ts @@ -7,8 +7,8 @@ export default function (): webpack.Configuration { return { context: __dirname, target: "electron-main", - devtool: "source-map", mode: isProduction ? "production" : "development", + devtool: isProduction ? "source-map" : "cheap-eval-source-map", cache: isDevelopment, entry: { main: path.resolve(mainDir, "index.ts"), diff --git a/webpack.renderer.ts b/webpack.renderer.ts index 632ce84437..93d638a6e2 100755 --- a/webpack.renderer.ts +++ b/webpack.renderer.ts @@ -5,7 +5,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"; import TerserPlugin from "terser-webpack-plugin"; import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin" import { VueLoaderPlugin } from "vue-loader" -import { htmlTemplate, isDevelopment, isProduction, outDir, rendererDir, sassCommonVars } from "./src/common/vars"; +import { htmlTemplate, isDevelopment, isProduction, outDir, reactAppName, rendererDir, sassCommonVars, vueAppName } from "./src/common/vars"; export default [ webpackConfigReact, @@ -16,11 +16,11 @@ export function webpackConfigReact(): webpack.Configuration { return { context: __dirname, target: "electron-renderer", - devtool: "source-map", + devtool: isProduction ? "source-map" : "cheap-eval-source-map", mode: isProduction ? "production" : "development", cache: isDevelopment, entry: { - renderer: path.resolve(rendererDir, "components/app.tsx"), + [reactAppName]: path.resolve(rendererDir, "components/app.tsx"), }, output: { path: outDir, @@ -34,7 +34,7 @@ export function webpackConfigReact(): webpack.Configuration { ] }, optimization: { - minimize: false, + minimize: isProduction, minimizer: [ new TerserPlugin({ cache: true, @@ -64,7 +64,7 @@ export function webpackConfigReact(): webpack.Configuration { { loader: "ts-loader", options: { - transpileOnly: false, // fixme: enable types resolution with ts-fork-checker + transpileOnly: true, compilerOptions: { // localization support // https://lingui.js.org/guides/typescript.html @@ -111,8 +111,7 @@ export function webpackConfigReact(): webpack.Configuration { }, plugins: [ - // fixme: enable with transpileOnly=true - // new ForkTsCheckerPlugin(), + new ForkTsCheckerPlugin(), // todo: check if this actually works in mode=production files // new webpack.DllReferencePlugin({ @@ -121,6 +120,12 @@ export function webpackConfigReact(): webpack.Configuration { // sourceType: libraryTarget, // }), + new HtmlWebpackPlugin({ + filename: `${reactAppName}.html`, + template: htmlTemplate, + inject: true, + }), + new MiniCssExtractPlugin({ filename: "[name].css", }), @@ -133,16 +138,15 @@ export function webpackConfigVue(): webpack.Configuration { config.resolve.extensions.push(".vue"); + config.entry = { + [vueAppName]: path.resolve(rendererDir, "_vue/index.js") + } config.resolve.alias = { "@": rendererDir, "vue$": "vue/dist/vue.esm.js", "vue-router$": "vue-router/dist/vue-router.esm.js", } - config.entry = { - renderer_vue: path.resolve(rendererDir, "_vue/index.js") - } - // rules and loaders config.module.rules = config.module.rules .filter(({ test }: { test: RegExp }) => !test.test(".ts")) @@ -189,6 +193,7 @@ export function webpackConfigVue(): webpack.Configuration { new ForkTsCheckerPlugin(), new HtmlWebpackPlugin({ + filename: `${vueAppName}.html`, template: htmlTemplate, inject: true, }), diff --git a/yarn.lock b/yarn.lock index f7bdb190e1..df8070c545 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3521,7 +3521,7 @@ chokidar@^2.1.8: optionalDependencies: fsevents "^1.2.7" -chokidar@^3.3.1, chokidar@^3.4.0: +chokidar@^3.4.0: version "3.4.0" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.0.tgz#b30611423ce376357c765b9b8f904b9fba3c0be8" integrity sha512-aXAaho2VJtisB/1fg1+3nlLJqGOuewTzQpd/Tz0yTg2R0e4IGtshYvtjowyEumcBv2z+y4+kc75Mz7j5xJskcQ== @@ -4214,13 +4214,6 @@ date-fns@^2.0.1, date-fns@^2.14.0: resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.14.0.tgz#359a87a265bb34ef2e38f93ecf63ac453f9bc7ba" integrity sha512-1zD+68jhFgDIM0rF05rcwYO8cExdNqxjq4xP1QKM60Q45mnO6zaMWB4tOzrIr4M4GSLntsKeE4c9Bdl2jhL/yw== -date-time@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/date-time/-/date-time-3.1.0.tgz#0d1e934d170579f481ed8df1e2b8ff70ee845e1e" - integrity sha512-uqCUKXE5q1PNBXjPqvwhwJf9SwMoAHBgWJ6DcrnS5o+W2JOiIILl0JEdVD8SGujrNS02GGxgwAg2PN2zONgtjg== - dependencies: - time-zone "^1.0.0" - de-indent@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d" @@ -4628,11 +4621,6 @@ electron-download@^4.1.0, electron-download@^4.1.1: semver "^5.4.1" sumchecker "^2.0.2" -electron-is-dev@^1.1.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-1.2.0.tgz#2e5cea0a1b3ccf1c86f577cee77363ef55deb05e" - integrity sha512-R1oD5gMBPS7PVU8gJwH6CtT0e6VSoD0+SzSnYpNm+dBkcijgA+K7VAMHDfnRq/lkKPZArpzplTW6jfiMYosdzw== - electron-notarize@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/electron-notarize/-/electron-notarize-0.3.0.tgz#b93c606306eac558b250c78ff95273ddb9fedf0a" @@ -4665,17 +4653,6 @@ electron-publish@22.7.0: lazy-val "^1.0.4" mime "^2.4.5" -electron-reloader@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/electron-reloader/-/electron-reloader-1.0.1.tgz#15b193219b6583aedd2c95fa143d9bfc244bfdec" - integrity sha512-jVLK4SMvLRI8bWMTLtcyoRcmntTWcDrLUFt5QefgdcgQwN8uKi05SMJ8dW+9yD+PM1ESuyE//poBHVmucV4vUg== - dependencies: - chalk "^3.0.0" - chokidar "^3.3.1" - date-time "^3.1.0" - electron-is-dev "^1.1.0" - find-up "^4.1.0" - electron-serve@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/electron-serve/-/electron-serve-1.0.0.tgz#babf2f5022102fa300a841d91e4c2e7048ac4b1f" @@ -10780,11 +10757,6 @@ through@2, through@^2.3.6: resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= -time-zone@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/time-zone/-/time-zone-1.0.0.tgz#99c5bf55958966af6d06d83bdf3800dc82faec5d" - integrity sha1-mcW/VZWJZq9tBtg73zgA3IL67F0= - timed-out@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"