mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge remote-tracking branch 'upstream/master' into make-menu-registry-obsolete
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
40 files changed
+670
-333
No files matched your search
@@ -136,11 +136,16 @@ export class ClusterManager extends Singleton {
|
||||
entity.spec.metrics.prometheus = prometheus;
|
||||
}
|
||||
|
||||
// Only set the icon if the preference is set. If the preference is not set
|
||||
// then let the source determine if a cluster has an icon.
|
||||
if (cluster.preferences.icon) {
|
||||
entity.spec.icon ??= {};
|
||||
entity.spec.icon.src = cluster.preferences.icon;
|
||||
} else if (cluster.preferences.icon === null) {
|
||||
/**
|
||||
* NOTE: only clear the icon if set to `null` by ClusterIconSettings.
|
||||
* We can then also clear that value too
|
||||
*/
|
||||
entity.spec.icon = undefined;
|
||||
cluster.preferences.icon = undefined;
|
||||
}
|
||||
|
||||
catalogEntityRegistry.items.splice(index, 1, entity);
|
||||
@@ -177,7 +182,8 @@ export class ClusterManager extends Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
@action syncClustersFromCatalog(entities: KubernetesCluster[]) {
|
||||
@action
|
||||
protected syncClustersFromCatalog(entities: KubernetesCluster[]) {
|
||||
for (const entity of entities) {
|
||||
const cluster = this.store.getById(entity.metadata.uid);
|
||||
|
||||
|
||||
+4
-3
@@ -102,7 +102,10 @@ configurePackages();
|
||||
mangleProxyEnv();
|
||||
|
||||
logger.debug("[APP-MAIN] initializing ipc main handlers");
|
||||
initializers.initIpcMainHandlers();
|
||||
|
||||
const menuItems = di.inject(electronMenuItemsInjectable);
|
||||
|
||||
initializers.initIpcMainHandlers(menuItems);
|
||||
|
||||
if (app.commandLine.getSwitchValue("proxy-server") !== "") {
|
||||
process.env.HTTPS_PROXY = app.commandLine.getSwitchValue("proxy-server");
|
||||
@@ -239,8 +242,6 @@ app.on("ready", async () => {
|
||||
logger.info("🖥️ Starting WindowManager");
|
||||
const windowManager = WindowManager.createInstance();
|
||||
|
||||
const menuItems = di.inject(electronMenuItemsInjectable);
|
||||
|
||||
onQuitCleanup.push(
|
||||
initMenu(windowManager, menuItems),
|
||||
initTray(windowManager),
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
|
||||
import { BrowserWindow, dialog, IpcMainInvokeEvent, Menu } from "electron";
|
||||
import { clusterFrameMap } from "../../common/cluster-frames";
|
||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../common/cluster-ipc";
|
||||
import type { ClusterId } from "../../common/cluster-types";
|
||||
@@ -30,12 +30,15 @@ import { catalogEntityRegistry } from "../catalog";
|
||||
import { pushCatalogToRenderer } from "../catalog-pusher";
|
||||
import { ClusterManager } from "../cluster-manager";
|
||||
import { ResourceApplier } from "../resource-applier";
|
||||
import { WindowManager } from "../window-manager";
|
||||
import { IpcMainWindowEvents, WindowManager } from "../window-manager";
|
||||
import path from "path";
|
||||
import { remove } from "fs-extra";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { getAppMenu } from "../menu/menu";
|
||||
import type { MenuRegistration } from "../menu/menu-registration";
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
export function initIpcMainHandlers() {
|
||||
export function initIpcMainHandlers(electronMenuItems: IComputedValue<MenuRegistration[]>) {
|
||||
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
||||
return ClusterStore.getInstance()
|
||||
.getById(clusterId)
|
||||
@@ -148,4 +151,16 @@ export function initIpcMainHandlers() {
|
||||
|
||||
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts);
|
||||
});
|
||||
|
||||
ipcMainOn(IpcMainWindowEvents.OPEN_CONTEXT_MENU, async (event) => {
|
||||
const menu = Menu.buildFromTemplate(getAppMenu(WindowManager.getInstance(), electronMenuItems.get()));
|
||||
const options = {
|
||||
...BrowserWindow.fromWebContents(event.sender),
|
||||
// Center of the topbar menu icon
|
||||
x: 20,
|
||||
y: 20,
|
||||
} as Electron.PopupOptions;
|
||||
|
||||
menu.popup(options);
|
||||
});
|
||||
}
|
||||
+58
-7
@@ -50,6 +50,24 @@ export function isLongRunningRequest(reqUrl: string) {
|
||||
return getBoolean(url.searchParams, watchParam) || getBoolean(url.searchParams, followParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the list of ports that chrome considers unsafe to allow HTTP
|
||||
* conntections to. Because they are the standard ports for processes that are
|
||||
* too forgiving in the connection types they accept.
|
||||
*
|
||||
* If we get one of these ports, the easiest thing to do is to just try again.
|
||||
*
|
||||
* Source: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/net/base/port_util.cc
|
||||
*/
|
||||
const disallowedPorts = new Set([
|
||||
1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,
|
||||
87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,
|
||||
139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,
|
||||
540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,
|
||||
2049, 3659, 4045, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669, 6697,
|
||||
10080,
|
||||
]);
|
||||
|
||||
export class LensProxy extends Singleton {
|
||||
protected origin: string;
|
||||
protected proxyServer: http.Server;
|
||||
@@ -91,12 +109,13 @@ export class LensProxy extends Singleton {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the lens proxy.
|
||||
* @resolves After the server is listening
|
||||
* @rejects if there is an error before that happens
|
||||
* Starts to listen on an OS provided port. Will reject if the server throws
|
||||
* an error.
|
||||
*
|
||||
* Resolves with the port number that was picked
|
||||
*/
|
||||
listen(): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
private attemptToListen(): Promise<number> {
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
this.proxyServer.listen(0, "127.0.0.1");
|
||||
|
||||
this.proxyServer
|
||||
@@ -113,7 +132,7 @@ export class LensProxy extends Singleton {
|
||||
|
||||
this.port = port;
|
||||
appEventBus.emit({ name: "lens-proxy", action: "listen", params: { port }});
|
||||
resolve();
|
||||
resolve(port);
|
||||
})
|
||||
.once("error", (error) => {
|
||||
logger.info(`[LENS-PROXY]: Proxy server failed to start: ${error}`);
|
||||
@@ -122,8 +141,40 @@ export class LensProxy extends Singleton {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the lens proxy.
|
||||
* @resolves After the server is listening on a good port
|
||||
* @rejects if there is an error before that happens
|
||||
*/
|
||||
async listen(): Promise<void> {
|
||||
const seenPorts = new Set<number>();
|
||||
|
||||
while(true) {
|
||||
this.proxyServer?.close();
|
||||
const port = await this.attemptToListen();
|
||||
|
||||
if (!disallowedPorts.has(port)) {
|
||||
// We didn't get a port that would result in an ERR_UNSAFE_PORT error, use it
|
||||
return;
|
||||
}
|
||||
|
||||
logger.warn(`[LENS-PROXY]: Proxy server has with port known to be considered unsafe to connect to by chrome, restarting...`);
|
||||
|
||||
if (seenPorts.has(port)) {
|
||||
/**
|
||||
* Assume that if we have seen the port before, then the OS has looped
|
||||
* through all the ports possible and we will not be able to get a safe
|
||||
* port.
|
||||
*/
|
||||
throw new Error("Failed to start LensProxy due to seeing too many unsafe ports. Please restart Lens.");
|
||||
} else {
|
||||
seenPorts.add(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
logger.info("Closing proxy server");
|
||||
logger.info("[LENS-PROXY]: Closing server");
|
||||
this.proxyServer.close();
|
||||
this.closed = true;
|
||||
}
|
||||
|
||||
+12
-2
@@ -63,7 +63,7 @@ export function showAbout(browserWindow: BrowserWindow) {
|
||||
});
|
||||
}
|
||||
|
||||
export function buildMenu(
|
||||
export function getAppMenu(
|
||||
windowManager: WindowManager,
|
||||
electronMenuItems: MenuRegistration[],
|
||||
) {
|
||||
@@ -324,5 +324,15 @@ export function buildMenu(
|
||||
appMenu.delete("mac");
|
||||
}
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate([...appMenu.values()]));
|
||||
return [...appMenu.values()];
|
||||
|
||||
}
|
||||
|
||||
export function buildMenu(
|
||||
windowManager: WindowManager,
|
||||
electronMenuItems: MenuRegistration[],
|
||||
) {
|
||||
Menu.setApplicationMenu(
|
||||
Menu.buildFromTemplate(getAppMenu(windowManager, electronMenuItems)),
|
||||
);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export class NodeShellSession extends ShellSession {
|
||||
const args = ["exec", "-i", "-t", "-n", "kube-system", this.podName, "--"];
|
||||
const nodeApi = new NodesApi({
|
||||
objectConstructor: Node,
|
||||
request: KubeJsonApi.forCluster(this.cluster),
|
||||
request: KubeJsonApi.forCluster(this.cluster.id),
|
||||
});
|
||||
const node = await nodeApi.get({ name: this.nodeName });
|
||||
const nodeOs = node.getOperatingSystem();
|
||||
|
||||
@@ -158,6 +158,8 @@ export abstract class ShellSession {
|
||||
cwd,
|
||||
env,
|
||||
name: "xterm-256color",
|
||||
// TODO: Something else is broken here so we need to force the use of winPty on windows
|
||||
useConpty: false,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,13 @@ import { delay, iter, Singleton } from "../common/utils";
|
||||
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
||||
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||
import logger from "./logger";
|
||||
import { productName } from "../common/vars";
|
||||
import { isMac, productName } from "../common/vars";
|
||||
import { LensProxy } from "./lens-proxy";
|
||||
|
||||
export const enum IpcMainWindowEvents {
|
||||
OPEN_CONTEXT_MENU = "window:open-context-menu",
|
||||
}
|
||||
|
||||
function isHideable(window: BrowserWindow | null): boolean {
|
||||
return Boolean(window && !window.isDestroyed());
|
||||
}
|
||||
@@ -81,7 +85,8 @@ export class WindowManager extends Singleton {
|
||||
show: false,
|
||||
minWidth: 700, // accommodate 800 x 600 display minimum
|
||||
minHeight: 500, // accommodate 800 x 600 display minimum
|
||||
titleBarStyle: "hiddenInset",
|
||||
titleBarStyle: isMac ? "hiddenInset" : "hidden",
|
||||
frame: isMac,
|
||||
backgroundColor: "#1e2124",
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
|
||||
Reference in new issue
Block a user