mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into turn-on-strict
This commit is contained in:
commit
729d9c3406
10 files changed
+193
-165
No files matched your search
@@ -144,22 +144,32 @@ export class ClusterManager extends Singleton {
|
||||
} else {
|
||||
entity.status.phase = (() => {
|
||||
if (!cluster) {
|
||||
logger.debug(`${logPrefix} setting entity ${entity.getName()} to DISCONNECTED, reason="no cluster"`);
|
||||
|
||||
return LensKubernetesClusterStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
if (cluster.accessible) {
|
||||
logger.debug(`${logPrefix} setting entity ${entity.getName()} to CONNECTED, reason="cluster is accessible"`);
|
||||
|
||||
return LensKubernetesClusterStatus.CONNECTED;
|
||||
}
|
||||
|
||||
if (!cluster.disconnected) {
|
||||
logger.debug(`${logPrefix} setting entity ${entity.getName()} to CONNECTING, reason="cluster is not disconnected"`);
|
||||
|
||||
return LensKubernetesClusterStatus.CONNECTING;
|
||||
}
|
||||
|
||||
// Extensions are not allowed to use the Lens specific status phases
|
||||
if (!lensSpecificClusterStatuses.has(entity?.status?.phase)) {
|
||||
logger.debug(`${logPrefix} not clearing entity ${entity.getName()} status, reason="custom string"`);
|
||||
|
||||
return entity.status.phase;
|
||||
}
|
||||
|
||||
logger.debug(`${logPrefix} setting entity ${entity.getName()} to DISCONNECTED, reason="fallthrough"`);
|
||||
|
||||
return LensKubernetesClusterStatus.DISCONNECTED;
|
||||
})();
|
||||
|
||||
|
||||
+1
-1
@@ -309,7 +309,7 @@ async function main(di: DiContainer) {
|
||||
|
||||
onQuitCleanup.push(
|
||||
initMenu(applicationMenuItems),
|
||||
await initTray(windowManager, trayMenuItems, navigateToPreferences),
|
||||
initTray(windowManager, trayMenuItems, navigateToPreferences),
|
||||
() => ShellSession.cleanup(),
|
||||
);
|
||||
|
||||
|
||||
+14
-63
@@ -4,22 +4,19 @@
|
||||
*/
|
||||
|
||||
import packageInfo from "../../../package.json";
|
||||
import type { NativeImage } from "electron";
|
||||
import { Menu, nativeImage, nativeTheme, Tray } from "electron";
|
||||
import { Menu, Tray } from "electron";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { autorun } from "mobx";
|
||||
import { showAbout } from "../menu/menu";
|
||||
import { checkForUpdates, isAutoUpdateEnabled } from "../app-updater";
|
||||
import type { WindowManager } from "../window-manager";
|
||||
import logger from "../logger";
|
||||
import { isWindows, productName } from "../../common/vars";
|
||||
import { isDevelopment, isWindows, productName, staticFilesDirectory } from "../../common/vars";
|
||||
import { exitApp } from "../exit-app";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import { base64, disposer, getOrInsertWithAsync, toJS } from "../../common/utils";
|
||||
import { disposer, toJS } from "../../common/utils";
|
||||
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
||||
import sharp from "sharp";
|
||||
import LogoLens from "../../renderer/components/icon/logo-lens.svg";
|
||||
import { JSDOM } from "jsdom";
|
||||
import path from "path";
|
||||
|
||||
|
||||
const TRAY_LOG_PREFIX = "[TRAY]";
|
||||
@@ -27,69 +24,25 @@ const TRAY_LOG_PREFIX = "[TRAY]";
|
||||
// note: instance of Tray should be saved somewhere, otherwise it disappears
|
||||
export let tray: Tray | null = null;
|
||||
|
||||
interface CreateTrayIconArgs {
|
||||
shouldUseDarkColors: boolean;
|
||||
size: number;
|
||||
sourceSvg: string;
|
||||
function getTrayIconPath(): string {
|
||||
return path.resolve(
|
||||
staticFilesDirectory,
|
||||
isDevelopment ? "../build/tray" : "icons", // copied within electron-builder extras
|
||||
"trayIconTemplate.png",
|
||||
);
|
||||
}
|
||||
|
||||
const trayIcons = new Map<boolean, NativeImage>();
|
||||
|
||||
async function createTrayIcon({ shouldUseDarkColors, size, sourceSvg }: CreateTrayIconArgs): Promise<NativeImage> {
|
||||
return getOrInsertWithAsync(trayIcons, shouldUseDarkColors, async () => {
|
||||
const trayIconColor = shouldUseDarkColors ? "white" : "black"; // Invert to show contrast
|
||||
const parsedSvg = base64.decode(sourceSvg.split("base64,")[1]);
|
||||
const svgDom = new JSDOM(`<body>${parsedSvg}</body>`);
|
||||
const svgRoot = svgDom.window.document.body.getElementsByTagName("svg")[0];
|
||||
|
||||
svgRoot.innerHTML += `<style>* {fill: ${trayIconColor} !important;}</style>`;
|
||||
|
||||
const iconBuffer = await sharp(Buffer.from(svgRoot.outerHTML))
|
||||
.resize({ width: size, height: size })
|
||||
.png()
|
||||
.toBuffer();
|
||||
|
||||
return nativeImage.createFromBuffer(iconBuffer);
|
||||
});
|
||||
}
|
||||
|
||||
function createCurrentTrayIcon() {
|
||||
return createTrayIcon({
|
||||
shouldUseDarkColors: nativeTheme.shouldUseDarkColors,
|
||||
size: 16,
|
||||
sourceSvg: LogoLens,
|
||||
});
|
||||
}
|
||||
|
||||
function watchShouldUseDarkColors(tray: Tray): Disposer {
|
||||
let prevShouldUseDarkColors = nativeTheme.shouldUseDarkColors;
|
||||
const onUpdated = () => {
|
||||
if (prevShouldUseDarkColors !== nativeTheme.shouldUseDarkColors) {
|
||||
prevShouldUseDarkColors = nativeTheme.shouldUseDarkColors;
|
||||
createCurrentTrayIcon()
|
||||
.then(img => tray.setImage(img));
|
||||
}
|
||||
};
|
||||
|
||||
nativeTheme.on("updated", onUpdated);
|
||||
|
||||
return () => nativeTheme.off("updated", onUpdated);
|
||||
}
|
||||
|
||||
export async function initTray(
|
||||
export function initTray(
|
||||
windowManager: WindowManager,
|
||||
trayMenuItems: IComputedValue<TrayMenuRegistration[]>,
|
||||
navigateToPreferences: () => void,
|
||||
): Promise<Disposer> {
|
||||
const icon = await createCurrentTrayIcon();
|
||||
const dispose = disposer();
|
||||
): Disposer {
|
||||
const icon = getTrayIconPath();
|
||||
|
||||
tray = new Tray(icon);
|
||||
tray.setToolTip(packageInfo.description);
|
||||
tray.setIgnoreDoubleClickEvents(true);
|
||||
|
||||
dispose.push(watchShouldUseDarkColors(tray));
|
||||
|
||||
if (isWindows) {
|
||||
tray.on("click", () => {
|
||||
windowManager
|
||||
@@ -98,7 +51,7 @@ export async function initTray(
|
||||
});
|
||||
}
|
||||
|
||||
dispose.push(
|
||||
return disposer(
|
||||
autorun(() => {
|
||||
try {
|
||||
const menu = createTrayMenu(windowManager, toJS(trayMenuItems.get()), navigateToPreferences);
|
||||
@@ -113,8 +66,6 @@ export async function initTray(
|
||||
tray = null;
|
||||
},
|
||||
);
|
||||
|
||||
return dispose;
|
||||
}
|
||||
|
||||
function getMenuItemConstructorOptions(trayItem: TrayMenuRegistration): Electron.MenuItemConstructorOptions {
|
||||
|
||||
@@ -6,14 +6,13 @@
|
||||
import "./components/app.scss";
|
||||
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import ReactDOM, { render, unmountComponentAtNode } from "react-dom";
|
||||
import * as Mobx from "mobx";
|
||||
import * as MobxReact from "mobx-react";
|
||||
import * as ReactRouter from "react-router";
|
||||
import * as ReactRouterDom from "react-router-dom";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { delay } from "../common/utils";
|
||||
import { isMac, isDevelopment } from "../common/vars";
|
||||
import { HelmRepoManager } from "../main/helm/helm-repo-manager";
|
||||
@@ -42,11 +41,11 @@ import navigateToAddClusterInjectable from "../common/front-end-routing/routes/
|
||||
import addSyncEntriesInjectable from "./initializers/add-sync-entries.injectable";
|
||||
import hotbarStoreInjectable from "../common/hotbars/store.injectable";
|
||||
import { bindEvents } from "./navigation/events";
|
||||
import assert from "assert";
|
||||
import openDeleteClusterDialogInjectable from "./components/delete-cluster-dialog/open.injectable";
|
||||
import { init } from "@sentry/electron/renderer";
|
||||
import kubernetesClusterCategoryInjectable from "../common/catalog/categories/kubernetes-cluster.injectable";
|
||||
import autoRegistrationInjectable from "../common/k8s-api/api-manager/auto-registration.injectable";
|
||||
import assert from "assert";
|
||||
|
||||
configurePackages(); // global packages
|
||||
registerCustomThemes(); // monaco editor themes
|
||||
@@ -73,12 +72,11 @@ export async function bootstrap(di: DiContainer) {
|
||||
bindEvents();
|
||||
|
||||
const rootElem = document.getElementById("app");
|
||||
|
||||
assert(rootElem);
|
||||
|
||||
const rootNode = createRoot(rootElem);
|
||||
const logPrefix = `[BOOTSTRAP-${process.isMainFrame ? "ROOT" : "CLUSTER"}-FRAME]:`;
|
||||
|
||||
assert(rootElem, "#app MUST exist");
|
||||
|
||||
|
||||
/**
|
||||
* This is injected here to initialize it for the side effect.
|
||||
*
|
||||
@@ -168,7 +166,7 @@ export async function bootstrap(di: DiContainer) {
|
||||
}
|
||||
|
||||
try {
|
||||
await initializeApp(() => rootNode.unmount());
|
||||
await initializeApp(() => unmountComponentAtNode(rootElem));
|
||||
} catch (error) {
|
||||
console.error(`[BOOTSTRAP]: view initialization error: ${error}`, {
|
||||
origin: location.href,
|
||||
@@ -176,12 +174,13 @@ export async function bootstrap(di: DiContainer) {
|
||||
});
|
||||
}
|
||||
|
||||
rootNode.render(
|
||||
render(
|
||||
<DiContextProvider value={{ di }}>
|
||||
<Router history={di.inject(historyInjectable)}>
|
||||
{DefaultProps(App)}
|
||||
</Router>
|
||||
</DiContextProvider>,
|
||||
rootElem,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user