mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix Catalog being empty after subsequent opens
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
22da7a9757
commit
dbf130d920
@ -27,7 +27,7 @@ import { IReactionOptions, observable, reaction, runInAction, when } from "mobx"
|
|||||||
import Singleton from "./utils/singleton";
|
import Singleton from "./utils/singleton";
|
||||||
import { getAppVersion } from "./utils/app-version";
|
import { getAppVersion } from "./utils/app-version";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
import { broadcastMessage, subscribeToBroadcast } from "./ipc";
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
|
|
||||||
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||||
@ -123,8 +123,7 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
this.onSync(model);
|
this.onSync(model);
|
||||||
};
|
};
|
||||||
|
|
||||||
subscribeToBroadcast(this.syncMainChannel, callback);
|
this.syncDisposers.push(subscribeToBroadcast(this.syncMainChannel, callback));
|
||||||
this.syncDisposers.push(() => unsubscribeFromBroadcast(this.syncMainChannel, callback));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
@ -133,8 +132,7 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
this.onSyncFromMain(model);
|
this.onSyncFromMain(model);
|
||||||
};
|
};
|
||||||
|
|
||||||
subscribeToBroadcast(this.syncRendererChannel, callback);
|
this.syncDisposers.push(subscribeToBroadcast(this.syncRendererChannel, callback));
|
||||||
this.syncDisposers.push(() => unsubscribeFromBroadcast(this.syncRendererChannel, callback));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,9 +21,9 @@
|
|||||||
|
|
||||||
import { action, computed, observable, IComputedValue, IObservableArray } from "mobx";
|
import { action, computed, observable, IComputedValue, IObservableArray } from "mobx";
|
||||||
import type { CatalogEntity } from "./catalog-entity";
|
import type { CatalogEntity } from "./catalog-entity";
|
||||||
import { iter } from "../utils";
|
import { iter, Singleton } from "../utils";
|
||||||
|
|
||||||
export class CatalogEntityRegistry {
|
export class CatalogEntityRegistry extends Singleton {
|
||||||
protected sources = observable.map<string, IComputedValue<CatalogEntity[]>>([], { deep: true });
|
protected sources = observable.map<string, IComputedValue<CatalogEntity[]>>([], { deep: true });
|
||||||
|
|
||||||
@action addObservableSource(id: string, source: IObservableArray<CatalogEntity>) {
|
@action addObservableSource(id: string, source: IObservableArray<CatalogEntity>) {
|
||||||
@ -48,5 +48,3 @@ export class CatalogEntityRegistry {
|
|||||||
return items as T[];
|
return items as T[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const catalogEntityRegistry = new CatalogEntityRegistry();
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { handleRequest } from "./ipc";
|
|
||||||
import { ClusterId, ClusterStore } from "./cluster-store";
|
import { ClusterId, ClusterStore } from "./cluster-store";
|
||||||
import { appEventBus } from "./event-bus";
|
import { appEventBus } from "./event-bus";
|
||||||
import { ResourceApplier } from "../main/resource-applier";
|
import { ResourceApplier } from "../main/resource-applier";
|
||||||
@ -33,13 +32,13 @@ export const clusterDisconnectHandler = "cluster:disconnect";
|
|||||||
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
||||||
|
|
||||||
if (ipcMain) {
|
if (ipcMain) {
|
||||||
handleRequest(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
ipcMain.handle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
||||||
return ClusterStore.getInstance()
|
return ClusterStore.getInstance()
|
||||||
.getById(clusterId)
|
.getById(clusterId)
|
||||||
?.activate(force);
|
?.activate(force);
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
ipcMain.handle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
if (cluster) {
|
if (cluster) {
|
||||||
@ -48,13 +47,13 @@ if (ipcMain) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterRefreshHandler, (event, clusterId: ClusterId) => {
|
ipcMain.handle(clusterRefreshHandler, (event, clusterId: ClusterId) => {
|
||||||
return ClusterStore.getInstance()
|
return ClusterStore.getInstance()
|
||||||
.getById(clusterId)
|
.getById(clusterId)
|
||||||
?.refresh({ refreshMetadata: true });
|
?.refresh({ refreshMetadata: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
ipcMain.handle(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
||||||
appEventBus.emit({name: "cluster", action: "stop"});
|
appEventBus.emit({name: "cluster", action: "stop"});
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ if (ipcMain) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
|
ipcMain.handle(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
|
||||||
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"});
|
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"});
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import { appEventBus } from "./event-bus";
|
|||||||
import { dumpConfigYaml } from "./kube-helpers";
|
import { dumpConfigYaml } from "./kube-helpers";
|
||||||
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
||||||
import type { KubeConfig } from "@kubernetes/client-node";
|
import type { KubeConfig } from "@kubernetes/client-node";
|
||||||
import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
|
import { requestMain, subscribeToBroadcast } from "./ipc";
|
||||||
import type { ResourceType } from "../renderer/components/cluster-settings/components/cluster-metrics-setting";
|
import type { ResourceType } from "../renderer/components/cluster-settings/components/cluster-metrics-setting";
|
||||||
import { disposer, noop } from "./utils";
|
import { disposer, noop } from "./utils";
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (ipcMain) {
|
} else if (ipcMain) {
|
||||||
handleRequest(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
ipcMain.handle(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
||||||
const states: clusterStateSync[] = [];
|
const states: clusterStateSync[] = [];
|
||||||
|
|
||||||
this.clustersList.forEach((cluster) => {
|
this.clustersList.forEach((cluster) => {
|
||||||
@ -191,7 +191,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
reaction(() => this.connectedClustersList, () => {
|
reaction(() => this.connectedClustersList, () => {
|
||||||
this.pushState();
|
this.pushState();
|
||||||
}),
|
}),
|
||||||
() => unsubscribeAllFromBroadcast("cluster:state"),
|
() => ipcMain.removeAllListeners("cluster:state"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,13 +27,10 @@ import { ipcMain, ipcRenderer, webContents, remote } from "electron";
|
|||||||
import { toJS } from "mobx";
|
import { toJS } from "mobx";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
import { ClusterFrameInfo, clusterFrameMap } from "../cluster-frames";
|
import { ClusterFrameInfo, clusterFrameMap } from "../cluster-frames";
|
||||||
|
import type { Disposer } from "../utils";
|
||||||
|
|
||||||
const subFramesChannel = "ipc:get-sub-frames";
|
const subFramesChannel = "ipc:get-sub-frames";
|
||||||
|
|
||||||
export function handleRequest(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) {
|
|
||||||
ipcMain.handle(channel, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function requestMain(channel: string, ...args: any[]) {
|
export async function requestMain(channel: string, ...args: any[]) {
|
||||||
return ipcRenderer.invoke(channel, ...args);
|
return ipcRenderer.invoke(channel, ...args);
|
||||||
}
|
}
|
||||||
@ -73,34 +70,14 @@ export async function broadcastMessage(channel: string, ...args: any[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function subscribeToBroadcast(channel: string, listener: (...args: any[]) => any) {
|
export function subscribeToBroadcast(channel: string, listener: (...args: any[]) => any): Disposer {
|
||||||
if (ipcRenderer) {
|
const source: NodeJS.EventEmitter = ipcRenderer ?? ipcMain;
|
||||||
ipcRenderer.on(channel, listener);
|
|
||||||
} else if (ipcMain) {
|
|
||||||
ipcMain.on(channel, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
return listener;
|
source?.on(channel, listener);
|
||||||
}
|
|
||||||
|
|
||||||
export function unsubscribeFromBroadcast(channel: string, listener: (...args: any[]) => any) {
|
return () => source?.off(channel, listener);
|
||||||
if (ipcRenderer) {
|
|
||||||
ipcRenderer.off(channel, listener);
|
|
||||||
} else if (ipcMain) {
|
|
||||||
ipcMain.off(channel, listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function unsubscribeAllFromBroadcast(channel: string) {
|
|
||||||
if (ipcRenderer) {
|
|
||||||
ipcRenderer.removeAllListeners(channel);
|
|
||||||
} else if (ipcMain) {
|
|
||||||
ipcMain.removeAllListeners(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bindBroadcastHandlers() {
|
export function bindBroadcastHandlers() {
|
||||||
handleRequest(subFramesChannel, () => {
|
ipcMain.handle(subFramesChannel, getSubFrames);
|
||||||
return getSubFrames();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,15 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { CatalogEntity, catalogEntityRegistry as registry } from "../../common/catalog";
|
import { CatalogEntity, CatalogEntityRegistry as InternalRegistry } from "../../common/catalog";
|
||||||
|
|
||||||
export { catalogCategoryRegistry as catalogCategories } from "../../common/catalog/catalog-category-registry";
|
export { catalogCategoryRegistry as catalogCategories } from "../../common/catalog/catalog-category-registry";
|
||||||
export * from "../../common/catalog-entities";
|
export * from "../../common/catalog-entities";
|
||||||
|
|
||||||
export class CatalogEntityRegistry {
|
export class CatalogEntityRegistry {
|
||||||
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
static getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
||||||
return registry.getItemsForApiKind<T>(apiVersion, kind);
|
return InternalRegistry.getInstance().getItemsForApiKind<T>(apiVersion, kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const catalogEntities = new CatalogEntityRegistry();
|
|
||||||
|
|||||||
@ -20,13 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { watch } from "chokidar";
|
import { watch } from "chokidar";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcMain, ipcRenderer } from "electron";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { observable, reaction, toJS, when } from "mobx";
|
import { observable, reaction, toJS, when } from "mobx";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
|
import { broadcastMessage, requestMain, subscribeToBroadcast } from "../common/ipc";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { ExtensionInstallationStateStore } from "../renderer/components/+extensions/extension-install.store";
|
import { ExtensionInstallationStateStore } from "../renderer/components/+extensions/extension-install.store";
|
||||||
@ -136,7 +136,7 @@ export class ExtensionDiscovery extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initMain() {
|
async initMain() {
|
||||||
handleRequest(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
|
ipcMain.handle(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
|
||||||
|
|
||||||
reaction(() => this.toJSON(), () => {
|
reaction(() => this.toJSON(), () => {
|
||||||
this.broadcast();
|
this.broadcast();
|
||||||
|
|||||||
@ -19,13 +19,13 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { app, ipcRenderer, remote } from "electron";
|
import { app, ipcMain, ipcRenderer, remote } from "electron";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { action, computed, observable, reaction, toJS, when } from "mobx";
|
import { action, computed, observable, reaction, toJS, when } from "mobx";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { getHostedCluster } from "../common/cluster-store";
|
import { getHostedCluster } from "../common/cluster-store";
|
||||||
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } from "../common/ipc";
|
import { broadcastMessage, requestMain, subscribeToBroadcast } from "../common/ipc";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import type { InstalledExtension } from "./extension-discovery";
|
import type { InstalledExtension } from "./extension-discovery";
|
||||||
@ -164,7 +164,7 @@ export class ExtensionLoader extends Singleton {
|
|||||||
this.broadcastExtensions();
|
this.broadcastExtensions();
|
||||||
});
|
});
|
||||||
|
|
||||||
handleRequest(ExtensionLoader.extensionsMainChannel, () => {
|
ipcMain.handle(ExtensionLoader.extensionsMainChannel, () => {
|
||||||
return Array.from(this.toJSON());
|
return Array.from(this.toJSON());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import type { MenuRegistration } from "./registries/menu-registry";
|
|||||||
import { LensExtension } from "./lens-extension";
|
import { LensExtension } from "./lens-extension";
|
||||||
import { WindowManager } from "../main/window-manager";
|
import { WindowManager } from "../main/window-manager";
|
||||||
import { getExtensionPageUrl } from "./registries/page-registry";
|
import { getExtensionPageUrl } from "./registries/page-registry";
|
||||||
import { CatalogEntity, catalogEntityRegistry } from "../common/catalog";
|
import { CatalogEntity, CatalogEntityRegistry } from "../common/catalog";
|
||||||
import type { IObservableArray } from "mobx";
|
import type { IObservableArray } from "mobx";
|
||||||
|
|
||||||
export class LensMainExtension extends LensExtension {
|
export class LensMainExtension extends LensExtension {
|
||||||
@ -41,10 +41,10 @@ export class LensMainExtension extends LensExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addCatalogSource(id: string, source: IObservableArray<CatalogEntity>) {
|
addCatalogSource(id: string, source: IObservableArray<CatalogEntity>) {
|
||||||
catalogEntityRegistry.addObservableSource(`${this.name}:${id}`, source);
|
CatalogEntityRegistry.getInstance().addObservableSource(`${this.name}:${id}`, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeCatalogSource(id: string) {
|
removeCatalogSource(id: string) {
|
||||||
catalogEntityRegistry.removeSource(`${this.name}:${id}`);
|
CatalogEntityRegistry.getInstance().removeSource(`${this.name}:${id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,33 +20,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { reaction, toJS } from "mobx";
|
import { reaction, toJS } from "mobx";
|
||||||
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "../common/ipc";
|
import { broadcastMessage, subscribeToBroadcast } from "../common/ipc";
|
||||||
import type { CatalogEntityRegistry} from "../common/catalog";
|
import { CatalogEntityRegistry} from "../common/catalog";
|
||||||
import "../common/catalog-entities/kubernetes-cluster";
|
import { disposer, Disposer } from "../common/utils";
|
||||||
import type { Disposer } from "../common/utils";
|
|
||||||
|
|
||||||
export class CatalogPusher {
|
export function pushCatalogToRenderer(): Disposer {
|
||||||
static init(catalog: CatalogEntityRegistry) {
|
return disposer(
|
||||||
new CatalogPusher(catalog).init();
|
reaction(() => toJS(CatalogEntityRegistry.getInstance().items, { recurseEverything: true }), (items) => {
|
||||||
}
|
|
||||||
|
|
||||||
private constructor(private catalog: CatalogEntityRegistry) {}
|
|
||||||
|
|
||||||
init() {
|
|
||||||
const disposers: Disposer[] = [];
|
|
||||||
|
|
||||||
disposers.push(reaction(() => toJS(this.catalog.items, { recurseEverything: true }), (items) => {
|
|
||||||
broadcastMessage("catalog:items", items);
|
broadcastMessage("catalog:items", items);
|
||||||
}, {
|
}, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
}));
|
}),
|
||||||
|
subscribeToBroadcast("catalog:broadcast", () => {
|
||||||
const listener = subscribeToBroadcast("catalog:broadcast", () => {
|
broadcastMessage("catalog:items", toJS(CatalogEntityRegistry.getInstance().items, { recurseEverything: true }));
|
||||||
broadcastMessage("catalog:items", toJS(this.catalog.items, { recurseEverything: true }));
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
disposers.push(() => unsubscribeFromBroadcast("catalog:broadcast", listener));
|
|
||||||
|
|
||||||
return disposers;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { action, observable, IComputedValue, computed, ObservableMap, runInAction } from "mobx";
|
import { action, observable, IComputedValue, computed, ObservableMap, runInAction } from "mobx";
|
||||||
import { CatalogEntity, catalogEntityRegistry } from "../../common/catalog";
|
import { CatalogEntity, CatalogEntityRegistry } from "../../common/catalog";
|
||||||
import { watch } from "chokidar";
|
import { watch } from "chokidar";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
@ -54,7 +54,7 @@ export class KubeconfigSyncManager extends Singleton {
|
|||||||
|
|
||||||
logger.info(`${logPrefix} starting requested syncs`);
|
logger.info(`${logPrefix} starting requested syncs`);
|
||||||
|
|
||||||
catalogEntityRegistry.addComputedSource(KubeconfigSyncManager.syncName, computed(() => (
|
CatalogEntityRegistry.getInstance().addComputedSource(KubeconfigSyncManager.syncName, computed(() => (
|
||||||
Array.from(iter.flatMap(
|
Array.from(iter.flatMap(
|
||||||
this.sources.values(),
|
this.sources.values(),
|
||||||
([entities]) => entities.get()
|
([entities]) => entities.get()
|
||||||
@ -88,7 +88,7 @@ export class KubeconfigSyncManager extends Singleton {
|
|||||||
this.stopOldSync(filePath);
|
this.stopOldSync(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
catalogEntityRegistry.removeSource(KubeconfigSyncManager.syncName);
|
CatalogEntityRegistry.getInstance().removeSource(KubeconfigSyncManager.syncName);
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import type { Cluster } from "./cluster";
|
|||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
import { apiKubePrefix } from "../common/vars";
|
import { apiKubePrefix } from "../common/vars";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import { catalogEntityRegistry } from "../common/catalog";
|
import { CatalogEntityRegistry } from "../common/catalog";
|
||||||
import { KubernetesCluster } from "../common/catalog-entities/kubernetes-cluster";
|
import { KubernetesCluster } from "../common/catalog-entities/kubernetes-cluster";
|
||||||
|
|
||||||
export class ClusterManager extends Singleton {
|
export class ClusterManager extends Singleton {
|
||||||
@ -39,7 +39,7 @@ export class ClusterManager extends Singleton {
|
|||||||
this.updateCatalog(ClusterStore.getInstance().clustersList);
|
this.updateCatalog(ClusterStore.getInstance().clustersList);
|
||||||
}, { fireImmediately: true });
|
}, { fireImmediately: true });
|
||||||
|
|
||||||
reaction(() => catalogEntityRegistry.getItemsForApiKind<KubernetesCluster>("entity.k8slens.dev/v1alpha1", "KubernetesCluster"), (entities) => {
|
reaction(() => CatalogEntityRegistry.getInstance().getItemsForApiKind<KubernetesCluster>("entity.k8slens.dev/v1alpha1", "KubernetesCluster"), (entities) => {
|
||||||
this.syncClustersFromCatalog(entities);
|
this.syncClustersFromCatalog(entities);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -64,11 +64,13 @@ export class ClusterManager extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action protected updateCatalog(clusters: Cluster[]) {
|
@action protected updateCatalog(clusters: Cluster[]) {
|
||||||
|
const registry = CatalogEntityRegistry.getInstance();
|
||||||
|
|
||||||
for (const cluster of clusters) {
|
for (const cluster of clusters) {
|
||||||
const index = catalogEntityRegistry.items.findIndex((entity) => entity.metadata.uid === cluster.id);
|
const index = registry.items.findIndex((entity) => entity.metadata.uid === cluster.id);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
const entity = catalogEntityRegistry.items[index];
|
const entity = registry.items[index];
|
||||||
|
|
||||||
entity.status.phase = cluster.disconnected ? "disconnected" : "connected";
|
entity.status.phase = cluster.disconnected ? "disconnected" : "connected";
|
||||||
entity.status.active = !cluster.disconnected;
|
entity.status.active = !cluster.disconnected;
|
||||||
@ -76,7 +78,7 @@ export class ClusterManager extends Singleton {
|
|||||||
if (cluster.preferences?.clusterName) {
|
if (cluster.preferences?.clusterName) {
|
||||||
entity.metadata.name = cluster.preferences.clusterName;
|
entity.metadata.name = cluster.preferences.clusterName;
|
||||||
}
|
}
|
||||||
catalogEntityRegistry.items.splice(index, 1, entity);
|
registry.items.splice(index, 1, entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,19 +45,20 @@ import type { LensExtensionId } from "../extensions/lens-extension";
|
|||||||
import { FilesystemProvisionerStore } from "./extension-filesystem";
|
import { FilesystemProvisionerStore } from "./extension-filesystem";
|
||||||
import { installDeveloperTools } from "./developer-tools";
|
import { installDeveloperTools } from "./developer-tools";
|
||||||
import { LensProtocolRouterMain } from "./protocol-handler";
|
import { LensProtocolRouterMain } from "./protocol-handler";
|
||||||
import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
import { disposer, getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
||||||
import { bindBroadcastHandlers } from "../common/ipc";
|
import { bindBroadcastHandlers } from "../common/ipc";
|
||||||
import { startUpdateChecking } from "./app-updater";
|
import { startUpdateChecking } from "./app-updater";
|
||||||
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||||
import { CatalogPusher } from "./catalog-pusher";
|
import { pushCatalogToRenderer } from "./catalog-pusher";
|
||||||
import { catalogEntityRegistry } from "../common/catalog";
|
|
||||||
import { HotbarStore } from "../common/hotbar-store";
|
import { HotbarStore } from "../common/hotbar-store";
|
||||||
import { HelmRepoManager } from "./helm/helm-repo-manager";
|
import { HelmRepoManager } from "./helm/helm-repo-manager";
|
||||||
import { KubeconfigSyncManager } from "./catalog-sources";
|
import { KubeconfigSyncManager } from "./catalog-sources";
|
||||||
import { handleWsUpgrade } from "./proxy/ws-upgrade";
|
import { handleWsUpgrade } from "./proxy/ws-upgrade";
|
||||||
import { initRegistries } from "./initializers";
|
import { initRegistries } from "./initializers";
|
||||||
|
import { CatalogEntityRegistry } from "../common/catalog";
|
||||||
|
|
||||||
const workingDir = path.join(app.getPath("appData"), appName);
|
const workingDir = path.join(app.getPath("appData"), appName);
|
||||||
|
const cleanup = disposer();
|
||||||
|
|
||||||
app.setName(appName);
|
app.setName(appName);
|
||||||
|
|
||||||
@ -110,6 +111,8 @@ app.on("second-instance", (event, argv) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on("ready", async () => {
|
app.on("ready", async () => {
|
||||||
|
CatalogEntityRegistry.createInstance();
|
||||||
|
|
||||||
logger.info(`🚀 Starting ${productName} from "${workingDir}"`);
|
logger.info(`🚀 Starting ${productName} from "${workingDir}"`);
|
||||||
logger.info("🐚 Syncing shell environment");
|
logger.info("🐚 Syncing shell environment");
|
||||||
await shellSync();
|
await shellSync();
|
||||||
@ -143,7 +146,6 @@ app.on("ready", async () => {
|
|||||||
const lensProxy = LensProxy.createInstance(handleWsUpgrade);
|
const lensProxy = LensProxy.createInstance(handleWsUpgrade);
|
||||||
|
|
||||||
ClusterManager.createInstance();
|
ClusterManager.createInstance();
|
||||||
KubeconfigSyncManager.createInstance().startSync();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("🔌 Starting LensProxy");
|
logger.info("🔌 Starting LensProxy");
|
||||||
@ -189,17 +191,14 @@ app.on("ready", async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on(IpcRendererNavigationEvents.LOADED, () => {
|
ipcMain.on(IpcRendererNavigationEvents.LOADED, () => {
|
||||||
CatalogPusher.init(catalogEntityRegistry);
|
KubeconfigSyncManager.createInstance().startSync();
|
||||||
|
cleanup.push(pushCatalogToRenderer());
|
||||||
startUpdateChecking();
|
startUpdateChecking();
|
||||||
LensProtocolRouterMain
|
LensProtocolRouterMain.getInstance().rendererLoaded = true;
|
||||||
.getInstance()
|
|
||||||
.rendererLoaded = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ExtensionLoader.getInstance().whenLoaded.then(() => {
|
ExtensionLoader.getInstance().whenLoaded.then(() => {
|
||||||
LensProtocolRouterMain
|
LensProtocolRouterMain.getInstance().extensionsLoaded = true;
|
||||||
.getInstance()
|
|
||||||
.extensionsLoaded = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info("🧩 Initializing extensions");
|
logger.info("🧩 Initializing extensions");
|
||||||
@ -253,6 +252,7 @@ app.on("will-quit", (event) => {
|
|||||||
appEventBus.emit({name: "app", action: "close"});
|
appEventBus.emit({name: "app", action: "close"});
|
||||||
ClusterManager.getInstance(false)?.stop(); // close cluster connections
|
ClusterManager.getInstance(false)?.stop(); // close cluster connections
|
||||||
KubeconfigSyncManager.getInstance(false)?.stopSync();
|
KubeconfigSyncManager.getInstance(false)?.stopSync();
|
||||||
|
cleanup();
|
||||||
|
|
||||||
if (blockQuit) {
|
if (blockQuit) {
|
||||||
event.preventDefault(); // prevent app's default shutdown (e.g. required for telemetry, etc.)
|
event.preventDefault(); // prevent app's default shutdown (e.g. required for telemetry, etc.)
|
||||||
|
|||||||
@ -44,6 +44,7 @@ import { HelmRepoManager } from "../main/helm/helm-repo-manager";
|
|||||||
import { ExtensionInstallationStateStore } from "./components/+extensions/extension-install.store";
|
import { ExtensionInstallationStateStore } from "./components/+extensions/extension-install.store";
|
||||||
import { DefaultProps } from "./mui-base-theme";
|
import { DefaultProps } from "./mui-base-theme";
|
||||||
import { initCommandRegistry, initEntitySettingsRegistry, initKubeObjectMenuRegistry, initRegistries, initWelcomeMenuRegistry, intiKubeObjectDetailRegistry } from "./initializers";
|
import { initCommandRegistry, initEntitySettingsRegistry, initKubeObjectMenuRegistry, initRegistries, initWelcomeMenuRegistry, intiKubeObjectDetailRegistry } from "./initializers";
|
||||||
|
import { CatalogEntityRegistry } from "../common/catalog";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this is a development buid, wait a second to attach
|
* If this is a development buid, wait a second to attach
|
||||||
@ -75,6 +76,8 @@ export async function bootstrap(App: AppComponent) {
|
|||||||
await attachChromeDebugger();
|
await attachChromeDebugger();
|
||||||
rootElem.classList.toggle("is-mac", isMac);
|
rootElem.classList.toggle("is-mac", isMac);
|
||||||
|
|
||||||
|
CatalogEntityRegistry.createInstance();
|
||||||
|
|
||||||
initRegistries();
|
initRegistries();
|
||||||
initCommandRegistry();
|
initCommandRegistry();
|
||||||
initEntitySettingsRegistry();
|
initEntitySettingsRegistry();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user