mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: Dispose the extension watcher when application quits
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
d0116b3b62
commit
deb65d41ec
@ -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;
|
||||
Loading…
Reference in New Issue
Block a user