1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/index.ts
Roman de77f486b1 extend #draggable-top area to header's height
Signed-off-by: Roman <ixrock@gmail.com>
2020-07-17 13:27:41 +03:00

89 lines
2.6 KiB
TypeScript

// Main process
import "../common/system-ca"
import "../common/prometheus-providers"
import { app, dialog } from "electron"
import { appName, appProto, staticDir, staticProto } from "../common/vars";
import path from "path"
import initMenu from "./menu"
import { LensProxy } from "./lens-proxy"
import { WindowManager } from "./window-manager";
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 { registerFileProtocol } from "../common/register-protocol";
import { clusterStore } from "../common/cluster-store"
import { userStore } from "../common/user-store";
import { workspaceStore } from "../common/workspace-store";
import { tracker } from "../common/tracker";
import logger from "./logger"
let windowManager: WindowManager;
let clusterManager: ClusterManager;
let proxyServer: LensProxy;
mangleProxyEnv()
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server")
}
async function main() {
shellSync(app.getLocale());
const workingDir = path.join(app.getPath("appData"), appName);
app.setName(appName);
app.setPath("userData", workingDir);
logger.info(`🚀 Starting Lens from "${workingDir}"`)
tracker.event("app", "start");
const updater = new AppUpdater()
updater.start();
initMenu();
registerFileProtocol(appProto, app.getPath("userData"));
registerFileProtocol(staticProto, staticDir);
// find free port
let proxyPort: number
try {
proxyPort = await getFreePort()
} catch (error) {
await dialog.showErrorBox("Lens Error", "Could not find a free port for the cluster proxy")
app.quit();
}
// preload configuration from stores
await Promise.all([
userStore.load(),
clusterStore.load(),
workspaceStore.load(),
]);
// create cluster manager
clusterManager = new ClusterManager(proxyPort);
// run proxy
try {
proxyServer = LensProxy.create(clusterManager);
} catch (error) {
logger.error(`Could not start proxy (127.0.0:${proxyPort}): ${error.message}`)
await dialog.showErrorBox("Lens Error", `Could not start proxy (127.0.0:${proxyPort}): ${error.message || "unknown error"}`)
app.quit();
}
// create window manager and open app
windowManager = new WindowManager(proxyPort);
windowManager.showSplash();
}
app.on("ready", main);
app.on("will-quit", async (event) => {
event.preventDefault(); // To allow mixpanel sending to be executed
if (clusterManager) clusterManager.stop()
if (proxyServer) proxyServer.close()
app.exit();
})