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:
authored and GitHub committed 2022-01-27 10:23:36 -05:00
1 parent 205225f6a4
commit 1cac3ca74c
58 files changed
+545 -418

No files matched your search

@@ -5,12 +5,12 @@
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus, CatalogCategory, CatalogCategorySpec } from "../catalog";
import { clusterActivateHandler, clusterDisconnectHandler } from "../cluster-ipc";
import { ClusterStore } from "../cluster-store/cluster-store";
import { broadcastMessage, requestMain } from "../ipc";
import { broadcastMessage } from "../ipc";
import { app } from "electron";
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
import { requestClusterActivation, requestClusterDisconnection } from "../../renderer/ipc";
export interface KubernetesClusterPrometheusMetrics {
address?: {
@@ -69,7 +69,7 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
if (app) {
await ClusterStore.getInstance().getById(this.metadata.uid)?.activate();
} else {
await requestMain(clusterActivateHandler, this.metadata.uid, false);
await requestClusterActivation(this.metadata.uid, false);
}
}
@@ -77,7 +77,7 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
if (app) {
ClusterStore.getInstance().getById(this.metadata.uid)?.disconnect();
} else {
await requestMain(clusterDisconnectHandler, this.metadata.uid, false);
await requestClusterDisconnection(this.metadata.uid, false);
}
}
@@ -111,7 +111,7 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
context.menuItems.push({
title: "Disconnect",
icon: "link_off",
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid),
onClick: () => requestClusterDisconnection(this.metadata.uid),
});
break;
case LensKubernetesClusterStatus.DISCONNECTED:
+9 -9
View File
@@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { ipcMain, ipcRenderer, webFrame } from "electron";
import { action, comparer, computed, makeObservable, observable, reaction } from "mobx";
@@ -11,16 +11,16 @@ import { Cluster } from "../cluster/cluster";
import migrations from "../../migrations/cluster-store";
import logger from "../../main/logger";
import { appEventBus } from "../app-event-bus/event-bus";
import { ipcMainHandle, requestMain } from "../ipc";
import { ipcMainHandle } from "../ipc";
import { disposer, toJS } from "../utils";
import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types";
import { requestInitialClusterStates } from "../../renderer/ipc";
import { clusterStates } from "../ipc/cluster";
export interface ClusterStoreModel {
clusters?: ClusterModel[];
}
const initialStates = "cluster:states";
interface Dependencies {
createCluster: (model: ClusterModel) => Cluster
}
@@ -49,18 +49,18 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
async loadInitialOnRenderer() {
logger.info("[CLUSTER-STORE] requesting initial state sync");
for (const { id, state } of await requestMain(initialStates)) {
for (const { id, state } of await requestInitialClusterStates()) {
this.getById(id)?.setState(state);
}
}
provideInitialFromMain() {
ipcMainHandle(initialStates, () => {
return this.clustersList.map(cluster => ({
ipcMainHandle(clusterStates, () => (
this.clustersList.map(cluster => ({
id: cluster.id,
state: cluster.getState(),
}));
});
}))
));
}
protected pushStateToViewsAutomatically() {
+3 -2
View File
@@ -5,7 +5,7 @@
import { ipcMain } from "electron";
import { action, comparer, computed, makeObservable, observable, reaction, when } from "mobx";
import { broadcastMessage, ClusterListNamespaceForbiddenChannel } from "../ipc";
import { broadcastMessage } from "../ipc";
import type { ContextHandler } from "../../main/context-handler/context-handler";
import { AuthorizationV1Api, CoreV1Api, HttpError, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
import type { Kubectl } from "../../main/kubectl/kubectl";
@@ -20,6 +20,7 @@ import type { ClusterState, ClusterRefreshOptions, ClusterMetricsResourceType, C
import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus } from "../cluster-types";
import { disposer, toJS } from "../utils";
import type { Response } from "request";
import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster";
interface Dependencies {
directoryForKubeConfigs: string,
@@ -641,7 +642,7 @@ export class Cluster implements ClusterModel, ClusterState {
const { response } = error as HttpError & { response: Response };
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body });
broadcastMessage(ClusterListNamespaceForbiddenChannel, this.id);
broadcastMessage(clusterListNamespaceForbiddenChannel, this.id);
}
return namespaceList;
+3 -2
View File
@@ -10,8 +10,9 @@ import { toJS } from "./utils";
import { CatalogEntity } from "./catalog";
import { catalogEntity } from "../main/catalog-sources/general";
import logger from "../main/logger";
import { broadcastMessage, HotbarTooManyItems } from "./ipc";
import { broadcastMessage } from "./ipc";
import { defaultHotbarCells, getEmptyHotbar, Hotbar, CreateHotbarData, CreateHotbarOptions } from "./hotbar-types";
import { hotbarTooManyItemsChannel } from "./ipc/hotbar";
export interface HotbarStoreModel {
hotbars: Hotbar[];
@@ -182,7 +183,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
if (emptyCellIndex != -1) {
hotbar.items[emptyCellIndex] = newItem;
} else {
broadcastMessage(HotbarTooManyItems);
broadcastMessage(hotbarTooManyItemsChannel);
}
} else if (0 <= cellIndex && cellIndex < hotbar.items.length) {
hotbar.items[cellIndex] = newItem;
+13 -10
View File
@@ -3,14 +3,17 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export enum CatalogIpcEvents {
/**
* This is broadcast on whenever there is an update to any catalog item
*/
ITEMS = "catalog:items",
/**
* This is used to activate a specific entity in the renderer main frame
*/
export const catalogEntityRunListener = "catalog-entity:run";
/**
* This can be sent from renderer to main to initialize a broadcast of ITEMS
*/
INIT = "catalog:init",
}
/**
* This is broadcast on whenever there is an update to any catalog item
*/
export const catalogItemsChannel = "catalog:items";
/**
* This can be sent from renderer to main to initialize a broadcast of ITEMS
*/
export const catalogInitChannel = "catalog:init";
-16
View File
@@ -1,16 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
/**
* This channel is broadcast on whenever the cluster fails to list namespaces
* during a refresh and no `accessibleNamespaces` have been set.
*/
export const ClusterListNamespaceForbiddenChannel = "cluster:list-namespace-forbidden";
export type ListNamespaceForbiddenArgs = [clusterId: string];
export function isListNamespaceForbiddenArgs(args: unknown[]): args is ListNamespaceForbiddenArgs {
return args.length === 1 && typeof args[0] === "string";
}
@@ -13,3 +13,16 @@ export const clusterSetDeletingHandler = "cluster:deleting:set";
export const clusterClearDeletingHandler = "cluster:deleting:clear";
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
export const clusterStates = "cluster:states";
/**
* This channel is broadcast on whenever the cluster fails to list namespaces
* during a refresh and no `accessibleNamespaces` have been set.
*/
export const clusterListNamespaceForbiddenChannel = "cluster:list-namespace-forbidden";
export type ListNamespaceForbiddenArgs = [clusterId: string];
export function isListNamespaceForbiddenArgs(args: unknown[]): args is ListNamespaceForbiddenArgs {
return args.length === 1 && typeof args[0] === "string";
}
@@ -2,4 +2,5 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const BundledExtensionsLoaded = "extension-loader:bundled-extensions-loaded";
export const openFilePickingDialogChannel = "dialog:open:file-picking";
+9
View File
@@ -0,0 +1,9 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const extensionDiscoveryStateChannel = "extension-discovery:state";
export const bundledExtensionsLoaded = "extension-loader:bundled-extensions-loaded";
export const extensionLoaderFromMainChannel = "extension-loader:main:state";
export const extensionLoaderFromRendererChannel = "extension-loader:renderer:state";
+1 -1
View File
@@ -3,4 +3,4 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const HotbarTooManyItems = "hotbar:too-many-items";
export const hotbarTooManyItemsChannel = "hotbar:too-many-items";
+1 -7
View File
@@ -3,13 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const dialogShowOpenDialogHandler = "dialog:show-open-dialog";
export const catalogEntityRunListener = "catalog-entity:run";
export * from "./ipc";
export * from "./invalid-kubeconfig";
export * from "./update-available.ipc";
export * from "./cluster.ipc";
export * from "./update-available";
export * from "./type-enforced-ipc";
export * from "./hotbar";
export * from "./extension-loader.ipc";
+41 -58
View File
@@ -12,25 +12,8 @@ import { toJS } from "../utils/toJS";
import logger from "../../main/logger";
import { ClusterFrameInfo, clusterFrameMap } from "../cluster-frames";
import type { Disposer } from "../utils";
import type remote from "@electron/remote";
const electronRemote = (() => {
if (ipcRenderer) {
try {
return require("@electron/remote");
} catch {
// ignore temp
}
}
return null;
})();
const subFramesChannel = "ipc:get-sub-frames";
export async function requestMain(channel: string, ...args: any[]) {
return ipcRenderer.invoke(channel, ...args.map(sanitizePayload));
}
export const broadcastMainChannel = "ipc:broadcast-main";
export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) {
ipcMain.handle(channel, async (event, ...args) => {
@@ -42,51 +25,55 @@ function getSubFrames(): ClusterFrameInfo[] {
return Array.from(clusterFrameMap.values());
}
export function broadcastMessage(channel: string, ...args: any[]) {
const subFramesP = ipcRenderer
? requestMain(subFramesChannel)
: Promise.resolve(getSubFrames());
export async function broadcastMessage(channel: string, ...args: any[]): Promise<void> {
if (ipcRenderer) {
return ipcRenderer.invoke(broadcastMainChannel, channel, ...args.map(sanitizePayload));
}
subFramesP
.then(subFrames => {
const views: undefined | ReturnType<typeof webContents.getAllWebContents> | ReturnType<typeof remote.webContents.getAllWebContents> = (webContents || electronRemote?.webContents)?.getAllWebContents();
if (!webContents) {
return;
}
if (!views || !Array.isArray(views) || views.length === 0) return;
args = args.map(sanitizePayload);
ipcMain.listeners(channel).forEach((func) => func({
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
}, ...args));
ipcRenderer?.send(channel, ...args);
ipcMain?.emit(channel, ...args);
const subFrames = getSubFrames();
const views = webContents.getAllWebContents();
for (const view of views) {
let viewType = "unknown";
if (!views || !Array.isArray(views) || views.length === 0) return;
// There will be a uncaught exception if the view is destroyed.
try {
viewType = view.getType();
} catch {
// We can ignore the view destroyed exception as viewType is only used for logging.
}
args = args.map(sanitizePayload);
// Send message to views.
try {
logger.silly(`[IPC]: broadcasting "${channel}" to ${viewType}=${view.id}`, { args });
view.send(channel, ...args);
} catch (error) {
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"`, { error: String(error) });
}
for (const view of views) {
let viewType = "unknown";
// Send message to subFrames of views.
for (const frameInfo of subFrames) {
logger.silly(`[IPC]: broadcasting "${channel}" to subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { args });
// There will be a uncaught exception if the view is destroyed.
try {
viewType = view.getType();
} catch {
// We can ignore the view destroyed exception as viewType is only used for logging.
}
try {
view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
} catch (error) {
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"'s subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { error: String(error) });
}
}
// Send message to views.
try {
logger.silly(`[IPC]: broadcasting "${channel}" to ${viewType}=${view.id}`, { args });
view.send(channel, ...args);
} catch (error) {
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"`, { error });
}
// Send message to subFrames of views.
for (const frameInfo of subFrames) {
logger.silly(`[IPC]: broadcasting "${channel}" to subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { args });
try {
view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
} catch (error) {
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"'s subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { error: String(error) });
}
});
}
}
}
export function ipcMainOn(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): Disposer {
@@ -101,10 +88,6 @@ export function ipcRendererOn(channel: string, listener: (event: Electron.IpcRen
return () => ipcRenderer.off(channel, listener);
}
export function bindBroadcastHandlers() {
ipcMainHandle(subFramesChannel, () => getSubFrames());
}
/**
* Sanitizing data for IPC-messaging before send.
* Removes possible observable values to avoid exceptions like "can't clone object".
File renamed without changes.
+39
View File
@@ -0,0 +1,39 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export const windowActionHandleChannel = "window:window-action";
export const windowOpenAppMenuAsContextMenuChannel = "window:open-app-context-menu";
export const windowLocationChangedChannel = "window:location-changed";
/**
* The supported actions on the current window. The argument for `windowActionHandleChannel`
*/
export enum WindowAction {
/**
* Request that the current window goes back one step of browser history
*/
GO_BACK = "back",
/**
* Request that the current window goes forward one step of browser history
*/
GO_FORWARD = "forward",
/**
* Request that the current window is minimized
*/
MINIMIZE = "minimize",
/**
* Request that the current window is maximized if it isn't, or unmaximized
* if it is
*/
TOGGLE_MAXIMIZE = "toggle-maximize",
/**
* Request that the current window is closed
*/
CLOSE = "close",
}
+5 -6
View File
@@ -9,11 +9,10 @@ import { ResourceApplier } from "../../main/resource-applier";
import type { KubernetesCluster } from "../catalog-entities";
import logger from "../../main/logger";
import { app } from "electron";
import { requestMain } from "../ipc";
import { clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler } from "../cluster-ipc";
import { ClusterStore } from "../cluster-store/cluster-store";
import yaml from "js-yaml";
import { productName } from "../vars";
import { requestKubectlApplyAll, requestKubectlDeleteAll } from "../../renderer/ipc";
export class ResourceStack {
constructor(protected cluster: KubernetesCluster, protected name: string) {}
@@ -41,7 +40,7 @@ export class ResourceStack {
}
protected async applyResources(resources: string[], extraArgs?: string[]): Promise<string> {
const clusterModel = ClusterStore.getInstance().getById(this.cluster.metadata.uid);
const clusterModel = ClusterStore.getInstance().getById(this.cluster.getId());
if (!clusterModel) {
throw new Error(`cluster not found`);
@@ -54,7 +53,7 @@ export class ResourceStack {
if (app) {
return await new ResourceApplier(clusterModel).kubectlApplyAll(resources, kubectlArgs);
} else {
const response = await requestMain(clusterKubectlApplyAllHandler, this.cluster.metadata.uid, resources, kubectlArgs);
const response = await requestKubectlApplyAll(this.cluster.getId(), resources, kubectlArgs);
if (response.stderr) {
throw new Error(response.stderr);
@@ -65,7 +64,7 @@ export class ResourceStack {
}
protected async deleteResources(resources: string[], extraArgs?: string[]): Promise<string> {
const clusterModel = ClusterStore.getInstance().getById(this.cluster.metadata.uid);
const clusterModel = ClusterStore.getInstance().getById(this.cluster.getId());
if (!clusterModel) {
throw new Error(`cluster not found`);
@@ -78,7 +77,7 @@ export class ResourceStack {
if (app) {
return await new ResourceApplier(clusterModel).kubectlDeleteAll(resources, kubectlArgs);
} else {
const response = await requestMain(clusterKubectlDeleteAllHandler, this.cluster.metadata.uid, resources, kubectlArgs);
const response = await requestKubectlDeleteAll(this.cluster.getId(), resources, kubectlArgs);
if (response.stderr) {
throw new Error(response.stderr);