From 529aa72bdf7d07fcc5c590aac67d18065054b7b2 Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Sat, 22 Nov 2025 15:46:30 -0700 Subject: [PATCH] Add the startSidebarExpanded setting (closes #2) --- .vscode/settings.json | 2 +- eslint.config.mjs | 2 +- langs/en-ca.json | 9 ++++++++- module/consts.mjs | 2 +- module/hooks/init.mjs | 8 ++++++++ module/hooks/ready.mjs | 2 +- module/hooks/renderSidebar.mjs | 9 +++++++++ module/oft.mjs | 2 ++ module/settings/startSidebarExpanded.mjs | 22 ++++++++++++++++++++++ module/utils/isBetweenVersions.mjs | 18 ++++++++++++++++++ 10 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 module/hooks/init.mjs create mode 100644 module/hooks/renderSidebar.mjs create mode 100644 module/settings/startSidebarExpanded.mjs create mode 100644 module/utils/isBetweenVersions.mjs diff --git a/.vscode/settings.json b/.vscode/settings.json index f33e799..961b5f8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,7 @@ "foundry": true }, "search.exclude": { - "foundry": true + "foundry": false }, "html.customData": [ "./.vscode/foundry.html-data.json" diff --git a/eslint.config.mjs b/eslint.config.mjs index 4ef4c09..71b890e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -75,7 +75,7 @@ export default [ "@stylistic/eol-last": `warn`, "@stylistic/operator-linebreak": [`warn`, `before`], "@stylistic/indent": [`warn`, `tab`], - "@stylistic/brace-style": [`warn`, `stroustrup`, { "allowSingleLine": true }], + "@stylistic/brace-style": [`off`], "@stylistic/quotes": [`warn`, `backtick`, { "avoidEscape": true }], "@stylistic/comma-dangle": [`warn`, { arrays: `always-multiline`, objects: `always-multiline`, imports: `always-multiline`, exports: `always-multiline`, functions: `always-multiline` }], "@stylistic/comma-style": [`warn`, `last`], diff --git a/langs/en-ca.json b/langs/en-ca.json index 2029f91..4c2b17f 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -1,3 +1,10 @@ { - "OFT": {} + "OFT": { + "setting": { + "startSidebarExpanded": { + "name": "Start Sidebar Expanded", + "hint": "(v13+) Starts the right-hand sidebar expanded when logging in." + } + } + } } diff --git a/module/consts.mjs b/module/consts.mjs index 7e598ed..9286d27 100644 --- a/module/consts.mjs +++ b/module/consts.mjs @@ -1,4 +1,4 @@ -export const __ID = `otf`; +export const __ID = `oft`; export function inDev() { return game.modules.get(__ID).flags.inDev; diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs new file mode 100644 index 0000000..93489c9 --- /dev/null +++ b/module/hooks/init.mjs @@ -0,0 +1,8 @@ +import { __ID } from "../consts.mjs"; +import { startSidebarExpanded } from "../settings/startSidebarExpanded.mjs"; + +Hooks.once(`init`, () => { + console.log(`${__ID} | Initializing`); + + startSidebarExpanded.register(); +}); diff --git a/module/hooks/ready.mjs b/module/hooks/ready.mjs index 7ccd43b..c5e280e 100644 --- a/module/hooks/ready.mjs +++ b/module/hooks/ready.mjs @@ -1,5 +1,5 @@ import { __ID } from "../consts.mjs"; -Hooks.on(`ready`, () => { +Hooks.once(`ready`, () => { console.log(`${__ID} | Ready`); }); diff --git a/module/hooks/renderSidebar.mjs b/module/hooks/renderSidebar.mjs new file mode 100644 index 0000000..9d8e2dd --- /dev/null +++ b/module/hooks/renderSidebar.mjs @@ -0,0 +1,9 @@ +import { startSidebarExpanded } from "../settings/startSidebarExpanded.mjs"; + +Hooks.once(`renderSidebar`, (app, _element, _context, _options) => { + + // MARK: Sidebar Expansion + if (startSidebarExpanded.value()) { + app.toggleExpanded(true); + } +}); diff --git a/module/oft.mjs b/module/oft.mjs index ccb796e..1f2399e 100644 --- a/module/oft.mjs +++ b/module/oft.mjs @@ -1,2 +1,4 @@ // Hooks +import "./hooks/init.mjs"; import "./hooks/ready.mjs"; +import "./hooks/renderSidebar.mjs"; diff --git a/module/settings/startSidebarExpanded.mjs b/module/settings/startSidebarExpanded.mjs new file mode 100644 index 0000000..43beada --- /dev/null +++ b/module/settings/startSidebarExpanded.mjs @@ -0,0 +1,22 @@ +import { __ID } from "../consts.mjs"; + +const key = `startSidebarExpanded`; + +const config = { + name: `OFT.setting.${key}.name`, + hint: `OFT.setting.${key}.hint`, + scope: `user`, + type: Boolean, + default: true, + config: true, + requiresReload: false, +}; + +export const startSidebarExpanded = { + value() { + return game.settings.get(__ID, key); + }, + register() { + game.settings.register(__ID, key, config); + }, +}; diff --git a/module/utils/isBetweenVersions.mjs b/module/utils/isBetweenVersions.mjs new file mode 100644 index 0000000..699ed99 --- /dev/null +++ b/module/utils/isBetweenVersions.mjs @@ -0,0 +1,18 @@ +export function isBetweenVersions(min, target, max) { + + if (min) { + const isOlderThanMin = foundry.utils.isNewerVersion(min, target); + if (isOlderThanMin) { + return false; + }; + }; + + if (max) { + const isNewerThanMax = foundry.utils.isNewerVersion(target, max); + if (isNewerThanMax) { + return false; + }; + }; + + return true; +};