Fix extension settings menu and persist committedTrackerData

- Fixed extension settings not appearing in Extensions tab by appending to correct container (#extensions_settings2)
- Added Discord and Support Creator buttons directly in JavaScript
- Added persistence for committedTrackerData to maintain state across refreshes and restarts
- Updated saveChatData() to include committedTrackerData in chat metadata
- Updated loadChatData() to restore committedTrackerData from saved chat data
This commit is contained in:
Spicy_Marinara
2025-10-18 13:21:41 +02:00
parent 66085d494e
commit 4a3170c661
2 changed files with 41 additions and 4 deletions
+28 -4
View File
@@ -146,9 +146,33 @@ import {
/** /**
* Adds the extension settings to the Extensions tab. * Adds the extension settings to the Extensions tab.
*/ */
async function addExtensionSettings() { function addExtensionSettings() {
const settingsHtml = await renderExtensionTemplateAsync(extensionName, 'settings'); const settingsHtml = `
$('#rpg_companion_container').append(settingsHtml); <div class="inline-drawer">
<div class="inline-drawer-toggle inline-drawer-header">
<b><i class="fa-solid fa-dice-d20"></i> RPG Companion</b>
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
</div>
<div class="inline-drawer-content">
<label class="checkbox_label" for="rpg-extension-enabled">
<input type="checkbox" id="rpg-extension-enabled" />
<span>Enable RPG Companion</span>
</label>
<small class="notes">Toggle to enable/disable the RPG Companion extension. Configure additional settings within the panel itself.</small>
<div style="margin-top: 10px; display: flex; gap: 10px;">
<a href="https://discord.com/invite/KdAkTg94ME" target="_blank" class="menu_button" style="flex: 1; text-align: center; text-decoration: none;">
<i class="fa-brands fa-discord"></i> Discord
</a>
<a href="https://ko-fi.com/marinara_spaghetti" target="_blank" class="menu_button" style="flex: 1; text-align: center; text-decoration: none;">
<i class="fa-solid fa-heart"></i> Support Creator
</a>
</div>
</div>
</div>
`;
$('#extensions_settings2').append(settingsHtml);
// Set up the enable/disable toggle // Set up the enable/disable toggle
$('#rpg-extension-enabled').prop('checked', extensionSettings.enabled).on('change', function() { $('#rpg-extension-enabled').prop('checked', extensionSettings.enabled).on('change', function() {
@@ -430,7 +454,7 @@ jQuery(async () => {
// Add extension settings to Extensions tab // Add extension settings to Extensions tab
try { try {
await addExtensionSettings(); addExtensionSettings();
} catch (error) { } catch (error) {
console.error('[RPG Companion] Failed to add extension settings tab:', error); console.error('[RPG Companion] Failed to add extension settings tab:', error);
// Don't throw - extension can still work without settings tab // Don't throw - extension can still work without settings tab
+13
View File
@@ -9,9 +9,11 @@ import { getContext } from '../../../../../extensions.js';
import { import {
extensionSettings, extensionSettings,
lastGeneratedData, lastGeneratedData,
committedTrackerData,
setExtensionSettings, setExtensionSettings,
updateExtensionSettings, updateExtensionSettings,
setLastGeneratedData, setLastGeneratedData,
setCommittedTrackerData,
FEATURE_FLAGS FEATURE_FLAGS
} from './state.js'; } from './state.js';
import { migrateInventory } from '../utils/migration.js'; import { migrateInventory } from '../utils/migration.js';
@@ -123,6 +125,7 @@ export function saveChatData() {
userStats: extensionSettings.userStats, userStats: extensionSettings.userStats,
classicStats: extensionSettings.classicStats, classicStats: extensionSettings.classicStats,
lastGeneratedData: lastGeneratedData, lastGeneratedData: lastGeneratedData,
committedTrackerData: committedTrackerData,
timestamp: Date.now() timestamp: Date.now()
}; };
@@ -195,6 +198,11 @@ export function loadChatData() {
characterThoughts: null, characterThoughts: null,
html: null html: null
}); });
setCommittedTrackerData({
userStats: null,
infoBox: null,
characterThoughts: null
});
return; return;
} }
@@ -215,6 +223,11 @@ export function loadChatData() {
setLastGeneratedData({ ...savedData.lastGeneratedData }); setLastGeneratedData({ ...savedData.lastGeneratedData });
} }
// Restore committed tracker data
if (savedData.committedTrackerData) {
setCommittedTrackerData({ ...savedData.committedTrackerData });
}
// Migrate inventory in chat data if feature flag enabled // Migrate inventory in chat data if feature flag enabled
if (FEATURE_FLAGS.useNewInventory && extensionSettings.userStats.inventory) { if (FEATURE_FLAGS.useNewInventory && extensionSettings.userStats.inventory) {
const migrationResult = migrateInventory(extensionSettings.userStats.inventory); const migrationResult = migrateInventory(extensionSettings.userStats.inventory);