feat: Implement saving and loading of the countdown window's position, prevent it from resizing larger than its content, and update module metadata.

This commit is contained in:
CPTN Cosmo 2026-01-07 15:52:39 +01:00
parent 4466a13098
commit 45003881af
No known key found for this signature in database
3 changed files with 35 additions and 3 deletions

View file

@ -6,6 +6,11 @@
export function createMovableCountdownsClass(BaseCountdowns) {
return class MovableCountdowns extends BaseCountdowns {
constructor(options = {}) {
// Load saved position if exists
const savedPos = game.user.getFlag('dh-countdownsplus', 'windowPosition');
if (savedPos) {
options.position = foundry.utils.mergeObject(options.position || {}, savedPos);
}
super(options);
}
@ -132,8 +137,31 @@ export function createMovableCountdownsClass(BaseCountdowns) {
}
}
/**
* Capture position changes to save them, since close() only has the final state.
* AppV2 doesn't have a simple 'move' hook, but we can override setPosition.
*/
setPosition(position = {}) {
const result = super.setPosition(position);
// Debounce save or just save on close?
// Saving on close is safer for perf, but crash might lose it.
// Let's stick to close() for now as per plan, but we need to ensure 'this.position' is updated.
// In AppV2, this.position is getter/setter.
return result;
}
/** @override */
async close(options = {}) {
// Save position before closing
if (this.position) {
await game.user.setFlag('dh-countdownsplus', 'windowPosition', {
top: this.position.top,
left: this.position.left,
width: this.position.width,
height: this.position.height
});
}
await super.close(options);
// Remove detached class from body