1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-11-30 14:03:44 +02:00
parent 3bd484f92a
commit 287147a64d
2 changed files with 21 additions and 17 deletions

View File

@ -7,12 +7,9 @@ jest.mock("electron", () => {
getPath: () => "tmp", getPath: () => "tmp",
getLocale: () => "en" getLocale: () => "en"
}, },
ipcRenderer: {
invoke: jest.fn(),
on: jest.fn()
},
ipcMain: { ipcMain: {
handle: jest.fn() handle: jest.fn(),
on: jest.fn()
} }
}; };
}); });

View File

@ -49,9 +49,9 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
} }
getState(): WorkspaceState { getState(): WorkspaceState {
return { return toJS({
enabled: this.enabled enabled: this.enabled
}; });
} }
pushState(state = this.getState()) { pushState(state = this.getState()) {
@ -87,21 +87,28 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
async load() { async load() {
await super.load(); await super.load();
type workspaceStateSync = {
id: string;
state: WorkspaceState;
};
if (ipcRenderer) { if (ipcRenderer) {
logger.info("[WORKSPACE-STORE] requesting initial state sync"); logger.info("[WORKSPACE-STORE] requesting initial state sync");
await requestMain(this.stateRequestChannel, (states: Map<string, WorkspaceState>) => { const workspaceStates: workspaceStateSync[] = await requestMain(this.stateRequestChannel);
states.forEach((state, id) => { console.log(workspaceStates);
const workspace = this.getById(id); workspaceStates.forEach((workspaceState) => {
if (workspace) { const workspace = this.getById(workspaceState.id);
workspace.setState(state); if (workspace) {
} workspace.setState(workspaceState.state);
}); }
}); });
} else { } else {
handleRequest(this.stateRequestChannel, (): Map<string, WorkspaceState> => { handleRequest(this.stateRequestChannel, (): workspaceStateSync[] => {
const states = new Map<string, WorkspaceState>(); const states: workspaceStateSync[] = [];
this.workspacesList.forEach((workspace) => { this.workspacesList.forEach((workspace) => {
states.set(workspace.id, workspace.getState()); states.push({
state: workspace.getState(),
id: workspace.id
});
}); });
return states; return states;
}); });