mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Upgrade to Electron 14.2.4 (#4625)
Co-authored-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
58 files changed
+545
-418
No files matched your search
@@ -51,8 +51,7 @@ describe("create clusters", () => {
|
||||
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
|
||||
const mockOpts = {
|
||||
mockFs({
|
||||
"minikube-config.yml": JSON.stringify({
|
||||
apiVersion: "v1",
|
||||
clusters: [{
|
||||
@@ -74,9 +73,7 @@ describe("create clusters", () => {
|
||||
kind: "Config",
|
||||
preferences: {},
|
||||
}),
|
||||
};
|
||||
|
||||
mockFs(mockOpts);
|
||||
});
|
||||
|
||||
await di.runSetups();
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ import "../common/catalog-entities/kubernetes-cluster";
|
||||
import { disposer, toJS } from "../common/utils";
|
||||
import { debounce } from "lodash";
|
||||
import type { CatalogEntity } from "../common/catalog";
|
||||
import { CatalogIpcEvents } from "../common/ipc/catalog";
|
||||
import { catalogInitChannel, catalogItemsChannel } from "../common/ipc/catalog";
|
||||
|
||||
const broadcaster = debounce((items: CatalogEntity[]) => {
|
||||
broadcastMessage(CatalogIpcEvents.ITEMS, items);
|
||||
broadcastMessage(catalogItemsChannel, items);
|
||||
}, 1_000, { leading: true, trailing: true });
|
||||
|
||||
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
||||
return disposer(
|
||||
ipcMainOn(CatalogIpcEvents.INIT, () => broadcaster(toJS(catalog.items))),
|
||||
ipcMainOn(catalogInitChannel, () => broadcaster(toJS(catalog.items))),
|
||||
reaction(() => toJS(catalog.items), (items) => {
|
||||
broadcaster(items);
|
||||
}, {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "../common/cluster-ipc";
|
||||
import "../common/ipc/cluster";
|
||||
import type http from "http";
|
||||
import { action, makeObservable, observable, observe, reaction, toJS } from "mobx";
|
||||
import { Cluster } from "../common/cluster/cluster";
|
||||
|
||||
+1
-7
@@ -6,7 +6,6 @@
|
||||
// Main process
|
||||
|
||||
import { injectSystemCAs } from "../common/system-ca";
|
||||
import { initialize as initializeRemote } from "@electron/remote/main";
|
||||
import * as Mobx from "mobx";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsMainApi from "../extensions/main-api";
|
||||
@@ -24,7 +23,7 @@ import type { InstalledExtension } from "../extensions/extension-discovery/exten
|
||||
import type { LensExtensionId } from "../extensions/lens-extension";
|
||||
import { installDeveloperTools } from "./developer-tools";
|
||||
import { disposer, getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
||||
import { bindBroadcastHandlers, ipcMainOn } from "../common/ipc";
|
||||
import { ipcMainOn } from "../common/ipc";
|
||||
import { startUpdateChecking } from "./app-updater";
|
||||
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||
import { pushCatalogToRenderer } from "./catalog-pusher";
|
||||
@@ -81,9 +80,6 @@ di.runSetups().then(() => {
|
||||
app.disableHardwareAcceleration();
|
||||
}
|
||||
|
||||
logger.debug("[APP-MAIN] initializing remote");
|
||||
initializeRemote();
|
||||
|
||||
logger.debug("[APP-MAIN] configuring packages");
|
||||
configurePackages();
|
||||
|
||||
@@ -131,8 +127,6 @@ di.runSetups().then(() => {
|
||||
logger.info("🐚 Syncing shell environment");
|
||||
await shellSync();
|
||||
|
||||
bindBroadcastHandlers();
|
||||
|
||||
powerMonitor.on("shutdown", () => app.exit());
|
||||
|
||||
registerFileProtocol("static", __static);
|
||||
|
||||
@@ -3,23 +3,27 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { BrowserWindow, dialog, IpcMainInvokeEvent, Menu } from "electron";
|
||||
import { BrowserWindow, 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 { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../../common/ipc/cluster";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
import { ClusterStore } from "../../../common/cluster-store/cluster-store";
|
||||
import { appEventBus } from "../../../common/app-event-bus/event-bus";
|
||||
import { dialogShowOpenDialogHandler, ipcMainHandle, ipcMainOn } from "../../../common/ipc";
|
||||
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../common/ipc";
|
||||
import { catalogEntityRegistry } from "../../catalog";
|
||||
import { pushCatalogToRenderer } from "../../catalog-pusher";
|
||||
import { ClusterManager } from "../../cluster-manager";
|
||||
import { ResourceApplier } from "../../resource-applier";
|
||||
import { IpcMainWindowEvents, WindowManager } from "../../window-manager";
|
||||
import { WindowManager } from "../../window-manager";
|
||||
import path from "path";
|
||||
import { remove } from "fs-extra";
|
||||
import { getAppMenu } from "../../menu/menu";
|
||||
import type { MenuRegistration } from "../../menu/menu-registration";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { onLocationChange, handleWindowAction } from "../../ipc/window";
|
||||
import { openFilePickingDialogChannel } from "../../../common/ipc/dialog";
|
||||
import { showOpenDialog } from "../../ipc/dialog";
|
||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../common/ipc/window";
|
||||
|
||||
interface Dependencies {
|
||||
electronMenuItems: IComputedValue<MenuRegistration[]>,
|
||||
@@ -136,21 +140,22 @@ export const initIpcMainHandlers = ({ electronMenuItems, directoryForLensLocalSt
|
||||
}
|
||||
});
|
||||
|
||||
ipcMainHandle(dialogShowOpenDialogHandler, async (event, dialogOpts: Electron.OpenDialogOptions) => {
|
||||
await WindowManager.getInstance().ensureMainWindow();
|
||||
ipcMainHandle(windowActionHandleChannel, (event, action) => handleWindowAction(action));
|
||||
|
||||
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts);
|
||||
});
|
||||
ipcMainOn(windowLocationChangedChannel, () => onLocationChange());
|
||||
|
||||
ipcMainOn(IpcMainWindowEvents.OPEN_CONTEXT_MENU, async (event) => {
|
||||
ipcMainHandle(openFilePickingDialogChannel, (event, opts) => showOpenDialog(opts));
|
||||
|
||||
ipcMainHandle(broadcastMainChannel, (event, channel, ...args) => broadcastMessage(channel, ...args));
|
||||
|
||||
ipcMainOn(windowOpenAppMenuAsContextMenuChannel, async (event) => {
|
||||
const menu = Menu.buildFromTemplate(getAppMenu(WindowManager.getInstance(), electronMenuItems.get()));
|
||||
const options = {
|
||||
|
||||
menu.popup({
|
||||
...BrowserWindow.fromWebContents(event.sender),
|
||||
// Center of the topbar menu icon
|
||||
x: 20,
|
||||
y: 20,
|
||||
} as Electron.PopupOptions;
|
||||
|
||||
menu.popup(options);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { BrowserWindow, dialog, OpenDialogOptions } from "electron";
|
||||
|
||||
export async function showOpenDialog(dialogOptions: OpenDialogOptions): Promise<{ canceled: boolean; filePaths: string[]; }> {
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOptions);
|
||||
|
||||
return { canceled, filePaths };
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { BrowserWindow, webContents } from "electron";
|
||||
import { broadcastMessage } from "../../common/ipc";
|
||||
import { WindowAction } from "../../common/ipc/window";
|
||||
|
||||
export function handleWindowAction(action: WindowAction) {
|
||||
const window = BrowserWindow.getFocusedWindow();
|
||||
|
||||
if (!window) return;
|
||||
|
||||
switch (action) {
|
||||
case WindowAction.GO_BACK: {
|
||||
window.webContents.goBack();
|
||||
break;
|
||||
}
|
||||
|
||||
case WindowAction.GO_FORWARD: {
|
||||
window.webContents.goForward();
|
||||
break;
|
||||
}
|
||||
|
||||
case WindowAction.MINIMIZE: {
|
||||
window.minimize();
|
||||
break;
|
||||
}
|
||||
|
||||
case WindowAction.TOGGLE_MAXIMIZE: {
|
||||
if (window.isMaximized()) {
|
||||
window.unmaximize();
|
||||
} else {
|
||||
window.maximize();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WindowAction.CLOSE: {
|
||||
window.close();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`Attemped window action ${action} is unknown`);
|
||||
}
|
||||
}
|
||||
|
||||
export function onLocationChange(): void {
|
||||
const getAllWebContents = webContents.getAllWebContents();
|
||||
|
||||
const canGoBack = getAllWebContents.some((webContent) => {
|
||||
if (webContent.getType() === "window") {
|
||||
return webContent.canGoBack();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
const canGoForward = getAllWebContents.some((webContent) => {
|
||||
if (webContent.getType() === "window") {
|
||||
return webContent.canGoForward();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
broadcastMessage("history:can-go-back", canGoBack);
|
||||
broadcastMessage("history:can-go-forward", canGoForward);
|
||||
}
|
||||
@@ -8,17 +8,14 @@ import { makeObservable, observable } from "mobx";
|
||||
import { app, BrowserWindow, dialog, ipcMain, shell, webContents } from "electron";
|
||||
import windowStateKeeper from "electron-window-state";
|
||||
import { appEventBus } from "../common/app-event-bus/event-bus";
|
||||
import { BundledExtensionsLoaded, ipcMainOn } from "../common/ipc";
|
||||
import { ipcMainOn } from "../common/ipc";
|
||||
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 { isMac, productName } from "../common/vars";
|
||||
import { LensProxy } from "./lens-proxy";
|
||||
|
||||
export const enum IpcMainWindowEvents {
|
||||
OPEN_CONTEXT_MENU = "window:open-context-menu",
|
||||
}
|
||||
import { bundledExtensionsLoaded } from "../common/ipc/extension-handling";
|
||||
|
||||
function isHideable(window: BrowserWindow | null): boolean {
|
||||
return Boolean(window && !window.isDestroyed());
|
||||
@@ -75,9 +72,9 @@ export class WindowManager extends Singleton {
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
nodeIntegrationInSubFrames: true,
|
||||
enableRemoteModule: true,
|
||||
webviewTag: true,
|
||||
contextIsolation: false,
|
||||
nativeWindowOpen: true,
|
||||
},
|
||||
});
|
||||
this.windowState.manage(this.mainWindow);
|
||||
@@ -135,7 +132,8 @@ export class WindowManager extends Singleton {
|
||||
|
||||
// Always disable Node.js integration for all webviews
|
||||
webPreferences.nodeIntegration = false;
|
||||
}).setWindowOpenHandler((details) => {
|
||||
})
|
||||
.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url);
|
||||
|
||||
return { action: "deny" };
|
||||
@@ -165,7 +163,7 @@ export class WindowManager extends Singleton {
|
||||
|
||||
if (!this.mainWindow) {
|
||||
viewHasLoaded = new Promise<void>(resolve => {
|
||||
ipcMain.once(BundledExtensionsLoaded, () => resolve());
|
||||
ipcMain.once(bundledExtensionsLoaded, () => resolve());
|
||||
});
|
||||
await this.initMainWindow(showSplash);
|
||||
}
|
||||
@@ -249,9 +247,9 @@ export class WindowManager extends Singleton {
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
contextIsolation: false,
|
||||
nodeIntegrationInSubFrames: true,
|
||||
nativeWindowOpen: true,
|
||||
},
|
||||
});
|
||||
await this.splashWindow.loadURL("static://splash.html");
|
||||
|
||||
Reference in new issue
Block a user