diff --git a/langs/en-ca.json b/langs/en-ca.json index 3f58800..3d3eac9 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -1,6 +1,10 @@ { "OFT": { "setting": { + "addGlobalAppsReference": { + "name": "Add Global Instances", + "hint": "(v13+) This adds a global variable named \"apps\" that allows you to access \"foundry.applications.instances\" with less typing." + }, "addGlobalDocReferrer": { "name": "Add Global \"_doc\"", "hint": "(v13+) This adds a header control to document sheets that sets the _doc globalThis variable. Until the header control is triggered, the \"_doc\" variable is undefined." diff --git a/module/hooks/setup.mjs b/module/hooks/setup.mjs index 085374b..d693714 100644 --- a/module/hooks/setup.mjs +++ b/module/hooks/setup.mjs @@ -1,4 +1,5 @@ // Tweaks +import { addGlobalAppsReference } from "../tweaks/addGlobalAppsReference.mjs"; import { addGlobalDocReferrer } from "../tweaks/addGlobalDocReferrer.mjs"; import { autoUnpauseOnLoad } from "../tweaks/autoUnpauseOnLoad.mjs"; import { chatImageLinks } from "../tweaks/chatImageLinks.mjs"; @@ -31,6 +32,7 @@ Hooks.on(`setup`, () => { restricted: false, type: DevSettingsMenu, }); + addGlobalAppsReference(); addGlobalDocReferrer(); autoUnpauseOnLoad(); diff --git a/module/tweaks/addGlobalAppsReference.mjs b/module/tweaks/addGlobalAppsReference.mjs new file mode 100644 index 0000000..634531a --- /dev/null +++ b/module/tweaks/addGlobalAppsReference.mjs @@ -0,0 +1,40 @@ +import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; +import { __ID__ } from "../consts.mjs"; +import { Logger } from "../utils/Logger.mjs"; +import { preventTweakRegistration } from "../utils/preRegisterTweak.mjs"; +import { registerDevSetting } from "../utils/SubMenuSettings.mjs"; + +export const key = `addGlobalAppsReference`; + +export function addGlobalAppsReference() { + status[key] = SettingStatusEnum.Unknown; + if (preventTweakRegistration(key)) { return }; + + // #region Registration + Logger.log(`Registering setting: ${key}`); + registerDevSetting(__ID__, key, { + name: `OFT.setting.${key}.name`, + hint: `OFT.setting.${key}.hint`, + scope: `user`, + type: Boolean, + default: false, + config: true, + requiresReload: false, + onChange: (newValue) => { + if (newValue) { + globalThis.apps = foundry.applications.instances; + } else { + delete globalThis.apps; + }; + }, + }); + // #endregion Registration + + // #region Implementation + Hooks.on(`ready`, () => { + globalThis.apps = foundry.applications.instances; + }); + // #endregion Implementation + + status[key] = SettingStatusEnum.Registered; +};