mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix issues with cluster state sync after renderer reload
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
7d805d81a1
commit
ba117e282e
@ -11,7 +11,7 @@ import { appEventBus } from "./event-bus";
|
||||
import { dumpConfigYaml } from "./kube-helpers";
|
||||
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
||||
import { KubeConfig } from "@kubernetes/client-node";
|
||||
import { subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
|
||||
import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
|
||||
import _ from "lodash";
|
||||
import move from "array-move";
|
||||
import type { WorkspaceId } from "./workspace-store";
|
||||
@ -89,6 +89,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
@observable removedClusters = observable.map<ClusterId, Cluster>();
|
||||
@observable clusters = observable.map<ClusterId, Cluster>();
|
||||
|
||||
private stateRequestChannel = "cluster:states";
|
||||
|
||||
private constructor() {
|
||||
super({
|
||||
configName: "lens-cluster-store",
|
||||
@ -102,8 +104,40 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
this.pushStateToViewsAutomatically();
|
||||
}
|
||||
|
||||
async load() {
|
||||
await super.load();
|
||||
type clusterStateSync = {
|
||||
id: string;
|
||||
state: ClusterState;
|
||||
};
|
||||
if (ipcRenderer) {
|
||||
logger.info("[CLUSTER-STORE] requesting initial state sync");
|
||||
const clusterStates: clusterStateSync[] = await requestMain(this.stateRequestChannel);
|
||||
clusterStates.forEach((clusterState) => {
|
||||
const cluster = this.getById(clusterState.id);
|
||||
if (cluster) {
|
||||
cluster.setState(clusterState.state);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handleRequest(this.stateRequestChannel, (): clusterStateSync[] => {
|
||||
const states: clusterStateSync[] = [];
|
||||
this.clustersList.forEach((cluster) => {
|
||||
states.push({
|
||||
state: cluster.getState(),
|
||||
id: cluster.id
|
||||
});
|
||||
});
|
||||
return states;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected pushStateToViewsAutomatically() {
|
||||
if (!ipcRenderer) {
|
||||
reaction(() => this.enabledClustersList, () => {
|
||||
this.pushState();
|
||||
});
|
||||
reaction(() => this.connectedClustersList, () => {
|
||||
this.pushState();
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user