1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/index.ts
Alex Andreev cd9a442fe1 Allowing to disable hardware acceleration
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
2020-10-23 15:42:49 +03:00

93 lines
2.7 KiB
TypeScript

// Main process
import "../common/system-ca"
import "../common/prometheus-providers"
import { app, dialog } from "electron"
import { appName } from "../common/vars";
import path from "path"
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"
const workingDir = path.join(app.getPath("appData"), appName);
app.setName(appName);
if (!process.env.CICD) {
app.setPath("userData", workingDir);
}
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() {
await shellSync();
logger.info(`🚀 Starting Lens from "${workingDir}"`)
tracker.event("app", "start");
const updater = new AppUpdater()
updater.start();
registerFileProtocol("static", __static);
// find free port
let proxyPort: number
try {
proxyPort = await getFreePort()
} catch (error) {
logger.error(error)
dialog.showErrorBox("Lens Error", "Could not find a free port for the cluster proxy")
app.quit();
}
// preload configuration from stores
await Promise.all([
clusterStore.load(),
workspaceStore.load(),
]);
// create cluster manager
clusterManager = new ClusterManager(proxyPort);
// run proxy
try {
proxyServer = LensProxy.create(proxyPort, clusterManager);
} catch (error) {
logger.error(`Could not start proxy (127.0.0:${proxyPort}): ${error.message}`)
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);
}
// Disable hardware acceleration if flag is checked in Preferences
userStore.load();
if (userStore.preferences.disableHardwareAcceleration) {
app.disableHardwareAcceleration();
}
app.on("ready", main);
app.on("will-quit", async (event) => {
event.preventDefault(); // To allow mixpanel sending to be executed
if (proxyServer) proxyServer.close()
if (clusterManager) clusterManager.stop()
app.exit();
})