diff --git a/src/main/index.ts b/src/main/index.ts index 265c91f6d4..cbe57a27d1 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -26,6 +26,8 @@ import { InstalledExtension, extensionDiscovery } from "../extensions/extension- import type { LensExtensionId } from "../extensions/lens-extension"; import { installDeveloperTools } from "./developer-tools"; import { filesystemProvisionerStore } from "./extension-filesystem"; +import requestPromise from "request-promise-native"; +import { getAppVersion } from "../common/utils"; const workingDir = path.join(app.getPath("appData"), appName); let proxyPort: number; @@ -67,14 +69,17 @@ app.on("ready", async () => { app.exit(); }); + logger.info(`📡 Checking for app updates`); const updater = new AppUpdater(); updater.start(); registerFileProtocol("static", __static); + logger.info("🤓 Installing developer tools"); await installDeveloperTools(); + logger.info("💾 Loading stores"); // preload await Promise.all([ userStore.load(), @@ -86,6 +91,7 @@ app.on("ready", async () => { // find free port try { + logger.info("🔑 Getting free port for LensProxy server"); proxyPort = await getFreePort(); } catch (error) { logger.error(error); @@ -98,6 +104,7 @@ app.on("ready", async () => { // run proxy try { + logger.info("🔌 Starting LensProxy"); // eslint-disable-next-line unused-imports/no-unused-vars-ts proxyServer = LensProxy.create(proxyPort, clusterManager); } catch (error) { @@ -106,10 +113,33 @@ app.on("ready", async () => { app.exit(); } + // test proxy connection + try { + logger.info("🔎 Testing LensProxy connection ..."); + const response = await requestPromise({ + method: "GET", + uri: `http://localhost:${proxyPort}/version`, + resolveWithFullResponse: true + }); + + const appVersion = JSON.parse(response.body).version; + + if (getAppVersion() != appVersion) { + logger.error(`Proxy server responded with invalid response: ${response.body}`); + } + logger.info("⚡ LensProxy connection OK"); + } catch (error) { + logger.error("Checking proxy server connection failed", error); + } + extensionLoader.init(); extensionDiscovery.init(); + + logger.info("🖥️ Starting WindowManager"); windowManager = WindowManager.getInstance(proxyPort); + logger.info("🧩 Initializing extensions"); + // call after windowManager to see splash earlier try { const extensions = await extensionDiscovery.load(); diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index e4f6ab4a34..98945413fb 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -29,7 +29,7 @@ export class LensProxy { listen(port = this.port): this { this.proxyServer = this.buildCustomProxy().listen(port); - logger.info(`LensProxy server has started at ${this.origin}`); + logger.info(`[LENS-PROXY] LensProxy server has started at ${this.origin}`); return this; } diff --git a/src/main/router.ts b/src/main/router.ts index 896893a592..b5dd8b99ac 100644 --- a/src/main/router.ts +++ b/src/main/router.ts @@ -5,7 +5,7 @@ import path from "path"; import { readFile } from "fs-extra"; import { Cluster } from "./cluster"; import { apiPrefix, appName, publicPath, isDevelopment, webpackDevServerPort } from "../common/vars"; -import { helmRoute, kubeconfigRoute, metricsRoute, portForwardRoute, resourceApplierRoute, watchRoute } from "./routes"; +import { helmRoute, kubeconfigRoute, metricsRoute, portForwardRoute, resourceApplierRoute, watchRoute, versionRoute } from "./routes"; import logger from "./logger"; export interface RouterRequestOpts { @@ -143,6 +143,7 @@ export class Router { this.handleStaticFile(params.path, response, req); }); + this.router.add({ method: "get", path: "/version"}, versionRoute.getVersion.bind(versionRoute)); this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute)); // Watch API diff --git a/src/main/routes/index.ts b/src/main/routes/index.ts index 5bc5b3f3dd..af2901862f 100644 --- a/src/main/routes/index.ts +++ b/src/main/routes/index.ts @@ -4,3 +4,4 @@ export * from "./port-forward-route"; export * from "./watch-route"; export * from "./helm-route"; export * from "./resource-applier-route"; +export * from "./version-route"; \ No newline at end of file diff --git a/src/main/routes/version-route.ts b/src/main/routes/version-route.ts new file mode 100644 index 0000000000..81ada9eca7 --- /dev/null +++ b/src/main/routes/version-route.ts @@ -0,0 +1,13 @@ +import { LensApiRequest } from "../router"; +import { LensApi } from "../lens-api"; +import { getAppVersion } from "../../common/utils"; + +class VersionRoute extends LensApi { + public async getVersion(request: LensApiRequest) { + const { response } = request; + + this.respondJson(response, { version: getAppVersion()}, 200); + } +} + +export const versionRoute = new VersionRoute(); diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index bf7458afa0..1f4fdd42f1 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -8,6 +8,7 @@ import { initMenu } from "./menu"; import { initTray } from "./tray"; import { Singleton } from "../common/utils"; import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames"; +import logger from "./logger"; export class WindowManager extends Singleton { protected mainWindow: BrowserWindow; @@ -81,10 +82,19 @@ export class WindowManager extends Singleton { this.splashWindow = null; app.dock?.hide(); // hide icon in dock (mac-os) }); + + this.mainWindow.webContents.on("did-fail-load", (_event, code, desc) => { + logger.error(`[WINDOW-MANAGER] Failed to load Main window`, code, desc); + }); + + this.mainWindow.webContents.on("did-finish-load", () => { + logger.info("[WINDOW-MANAGER] Main window loaded"); + }); } try { if (showSplash) await this.showSplash(); + logger.info(`[WINDOW-MANAGER] Loading Main window from url: ${this.mainUrl} ...`); await this.mainWindow.loadURL(this.mainUrl); this.mainWindow.show(); this.splashWindow?.close();