From 338d75a2db28a01554a299651b60caab51f80d01 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Sat, 4 Oct 2025 02:32:26 +0800 Subject: [PATCH] Update cwb_index.js --- CharacterWorldBook/cwb_index.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/CharacterWorldBook/cwb_index.js b/CharacterWorldBook/cwb_index.js index b027d7d..69a03e6 100644 --- a/CharacterWorldBook/cwb_index.js +++ b/CharacterWorldBook/cwb_index.js @@ -1,6 +1,6 @@ import { loadSettings, bindSettingsEvents } from './src/cwb_settingsManager.js'; import { initializeCharCardViewer, bindCwbApiEvents } from './src/cwb_uiManager.js'; -import { initializeCore, getLatestChatName, resetScriptStateForNewChat, handleMessageReceived } from './src/cwb_core.js'; +import { initializeCore, getLatestChatName, resetScriptStateForNewChat, handleMessageReceived, updateCardUpdateStatusDisplay } from './src/cwb_core.js'; import { checkForUpdates } from './src/cwb_updater.js'; import { isCwbEnabled } from './src/cwb_utils.js'; import { eventSource, event_types } from '/script.js'; @@ -17,29 +17,31 @@ export async function initializeCharacterWorldBook($cwbSettingsPanel) { bindSettingsEvents($cwbSettingsPanel); bindCwbApiEvents(); loadSettings(); + initializeCharCardViewer(); - if (!isCwbEnabled()) { + // Always update status display on initialization + updateCardUpdateStatusDisplay($cwbSettingsPanel); + + if (isCwbEnabled()) { + console.log('[CWB] Master switch is enabled. Initializing core features.'); + checkForUpdates(false, $cwbSettingsPanel); + await initializeCore($cwbSettingsPanel); + } else { console.log('[CWB] Master switch is disabled. Halting core feature initialization.'); - initializeCharCardViewer(); - return; } - console.log('[CWB] Master switch is enabled. Initializing core features.'); - - initializeCharCardViewer(); - checkForUpdates(false, $cwbSettingsPanel); - await initializeCore($cwbSettingsPanel); - eventSource.on(event_types.CHAT_CHANGED, async () => { - console.log('[CWB] Detected chat change. Resetting state.'); + console.log('[CWB] Detected chat change. Resetting state and updating UI.'); setTimeout(async () => { const newChatName = await getLatestChatName(); await resetScriptStateForNewChat($cwbSettingsPanel, newChatName); + updateCardUpdateStatusDisplay($cwbSettingsPanel); }, 150); }); eventSource.on(event_types.MESSAGE_RECEIVED, () => { handleMessageReceived($cwbSettingsPanel); + updateCardUpdateStatusDisplay($cwbSettingsPanel); }); console.log('[CWB] Character World Book feature initialized successfully.');