diff --git a/module/applications/dialogs/CompendiumBrowserSettings.mjs b/module/applications/dialogs/CompendiumBrowserSettings.mjs index ad89a688..c0c1ae0c 100644 --- a/module/applications/dialogs/CompendiumBrowserSettings.mjs +++ b/module/applications/dialogs/CompendiumBrowserSettings.mjs @@ -123,6 +123,16 @@ export default class CompendiumBrowserSettings extends HandlebarsApplicationMixi CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings, settings.toObject() ); + + this.updated = true; this.close(); } + + static async configure() { + return new Promise(resolve => { + const app = new this(); + app.addEventListener('close', () => resolve(app.updated), { once: true }); + app.render({ force: true }); + }); + } } diff --git a/module/applications/ui/itemBrowser.mjs b/module/applications/ui/itemBrowser.mjs index 6869271a..8cf31436 100644 --- a/module/applications/ui/itemBrowser.mjs +++ b/module/applications/ui/itemBrowser.mjs @@ -1,3 +1,5 @@ +import { RefreshType, socketEvent } from '../../systemRegistration/socket.mjs'; + const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; /** @@ -17,6 +19,13 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) { this.config = CONFIG.DH.ITEMBROWSER.compendiumConfig; this.presets = {}; this.compendiumBrowserTypeKey = 'compendiumBrowserDefault'; + + this.setupHooks = Hooks.on(socketEvent.Refresh, ({ refreshType }) => { + if (refreshType === RefreshType.CompendiumBrowser) { + this.render({ force: true }); + this.loadItems(); + } + }); } /** @inheritDoc */ @@ -518,7 +527,16 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) { } static async openSettings() { - new game.system.api.applications.dialogs.CompendiumBrowserSettingsDialog().render({ force: true }); + const settingsUpdated = await game.system.api.applications.dialogs.CompendiumBrowserSettingsDialog.configure(); + if (settingsUpdated) { + Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.CompendiumBrowser }); + await game.socket.emit(`system.${CONFIG.DH.id}`, { + action: socketEvent.Refresh, + data: { + refreshType: RefreshType.CompendiumBrowser + } + }); + } } _createDragProcess() { @@ -580,4 +598,9 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) { headerActions.append(button); } } + + async close(options = {}) { + Hooks.off(socketEvent.Refresh, this.setupHooks); + await super.close(options); + } } diff --git a/module/systemRegistration/socket.mjs b/module/systemRegistration/socket.mjs index a9e86917..173ef02b 100644 --- a/module/systemRegistration/socket.mjs +++ b/module/systemRegistration/socket.mjs @@ -38,7 +38,8 @@ export const RefreshType = { Countdown: 'DhCoundownRefresh', TagTeamRoll: 'DhTagTeamRollRefresh', EffectsDisplay: 'DhEffectsDisplayRefresh', - Scene: 'DhSceneRefresh' + Scene: 'DhSceneRefresh', + CompendiumBrowser: 'DhCompendiumBrowserRefresh' }; export const registerSocketHooks = () => {