1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

added tracking cluster-manager's ipc events

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-07-07 21:13:23 +03:00
parent f474a20904
commit cf00debb33
2 changed files with 20 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import { clusterStore } from "./cluster-store"
export type WorkspaceId = string;
export interface WorkspaceStoreModel {
currentWorkspace?: WorkspaceId; // last visited/activated
workspaces: Workspace[]
}
@ -18,6 +19,7 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
static readonly defaultId: WorkspaceId = "default"
protected data: WorkspaceStoreModel = {
currentWorkspace: WorkspaceStore.defaultId,
workspaces: [{
id: WorkspaceStore.defaultId,
name: "default"
@ -42,6 +44,11 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
return this.workspaces.findIndex(workspace => workspace.id === id);
}
@action
setCurrent(id: WorkspaceId) {
this.data.currentWorkspace = id;
}
@action
public saveWorkspace(newWorkspace: Workspace) {
const workspace = this.getById(newWorkspace.id);

View File

@ -12,6 +12,7 @@ import logger from "./logger"
import { onMessages } from "../common/ipc-helpers";
import { ClusterIpcMessage } from "../common/ipc-messages";
import { FeatureInstallRequest } from "./feature";
import { tracker } from "../common/tracker";
export interface ClusterIconUpload {
clusterId: string;
@ -107,44 +108,51 @@ export class ClusterManager {
protected listenIpcEvents() {
onMessages({
[ClusterIpcMessage.CLUSTER_ADD]: async (model: ClusterModel): Promise<boolean> => {
tracker.event("cluster", "add");
await this.addCluster(model);
return true;
},
[ClusterIpcMessage.CLUSTER_STOP]: (clusterId: ClusterId) => {
tracker.event("cluster", "stop");
this.getCluster(clusterId)?.stopServer();
},
[ClusterIpcMessage.CLUSTER_REFRESH]: (clusterId: ClusterId) => {
this.getCluster(clusterId)?.refreshCluster();
},
[ClusterIpcMessage.CLUSTER_REMOVE]: (clusterId: ClusterId) => {
tracker.event("cluster", "remove");
this.removeCluster(clusterId);
},
[ClusterIpcMessage.CLUSTER_REMOVE_WORKSPACE]: (workspaceId: ClusterId) => {
this.removeAllByWorkspace(workspaceId);
},
[ClusterIpcMessage.CLUSTER_REFRESH]: (clusterId: ClusterId) => {
this.getCluster(clusterId)?.refreshCluster();
},
[ClusterIpcMessage.CLUSTER_EVENTS]: async (clusterId: ClusterId): Promise<number> => {
return await this.getCluster(clusterId)?.getEventCount() || 0;
},
// todo: check feature failures
[ClusterIpcMessage.FEATURE_INSTALL]: ({ clusterId, name, config }: FeatureInstallRequest) => {
tracker.event("cluster", "install-feature")
return this.getCluster(clusterId)?.installFeature(name, config)
},
[ClusterIpcMessage.FEATURE_UPGRADE]: ({ clusterId, name, config }: FeatureInstallRequest) => {
tracker.event("cluster", "upgrade-feature")
return this.getCluster(clusterId)?.upgradeFeature(name, config)
},
[ClusterIpcMessage.FEATURE_REMOVE]: ({ clusterId, name }: FeatureInstallRequest) => {
tracker.event("cluster", "uninstall-feature")
return this.getCluster(clusterId)?.uninstallFeature(name);
},
[ClusterIpcMessage.ICON_SAVE]: async ({ clusterId, name, path }: ClusterIconUpload) => {
tracker.event("cluster", "upload-icon");
const cluster = this.getCluster(clusterId);
if (!cluster) return false;
cluster.preferences.icon = await this.uploadClusterIcon(cluster, name, path);
},
// todo: remove current file icon ?
[ClusterIpcMessage.ICON_RESET]: async (clusterId: ClusterId) => {
tracker.event("cluster", "reset-icon")
const cluster = this.getCluster(clusterId);
if (!cluster) return false;
cluster.preferences.icon = null;
cluster.preferences.icon = null; // todo: remove current file-icon ?
},
}, {
timeout: 2000,