Refactor Ena Planner to iframe settings and harden save ack flow
This commit is contained in:
32
index.js
32
index.js
@@ -27,7 +27,7 @@ import { initNovelDraw, cleanupNovelDraw } from "./modules/novel-draw/novel-draw
|
||||
import "./modules/story-summary/story-summary.js";
|
||||
import "./modules/story-outline/story-outline.js";
|
||||
import { initTts, cleanupTts } from "./modules/tts/tts.js";
|
||||
import { initEnaPlanner } from "./modules/ena-planner/ena-planner.js";
|
||||
import { initEnaPlanner, cleanupEnaPlanner } from "./modules/ena-planner/ena-planner.js";
|
||||
|
||||
extension_settings[EXT_ID] = extension_settings[EXT_ID] || {
|
||||
enabled: true,
|
||||
@@ -45,6 +45,7 @@ extension_settings[EXT_ID] = extension_settings[EXT_ID] || {
|
||||
storyOutline: { enabled: false },
|
||||
novelDraw: { enabled: false },
|
||||
tts: { enabled: false },
|
||||
enaPlanner: { enabled: false },
|
||||
useBlob: false,
|
||||
wrapperIframe: true,
|
||||
renderEnabled: true,
|
||||
@@ -277,7 +278,8 @@ function toggleSettingsControls(enabled) {
|
||||
'xiaobaix_use_blob', 'xiaobaix_variables_core_enabled', 'xiaobaix_variables_mode', 'Wrapperiframe', 'xiaobaix_render_enabled',
|
||||
'xiaobaix_max_rendered', 'xiaobaix_story_outline_enabled', 'xiaobaix_story_summary_enabled',
|
||||
'xiaobaix_novel_draw_enabled', 'xiaobaix_novel_draw_open_settings',
|
||||
'xiaobaix_tts_enabled', 'xiaobaix_tts_open_settings'
|
||||
'xiaobaix_tts_enabled', 'xiaobaix_tts_open_settings',
|
||||
'xiaobaix_ena_planner_enabled', 'xiaobaix_ena_planner_open_settings'
|
||||
];
|
||||
controls.forEach(id => {
|
||||
$(`#${id}`).prop('disabled', !enabled).closest('.flex-container').toggleClass('disabled-control', !enabled);
|
||||
@@ -312,6 +314,7 @@ async function toggleAllFeatures(enabled) {
|
||||
{ condition: extension_settings[EXT_ID].variablesCore?.enabled, init: initVariablesCore },
|
||||
{ condition: extension_settings[EXT_ID].novelDraw?.enabled, init: initNovelDraw },
|
||||
{ condition: extension_settings[EXT_ID].tts?.enabled, init: initTts },
|
||||
{ condition: extension_settings[EXT_ID].enaPlanner?.enabled, init: initEnaPlanner },
|
||||
{ condition: true, init: initStreamingGeneration },
|
||||
{ condition: true, init: initButtonCollapse }
|
||||
];
|
||||
@@ -347,6 +350,7 @@ async function toggleAllFeatures(enabled) {
|
||||
try { cleanupVareventEditor(); } catch (e) { }
|
||||
try { cleanupNovelDraw(); } catch (e) { }
|
||||
try { cleanupTts(); } catch (e) { }
|
||||
try { cleanupEnaPlanner(); } catch (e) { }
|
||||
try { clearBlobCaches(); } catch (e) { }
|
||||
toggleSettingsControls(false);
|
||||
try { window.cleanupWorldbookHostBridge && window.cleanupWorldbookHostBridge(); document.getElementById('xb-worldbook')?.remove(); } catch (e) { }
|
||||
@@ -391,7 +395,8 @@ async function setupSettings() {
|
||||
{ id: 'xiaobaix_story_summary_enabled', key: 'storySummary' },
|
||||
{ id: 'xiaobaix_story_outline_enabled', key: 'storyOutline' },
|
||||
{ id: 'xiaobaix_novel_draw_enabled', key: 'novelDraw', init: initNovelDraw },
|
||||
{ id: 'xiaobaix_tts_enabled', key: 'tts', init: initTts }
|
||||
{ id: 'xiaobaix_tts_enabled', key: 'tts', init: initTts },
|
||||
{ id: 'xiaobaix_ena_planner_enabled', key: 'enaPlanner', init: initEnaPlanner }
|
||||
];
|
||||
|
||||
moduleConfigs.forEach(({ id, key, init }) => {
|
||||
@@ -407,6 +412,9 @@ async function setupSettings() {
|
||||
if (!enabled && key === 'tts') {
|
||||
try { cleanupTts(); } catch (e) { }
|
||||
}
|
||||
if (!enabled && key === 'enaPlanner') {
|
||||
try { cleanupEnaPlanner(); } catch (e) { }
|
||||
}
|
||||
settings[key] = extension_settings[EXT_ID][key] || {};
|
||||
settings[key].enabled = enabled;
|
||||
extension_settings[EXT_ID][key] = settings[key];
|
||||
@@ -450,6 +458,15 @@ async function setupSettings() {
|
||||
}
|
||||
});
|
||||
|
||||
$("#xiaobaix_ena_planner_open_settings").on("click", function () {
|
||||
if (!isXiaobaixEnabled) return;
|
||||
if (settings.enaPlanner?.enabled && window.xiaobaixEnaPlanner?.openSettings) {
|
||||
window.xiaobaixEnaPlanner.openSettings();
|
||||
} else {
|
||||
toastr.warning('请先启用剧情规划模块');
|
||||
}
|
||||
});
|
||||
|
||||
$("#xiaobaix_use_blob").prop("checked", !!settings.useBlob).on("change", async function () {
|
||||
if (!isXiaobaixEnabled) return;
|
||||
settings.useBlob = $(this).prop("checked");
|
||||
@@ -512,10 +529,11 @@ async function setupSettings() {
|
||||
variablesPanel: 'xiaobaix_variables_panel_enabled',
|
||||
variablesCore: 'xiaobaix_variables_core_enabled',
|
||||
novelDraw: 'xiaobaix_novel_draw_enabled',
|
||||
tts: 'xiaobaix_tts_enabled'
|
||||
tts: 'xiaobaix_tts_enabled',
|
||||
enaPlanner: 'xiaobaix_ena_planner_enabled'
|
||||
};
|
||||
const ON = ['templateEditor', 'tasks', 'variablesCore', 'audio', 'storySummary', 'recorded'];
|
||||
const OFF = ['preview', 'immersive', 'variablesPanel', 'fourthWall', 'storyOutline', 'novelDraw', 'tts'];
|
||||
const OFF = ['preview', 'immersive', 'variablesPanel', 'fourthWall', 'storyOutline', 'novelDraw', 'tts', 'enaPlanner'];
|
||||
function setChecked(id, val) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) {
|
||||
@@ -650,11 +668,11 @@ jQuery(async () => {
|
||||
{ condition: settings.variablesCore?.enabled, init: initVariablesCore },
|
||||
{ condition: settings.novelDraw?.enabled, init: initNovelDraw },
|
||||
{ condition: settings.tts?.enabled, init: initTts },
|
||||
{ condition: settings.enaPlanner?.enabled, init: initEnaPlanner },
|
||||
{ condition: true, init: initStreamingGeneration },
|
||||
{ condition: true, init: initButtonCollapse }
|
||||
];
|
||||
moduleInits.forEach(({ condition, init }) => { if (condition) init(); });
|
||||
try { initEnaPlanner(); } catch (e) { console.error('[EnaPlanner] Init failed:', e); }
|
||||
|
||||
if (settings.preview?.enabled || settings.recorded?.enabled) {
|
||||
setTimeout(initMessagePreview, 1500);
|
||||
@@ -675,4 +693,4 @@ jQuery(async () => {
|
||||
} catch (err) { }
|
||||
});
|
||||
|
||||
export { executeSlashCommand };
|
||||
export { executeSlashCommand };
|
||||
|
||||
Reference in New Issue
Block a user