mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add more log entries on start up (#1955)
* Add more log entries on start up Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * And log entry about shell sync Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Refactoring Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Add new line Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Apply suggestions from code review Co-authored-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
0727456aa1
commit
ad6de71826
@ -1,3 +1,4 @@
|
|||||||
|
import requestPromise from "request-promise-native";
|
||||||
import packageInfo from "../../../package.json";
|
import packageInfo from "../../../package.json";
|
||||||
|
|
||||||
export function getAppVersion(): string {
|
export function getAppVersion(): string {
|
||||||
@ -11,3 +12,13 @@ export function getBundledKubectlVersion(): string {
|
|||||||
export function getBundledExtensions(): string[] {
|
export function getBundledExtensions(): string[] {
|
||||||
return packageInfo.lens?.extensions || [];
|
return packageInfo.lens?.extensions || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAppVersionFromProxyServer(proxyPort: number): Promise<string> {
|
||||||
|
const response = await requestPromise({
|
||||||
|
method: "GET",
|
||||||
|
uri: `http://localhost:${proxyPort}/version`,
|
||||||
|
resolveWithFullResponse: true
|
||||||
|
});
|
||||||
|
|
||||||
|
return JSON.parse(response.body).version;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
|
import logger from "./logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs Electron developer tools in the development build.
|
* Installs Electron developer tools in the development build.
|
||||||
* The dependency is not bundled to the production build.
|
* The dependency is not bundled to the production build.
|
||||||
*/
|
*/
|
||||||
export const installDeveloperTools = async () => {
|
export const installDeveloperTools = async () => {
|
||||||
if (process.env.NODE_ENV === "development") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
|
logger.info("🤓 Installing developer tools");
|
||||||
const { default: devToolsInstaller, REACT_DEVELOPER_TOOLS } = await import("electron-devtools-installer");
|
const { default: devToolsInstaller, REACT_DEVELOPER_TOOLS } = await import("electron-devtools-installer");
|
||||||
|
|
||||||
return devToolsInstaller([REACT_DEVELOPER_TOOLS]);
|
return devToolsInstaller([REACT_DEVELOPER_TOOLS]);
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import { InstalledExtension, extensionDiscovery } from "../extensions/extension-
|
|||||||
import type { LensExtensionId } from "../extensions/lens-extension";
|
import type { LensExtensionId } from "../extensions/lens-extension";
|
||||||
import { installDeveloperTools } from "./developer-tools";
|
import { installDeveloperTools } from "./developer-tools";
|
||||||
import { filesystemProvisionerStore } from "./extension-filesystem";
|
import { filesystemProvisionerStore } from "./extension-filesystem";
|
||||||
|
import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
||||||
import { bindBroadcastHandlers } from "../common/ipc";
|
import { bindBroadcastHandlers } from "../common/ipc";
|
||||||
|
|
||||||
const workingDir = path.join(app.getPath("appData"), appName);
|
const workingDir = path.join(app.getPath("appData"), appName);
|
||||||
@ -62,6 +63,7 @@ if (process.env.LENS_DISABLE_GPU) {
|
|||||||
|
|
||||||
app.on("ready", async () => {
|
app.on("ready", async () => {
|
||||||
logger.info(`🚀 Starting Lens from "${workingDir}"`);
|
logger.info(`🚀 Starting Lens from "${workingDir}"`);
|
||||||
|
logger.info("🐚 Syncing shell environment");
|
||||||
await shellSync();
|
await shellSync();
|
||||||
|
|
||||||
bindBroadcastHandlers();
|
bindBroadcastHandlers();
|
||||||
@ -70,6 +72,7 @@ app.on("ready", async () => {
|
|||||||
app.exit();
|
app.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.info(`📡 Checking for app updates`);
|
||||||
const updater = new AppUpdater();
|
const updater = new AppUpdater();
|
||||||
|
|
||||||
updater.start();
|
updater.start();
|
||||||
@ -78,6 +81,7 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
await installDeveloperTools();
|
await installDeveloperTools();
|
||||||
|
|
||||||
|
logger.info("💾 Loading stores");
|
||||||
// preload
|
// preload
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
userStore.load(),
|
userStore.load(),
|
||||||
@ -89,6 +93,7 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
// find free port
|
// find free port
|
||||||
try {
|
try {
|
||||||
|
logger.info("🔑 Getting free port for LensProxy server");
|
||||||
proxyPort = await getFreePort();
|
proxyPort = await getFreePort();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
@ -101,6 +106,7 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
// run proxy
|
// run proxy
|
||||||
try {
|
try {
|
||||||
|
logger.info("🔌 Starting LensProxy");
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||||
proxyServer = LensProxy.create(proxyPort, clusterManager);
|
proxyServer = LensProxy.create(proxyPort, clusterManager);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -109,10 +115,27 @@ app.on("ready", async () => {
|
|||||||
app.exit();
|
app.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test proxy connection
|
||||||
|
try {
|
||||||
|
logger.info("🔎 Testing LensProxy connection ...");
|
||||||
|
const versionFromProxy = await getAppVersionFromProxyServer(proxyPort);
|
||||||
|
|
||||||
|
if (getAppVersion() !== versionFromProxy) {
|
||||||
|
logger.error(`Proxy server responded with invalid response`);
|
||||||
|
}
|
||||||
|
logger.info("⚡ LensProxy connection OK");
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Checking proxy server connection failed", error);
|
||||||
|
}
|
||||||
|
|
||||||
extensionLoader.init();
|
extensionLoader.init();
|
||||||
extensionDiscovery.init();
|
extensionDiscovery.init();
|
||||||
|
|
||||||
|
logger.info("🖥️ Starting WindowManager");
|
||||||
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
||||||
|
|
||||||
|
logger.info("🧩 Initializing extensions");
|
||||||
|
|
||||||
// call after windowManager to see splash earlier
|
// call after windowManager to see splash earlier
|
||||||
try {
|
try {
|
||||||
const extensions = await extensionDiscovery.load();
|
const extensions = await extensionDiscovery.load();
|
||||||
|
|||||||
@ -29,7 +29,7 @@ export class LensProxy {
|
|||||||
|
|
||||||
listen(port = this.port): this {
|
listen(port = this.port): this {
|
||||||
this.proxyServer = this.buildCustomProxy().listen(port);
|
this.proxyServer = this.buildCustomProxy().listen(port);
|
||||||
logger.info(`LensProxy server has started at ${this.origin}`);
|
logger.info(`[LENS-PROXY]: Proxy server has started at ${this.origin}`);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import path from "path";
|
|||||||
import { readFile } from "fs-extra";
|
import { readFile } from "fs-extra";
|
||||||
import { Cluster } from "./cluster";
|
import { Cluster } from "./cluster";
|
||||||
import { apiPrefix, appName, publicPath, isDevelopment, webpackDevServerPort } from "../common/vars";
|
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";
|
import logger from "./logger";
|
||||||
|
|
||||||
export interface RouterRequestOpts {
|
export interface RouterRequestOpts {
|
||||||
@ -143,6 +143,7 @@ export class Router {
|
|||||||
this.handleStaticFile(params.path, response, req);
|
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));
|
this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute));
|
||||||
|
|
||||||
// Watch API
|
// Watch API
|
||||||
|
|||||||
@ -4,3 +4,4 @@ export * from "./port-forward-route";
|
|||||||
export * from "./watch-route";
|
export * from "./watch-route";
|
||||||
export * from "./helm-route";
|
export * from "./helm-route";
|
||||||
export * from "./resource-applier-route";
|
export * from "./resource-applier-route";
|
||||||
|
export * from "./version-route";
|
||||||
|
|||||||
13
src/main/routes/version-route.ts
Normal file
13
src/main/routes/version-route.ts
Normal file
@ -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();
|
||||||
@ -8,6 +8,7 @@ import { initMenu } from "./menu";
|
|||||||
import { initTray } from "./tray";
|
import { initTray } from "./tray";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
||||||
|
import logger from "./logger";
|
||||||
|
|
||||||
export class WindowManager extends Singleton {
|
export class WindowManager extends Singleton {
|
||||||
protected mainWindow: BrowserWindow;
|
protected mainWindow: BrowserWindow;
|
||||||
@ -81,10 +82,19 @@ export class WindowManager extends Singleton {
|
|||||||
this.splashWindow = null;
|
this.splashWindow = null;
|
||||||
app.dock?.hide(); // hide icon in dock (mac-os)
|
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 {
|
try {
|
||||||
if (showSplash) await this.showSplash();
|
if (showSplash) await this.showSplash();
|
||||||
|
logger.info(`[WINDOW-MANAGER]: Loading Main window from url: ${this.mainUrl} ...`);
|
||||||
await this.mainWindow.loadURL(this.mainUrl);
|
await this.mainWindow.loadURL(this.mainUrl);
|
||||||
this.mainWindow.show();
|
this.mainWindow.show();
|
||||||
this.splashWindow?.close();
|
this.splashWindow?.close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user