mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
clean up
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
7cf7756d27
commit
fbaaf6e906
@ -6,7 +6,7 @@ import { action, observable, reaction, runInAction, toJS, when } from "mobx";
|
||||
import Singleton from "./utils/singleton";
|
||||
import { getAppVersion } from "./utils/app-version";
|
||||
import logger from "../main/logger";
|
||||
import { broadcastIpc } from "./ipc";
|
||||
import { broadcastIpc, IpcBroadcastParams } from "./ipc";
|
||||
import isEqual from "lodash/isEqual";
|
||||
|
||||
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||
@ -63,7 +63,7 @@ export class BaseStore<T = any> extends Singleton {
|
||||
this.isLoaded = true;
|
||||
}
|
||||
|
||||
protected async save(model: T) {
|
||||
protected async saveToFile(model: T) {
|
||||
logger.info(`[STORE]: SAVING ${this.name}`);
|
||||
// todo: update when fixed https://github.com/sindresorhus/conf/issues/114
|
||||
Object.entries(model).forEach(([key, value]) => {
|
||||
@ -115,9 +115,8 @@ export class BaseStore<T = any> extends Singleton {
|
||||
|
||||
protected async onModelChange(model: T) {
|
||||
if (ipcMain) {
|
||||
this.save(model); // save config file
|
||||
broadcastIpc({ channel: this.syncChannel, args: [model] }); // send to all windows (BrowserWindow, webContents)
|
||||
this.syncInSubFrames(model); // send to all sub-frames (cluster-view is managed inside iframe)
|
||||
this.saveToFile(model); // save config file
|
||||
this.syncToWebViews(model); // send update to renderer views
|
||||
}
|
||||
// send "update-request" to main-process
|
||||
if (ipcRenderer) {
|
||||
@ -125,7 +124,20 @@ export class BaseStore<T = any> extends Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
protected async syncInSubFrames(model: T) {
|
||||
protected async syncToWebViews(model: T) {
|
||||
const msg: IpcBroadcastParams = {
|
||||
channel: this.syncChannel,
|
||||
args: [model],
|
||||
}
|
||||
broadcastIpc(msg); // send to all windows (BrowserWindow, webContents)
|
||||
const frames = await this.getSubFrames();
|
||||
frames.forEach(frameId => {
|
||||
broadcastIpc({ frameId, ...msg }); // send to all sub-frames (e.g. cluster-view managed in iframe)
|
||||
});
|
||||
}
|
||||
|
||||
// todo: refactor?
|
||||
protected async getSubFrames(): Promise<number[]> {
|
||||
const subFrames: number[] = [];
|
||||
const { clusterStore } = await import("./cluster-store");
|
||||
clusterStore.clustersList.forEach(cluster => {
|
||||
@ -133,13 +145,7 @@ export class BaseStore<T = any> extends Singleton {
|
||||
subFrames.push(cluster.frameId)
|
||||
}
|
||||
});
|
||||
subFrames.forEach(frameId => {
|
||||
broadcastIpc({
|
||||
channel: this.syncChannel,
|
||||
frameId: frameId,
|
||||
args: [model],
|
||||
})
|
||||
})
|
||||
return subFrames;
|
||||
}
|
||||
|
||||
@action
|
||||
|
||||
Loading…
Reference in New Issue
Block a user