mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
auto-update clusters state in renderer stores
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
dec9d92032
commit
ab61fd6308
@ -2,7 +2,7 @@ import path from "path"
|
|||||||
import Config from "conf"
|
import Config from "conf"
|
||||||
import { Options as ConfOptions } from "conf/dist/source/types"
|
import { Options as ConfOptions } from "conf/dist/source/types"
|
||||||
import { app, ipcMain, ipcRenderer, remote } from "electron"
|
import { app, ipcMain, ipcRenderer, remote } from "electron"
|
||||||
import { action, observable, reaction, toJS, when } from "mobx";
|
import { action, observable, reaction, runInAction, toJS, 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";
|
||||||
@ -101,6 +101,14 @@ export class BaseStore<T = any> extends Singleton {
|
|||||||
this.syncDisposers.length = 0;
|
this.syncDisposers.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected applyWithoutSync(callback: () => void) {
|
||||||
|
this.disableSync();
|
||||||
|
runInAction(callback);
|
||||||
|
if (this.params.syncEnabled) {
|
||||||
|
this.enableSync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected onSync(model: T) {
|
protected onSync(model: T) {
|
||||||
if (!isEqual(this.toJSON(), model)) {
|
if (!isEqual(this.toJSON(), model)) {
|
||||||
this.fromStore(model);
|
this.fromStore(model);
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
import { ipcRenderer } from "electron";
|
||||||
import type { WorkspaceId } from "./workspace-store";
|
import type { WorkspaceId } from "./workspace-store";
|
||||||
import { action, computed, observable, toJS } from "mobx";
|
import { action, computed, observable, toJS } from "mobx";
|
||||||
import { v4 as uuid } from "uuid"
|
import { v4 as uuid } from "uuid"
|
||||||
import { BaseStore } from "./base-store";
|
import { BaseStore } from "./base-store";
|
||||||
import { Cluster } from "../main/cluster";
|
import { Cluster, ClusterState } from "../main/cluster";
|
||||||
import migrations from "../migrations/cluster-store"
|
import migrations from "../migrations/cluster-store"
|
||||||
|
import logger from "../main/logger";
|
||||||
|
|
||||||
export interface ClusterStoreModel {
|
export interface ClusterStoreModel {
|
||||||
activeCluster?: ClusterId; // last opened cluster
|
activeCluster?: ClusterId; // last opened cluster
|
||||||
@ -46,6 +48,15 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
||||||
migrations: migrations,
|
migrations: migrations,
|
||||||
});
|
});
|
||||||
|
if (ipcRenderer) {
|
||||||
|
ipcRenderer.on("cluster:state", (event, clusterState: ClusterState) => {
|
||||||
|
this.applyWithoutSync(() => {
|
||||||
|
logger.info(`[CLUSTER-STORE]: received cluster(${clusterState.id}) update`, clusterState);
|
||||||
|
const cluster = this.getById(clusterState.id);
|
||||||
|
if (cluster) cluster.updateModel(clusterState)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable activeClusterId: ClusterId;
|
@observable activeClusterId: ClusterId;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user