Remove ClusterStore.removedClusters and correctly delete lens storage file (#4077)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-20 08:51:26 -04:00
1 parent b4a4cc6be4
commit 32562b11a4
5 files changed
+19 -40

No files matched your search

+17 -3
View File
@@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
import { app, BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
import { KubernetesCluster } from "../../common/catalog-entities";
import { clusterFrameMap } from "../../common/cluster-frames";
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../common/cluster-ipc";
@@ -32,6 +32,8 @@ import { pushCatalogToRenderer } from "../catalog-pusher";
import { ClusterManager } from "../cluster-manager";
import { ResourceApplier } from "../resource-applier";
import { WindowManager } from "../window-manager";
import path from "path";
import { remove } from "fs-extra";
export function initIpcMainHandlers() {
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
@@ -79,9 +81,11 @@ export function initIpcMainHandlers() {
}
});
ipcMainHandle(clusterDeleteHandler, (event, clusterId: ClusterId) => {
ipcMainHandle(clusterDeleteHandler, async (event, clusterId: ClusterId) => {
appEventBus.emit({ name: "cluster", action: "remove" });
const cluster = ClusterStore.getInstance().getById(clusterId);
const clusterStore = ClusterStore.getInstance();
const cluster = clusterStore.getById(clusterId);
if (!cluster) {
return;
@@ -89,6 +93,16 @@ export function initIpcMainHandlers() {
cluster.disconnect();
clusterFrameMap.delete(cluster.id);
// Remove from the cluster store as well, this should clear any old settings
clusterStore.clusters.delete(cluster.id);
try {
// remove the local storage file
const localStorageFilePath = path.resolve(app.getPath("userData"), "lens-local-storage", `${cluster.id}.json`);
await remove(localStorageFilePath);
} catch {}
});
ipcMainHandle(clusterSetDeletingHandler, (event, clusterId: string) => {