diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-29 19:20:33 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-29 19:20:33 +1100 |
| commit | abcf099f87af0877c5be2bcfad229b2a83e4bf5c (patch) | |
| tree | 06bbd8350686e242d3b6848343f05ef61d71d3a5 | |
| parent | sidebar: allow seeking (diff) | |
| download | caelestia-shell-abcf099f87af0877c5be2bcfad229b2a83e4bf5c.tar.gz caelestia-shell-abcf099f87af0877c5be2bcfad229b2a83e4bf5c.tar.bz2 caelestia-shell-abcf099f87af0877c5be2bcfad229b2a83e4bf5c.zip | |
system: fix directory monitor
Keep ref to monitor so it doesn't get garbage collected
| -rw-r--r-- | src/services/schemes.ts | 3 | ||||
| -rw-r--r-- | src/utils/system.ts | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/services/schemes.ts b/src/services/schemes.ts index 548975c..2808b55 100644 --- a/src/services/schemes.ts +++ b/src/services/schemes.ts @@ -32,7 +32,6 @@ export default class Schemes extends GObject.Object { } readonly #schemeDir: string = `${DATA}/scripts/data/schemes`; - readonly #monitor; #map: { [k: string]: Scheme } = {}; @@ -106,7 +105,7 @@ export default class Schemes extends GObject.Object { super(); this.update().catch(console.error); - this.#monitor = monitorDirectory(this.#schemeDir, (_m, file, _f, type) => { + monitorDirectory(this.#schemeDir, (_m, file, _f, type) => { if (type !== Gio.FileMonitorEvent.DELETED) this.updateFile(file).catch(console.error); }); } diff --git a/src/utils/system.ts b/src/utils/system.ts index 2e9fa4a..8ccb5d1 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -76,6 +76,7 @@ export const bindCurrentTime = ( return bind(time); }; +const monitors = new Set(); export const monitorDirectory = ( path: string, callback: ( @@ -102,5 +103,9 @@ export const monitorDirectory = ( } } + // Keep ref to monitor so it doesn't get GCed + monitors.add(monitor); + monitor.connect("notify::cancelled", () => monitor.cancelled && monitors.delete(monitor)); + return monitor; }; |