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

Fix kube sync items not visible on reopening (#2815)

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Sebastian Malton 2021-05-20 09:40:47 -04:00 committed by GitHub
parent c8421e4740
commit 1c422f6ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 32 deletions

View File

@ -20,33 +20,14 @@
*/ */
import { reaction, toJS } from "mobx"; import { reaction, toJS } from "mobx";
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "../common/ipc"; import { broadcastMessage } from "../common/ipc";
import type { CatalogEntityRegistry} from "./catalog"; import type { CatalogEntityRegistry} from "./catalog";
import "../common/catalog-entities/kubernetes-cluster"; import "../common/catalog-entities/kubernetes-cluster";
import type { Disposer } from "../common/utils";
export class CatalogPusher { export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
static init(catalog: CatalogEntityRegistry) { return reaction(() => toJS(catalog.items, { recurseEverything: true }), (items) => {
new CatalogPusher(catalog).init(); broadcastMessage("catalog:items", items);
} }, {
fireImmediately: true,
private constructor(private catalog: CatalogEntityRegistry) {} });
init() {
const disposers: Disposer[] = [];
disposers.push(reaction(() => toJS(this.catalog.items, { recurseEverything: true }), (items) => {
broadcastMessage("catalog:items", items);
}, {
fireImmediately: true,
}));
const listener = subscribeToBroadcast("catalog:broadcast", () => {
broadcastMessage("catalog:items", toJS(this.catalog.items, { recurseEverything: true }));
});
disposers.push(() => unsubscribeFromBroadcast("catalog:broadcast", listener));
return disposers;
}
} }

View File

@ -45,11 +45,11 @@ import type { LensExtensionId } from "../extensions/lens-extension";
import { FilesystemProvisionerStore } from "./extension-filesystem"; import { FilesystemProvisionerStore } from "./extension-filesystem";
import { installDeveloperTools } from "./developer-tools"; import { installDeveloperTools } from "./developer-tools";
import { LensProtocolRouterMain } from "./protocol-handler"; import { LensProtocolRouterMain } from "./protocol-handler";
import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils"; import { disposer, getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
import { bindBroadcastHandlers } from "../common/ipc"; import { bindBroadcastHandlers } from "../common/ipc";
import { startUpdateChecking } from "./app-updater"; import { startUpdateChecking } from "./app-updater";
import { IpcRendererNavigationEvents } from "../renderer/navigation/events"; import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
import { CatalogPusher } from "./catalog-pusher"; import { pushCatalogToRenderer } from "./catalog-pusher";
import { catalogEntityRegistry } from "./catalog"; import { catalogEntityRegistry } from "./catalog";
import { HotbarStore } from "../common/hotbar-store"; import { HotbarStore } from "../common/hotbar-store";
import { HelmRepoManager } from "./helm/helm-repo-manager"; import { HelmRepoManager } from "./helm/helm-repo-manager";
@ -57,6 +57,7 @@ import { KubeconfigSyncManager } from "./catalog-sources";
import { handleWsUpgrade } from "./proxy/ws-upgrade"; import { handleWsUpgrade } from "./proxy/ws-upgrade";
const workingDir = path.join(app.getPath("appData"), appName); const workingDir = path.join(app.getPath("appData"), appName);
const cleanup = disposer();
app.setName(appName); app.setName(appName);
@ -142,7 +143,7 @@ app.on("ready", async () => {
const lensProxy = LensProxy.createInstance(handleWsUpgrade); const lensProxy = LensProxy.createInstance(handleWsUpgrade);
ClusterManager.createInstance(); ClusterManager.createInstance();
KubeconfigSyncManager.createInstance().startSync(); KubeconfigSyncManager.createInstance();
try { try {
logger.info("🔌 Starting LensProxy"); logger.info("🔌 Starting LensProxy");
@ -187,7 +188,8 @@ app.on("ready", async () => {
} }
ipcMain.on(IpcRendererNavigationEvents.LOADED, () => { ipcMain.on(IpcRendererNavigationEvents.LOADED, () => {
CatalogPusher.init(catalogEntityRegistry); cleanup.push(pushCatalogToRenderer(catalogEntityRegistry));
KubeconfigSyncManager.getInstance().startSync();
startUpdateChecking(); startUpdateChecking();
LensProtocolRouterMain LensProtocolRouterMain
.getInstance() .getInstance()
@ -251,6 +253,7 @@ app.on("will-quit", (event) => {
appEventBus.emit({name: "app", action: "close"}); appEventBus.emit({name: "app", action: "close"});
ClusterManager.getInstance(false)?.stop(); // close cluster connections ClusterManager.getInstance(false)?.stop(); // close cluster connections
KubeconfigSyncManager.getInstance(false)?.stopSync(); KubeconfigSyncManager.getInstance(false)?.stopSync();
cleanup();
if (blockQuit) { if (blockQuit) {
event.preventDefault(); // prevent app's default shutdown (e.g. required for telemetry, etc.) event.preventDefault(); // prevent app's default shutdown (e.g. required for telemetry, etc.)

View File

@ -20,7 +20,7 @@
*/ */
import { computed, observable } from "mobx"; import { computed, observable } from "mobx";
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc"; import { subscribeToBroadcast } from "../../common/ipc";
import { CatalogCategory, CatalogEntity, CatalogEntityData, catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntityKindData } from "../../common/catalog"; import { CatalogCategory, CatalogEntity, CatalogEntityData, catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntityKindData } from "../../common/catalog";
import "../../common/catalog-entities"; import "../../common/catalog-entities";
import { iter } from "../utils"; import { iter } from "../utils";
@ -35,7 +35,6 @@ export class CatalogEntityRegistry {
subscribeToBroadcast("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => { subscribeToBroadcast("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
this.rawItems.replace(items); this.rawItems.replace(items);
}); });
broadcastMessage("catalog:broadcast");
} }
set activeEntity(entity: CatalogEntity) { set activeEntity(entity: CatalogEntity) {