diff --git a/packages/core/src/extensions/extension-discovery/extension-discovery.ts b/packages/core/src/extensions/extension-discovery/extension-discovery.ts index bd9baff2c8..5b4f0d6486 100644 --- a/packages/core/src/extensions/extension-discovery/extension-discovery.ts +++ b/packages/core/src/extensions/extension-discovery/extension-discovery.ts @@ -17,7 +17,7 @@ import { requestInitialExtensionDiscovery } from "../../renderer/ipc"; import type { ReadJson } from "../../common/fs/read-json-file.injectable"; import type { Logger } from "../../common/logger"; import type { PathExists } from "../../common/fs/path-exists.injectable"; -import type { Watch } from "../../common/fs/watch/watch.injectable"; +import type { Watch, Watcher } from "../../common/fs/watch/watch.injectable"; import type { Stats } from "fs"; import type { LStat } from "../../common/fs/lstat.injectable"; import type { ReadDirectory } from "../../common/fs/read-directory.injectable"; @@ -168,6 +168,8 @@ export class ExtensionDiscovery { }); } + private _watch: Watcher|undefined; + /** * Watches for added/removed local extensions. * Dependencies are installed automatically after an extension folder is copied. @@ -178,7 +180,7 @@ export class ExtensionDiscovery { // Wait until .load() has been called and has been resolved await this.whenLoaded; - this.dependencies.watch(this.localFolderPath, { + this._watch = this.dependencies.watch(this.localFolderPath, { // For adding and removing symlinks to work, the depth has to be 1. depth: 1, ignoreInitial: true, @@ -198,6 +200,12 @@ export class ExtensionDiscovery { .on("unlink", this.handleWatchUnlinkEvent); } + async stopWatchingExtensions() { + this.dependencies.logger.info(`${logModule} stopping the watch for extensions`); + + await this._watch?.close(); + } + handleWatchFileAdd = async (manifestPath: string): Promise => { // e.g. "foo/package.json" const relativePath = this.dependencies.getRelativePath(this.localFolderPath, manifestPath); diff --git a/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts b/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts new file mode 100644 index 0000000000..2644612d54 --- /dev/null +++ b/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts @@ -0,0 +1,27 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable } from "@ogre-tools/injectable"; +import { beforeQuitOfBackEndInjectionToken } from "../../main/start-main-application/runnable-tokens/before-quit-of-back-end-injection-token"; +import extensionDiscoveryInjectable from "./extension-discovery.injectable"; + +const stopWatchingExtensionsOnQuitInjectable = getInjectable({ + id: "stop-watching-extensions-on-quit", + + instantiate: (di) => { + const extensionDiscovery = di.inject(extensionDiscoveryInjectable); + + return { + id: "stop-watching-extensions-on-quit", + + run: async () => { + await extensionDiscovery.stopWatchingExtensions(); + }, + }; + }, + + injectionToken: beforeQuitOfBackEndInjectionToken, +}); + +export default stopWatchingExtensionsOnQuitInjectable; diff --git a/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts b/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts index cf05577ae7..238857db4c 100644 --- a/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts +++ b/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts @@ -98,11 +98,19 @@ export class KubeconfigSyncManager { @action protected stopOldSync(filePath: string): void { - if (!this.sources.delete(filePath)) { - // already stopped + const source = this.sources.get(filePath); + + // already stopped + if (!source) { return this.dependencies.logger.debug(`no syncing file/folder to stop`, { filePath }); } + const [, disposer] = source; + + disposer(); + + this.sources.delete(filePath); + this.dependencies.logger.info(`stopping sync of file/folder`, { filePath }); this.dependencies.logger.debug(`${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) }); }