system: fix directory monitor
Keep ref to monitor so it doesn't get garbage collected
This commit is contained in:
parent
977a59afb3
commit
abcf099f87
2 changed files with 6 additions and 2 deletions
|
|
@ -32,7 +32,6 @@ export default class Schemes extends GObject.Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly #schemeDir: string = `${DATA}/scripts/data/schemes`;
|
readonly #schemeDir: string = `${DATA}/scripts/data/schemes`;
|
||||||
readonly #monitor;
|
|
||||||
|
|
||||||
#map: { [k: string]: Scheme } = {};
|
#map: { [k: string]: Scheme } = {};
|
||||||
|
|
||||||
|
|
@ -106,7 +105,7 @@ export default class Schemes extends GObject.Object {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.update().catch(console.error);
|
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);
|
if (type !== Gio.FileMonitorEvent.DELETED) this.updateFile(file).catch(console.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ export const bindCurrentTime = (
|
||||||
return bind(time);
|
return bind(time);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const monitors = new Set();
|
||||||
export const monitorDirectory = (
|
export const monitorDirectory = (
|
||||||
path: string,
|
path: string,
|
||||||
callback: (
|
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;
|
return monitor;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue