Use socket to manage loksyu
This commit is contained in:
@@ -43,6 +43,9 @@ export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplication
|
||||
/** @type {Function|null} bound hook handler */
|
||||
_updateHook = null
|
||||
|
||||
/** @type {Function|null} updateSetting hook handler (for socket-propagated writes) */
|
||||
_settingHook = null
|
||||
|
||||
/** Singleton accessor — open or bring to front */
|
||||
static open() {
|
||||
const existing = Array.from(foundry.applications.instances.values()).find(
|
||||
@@ -78,7 +81,14 @@ export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplication
|
||||
super._onRender(context, options)
|
||||
this.#bindInputs()
|
||||
|
||||
this._updateHook = Hooks.on("cde:loksyuUpdated", () => this.render())
|
||||
if (!this._updateHook) {
|
||||
this._updateHook = Hooks.on("cde:loksyuUpdated", () => this.render())
|
||||
}
|
||||
if (!this._settingHook) {
|
||||
this._settingHook = Hooks.on("updateSetting", (setting) => {
|
||||
if (setting.key === `${SYSTEM_ID}.loksyuData`) this.render()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
_onClose(options) {
|
||||
@@ -86,6 +96,10 @@ export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplication
|
||||
Hooks.off("cde:loksyuUpdated", this._updateHook)
|
||||
this._updateHook = null
|
||||
}
|
||||
if (this._settingHook !== null) {
|
||||
Hooks.off("updateSetting", this._settingHook)
|
||||
this._settingHook = null
|
||||
}
|
||||
super._onClose(options)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user