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:
@@ -146,9 +146,33 @@ import {
|
||||
/**
|
||||
* Adds the extension settings to the Extensions tab.
|
||||
*/
|
||||
async function addExtensionSettings() {
|
||||
const settingsHtml = await renderExtensionTemplateAsync(extensionName, 'settings');
|
||||
$('#rpg_companion_container').append(settingsHtml);
|
||||
function addExtensionSettings() {
|
||||
const 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
|
||||
$('#rpg-extension-enabled').prop('checked', extensionSettings.enabled).on('change', function() {
|
||||
@@ -430,7 +454,7 @@ jQuery(async () => {
|
||||
|
||||
// Add extension settings to Extensions tab
|
||||
try {
|
||||
await addExtensionSettings();
|
||||
addExtensionSettings();
|
||||
} catch (error) {
|
||||
console.error('[RPG Companion] Failed to add extension settings tab:', error);
|
||||
// Don't throw - extension can still work without settings tab
|
||||
|
||||
@@ -9,9 +9,11 @@ import { getContext } from '../../../../../extensions.js';
|
||||
import {
|
||||
extensionSettings,
|
||||
lastGeneratedData,
|
||||
committedTrackerData,
|
||||
setExtensionSettings,
|
||||
updateExtensionSettings,
|
||||
setLastGeneratedData,
|
||||
setCommittedTrackerData,
|
||||
FEATURE_FLAGS
|
||||
} from './state.js';
|
||||
import { migrateInventory } from '../utils/migration.js';
|
||||
@@ -123,6 +125,7 @@ export function saveChatData() {
|
||||
userStats: extensionSettings.userStats,
|
||||
classicStats: extensionSettings.classicStats,
|
||||
lastGeneratedData: lastGeneratedData,
|
||||
committedTrackerData: committedTrackerData,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
|
||||
@@ -195,6 +198,11 @@ export function loadChatData() {
|
||||
characterThoughts: null,
|
||||
html: null
|
||||
});
|
||||
setCommittedTrackerData({
|
||||
userStats: null,
|
||||
infoBox: null,
|
||||
characterThoughts: null
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -215,6 +223,11 @@ export function loadChatData() {
|
||||
setLastGeneratedData({ ...savedData.lastGeneratedData });
|
||||
}
|
||||
|
||||
// Restore committed tracker data
|
||||
if (savedData.committedTrackerData) {
|
||||
setCommittedTrackerData({ ...savedData.committedTrackerData });
|
||||
}
|
||||
|
||||
// Migrate inventory in chat data if feature flag enabled
|
||||
if (FEATURE_FLAGS.useNewInventory && extensionSettings.userStats.inventory) {
|
||||
const migrationResult = migrateInventory(extensionSettings.userStats.inventory);
|
||||
|
||||
Reference in New Issue
Block a user