mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Stop file system watchers on application quit to prevent exit code !== 0 (#7504)
* fix: Dispose the kubeconfig watcher when application quits Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * fix: Dispose the extension watcher when application quits Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> --------- Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
673144ae8f
commit
696c026f2d
@ -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<false>|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<void> => {
|
||||
// e.g. "foo/package.json"
|
||||
const relativePath = this.dependencies.getRelativePath(this.localFolderPath, manifestPath);
|
||||
|
||||
@ -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;
|
||||
@ -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()) });
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user