Add debug functions menu

This commit is contained in:
Cohee
2023-08-27 23:20:43 +03:00
parent 96512c178e
commit 3b4e6f0b78
7 changed files with 80 additions and 11 deletions

View File

@ -13,7 +13,8 @@ import {
getCurrentChatId,
printCharacters,
setCharacterId,
setEditedMessageId
setEditedMessageId,
renderTemplate,
} from "../script.js";
import { isMobile, initMovingUI } from "./RossAscends-mods.js";
import {
@ -232,6 +233,7 @@ const storage_keys = {
};
let browser_has_focus = true;
const debug_functions = [];
function playMessageSound() {
if (!power_user.play_message_sound) {
@ -653,6 +655,22 @@ async function applyMovingUIPreset(name) {
loadMovingUIState()
}
/**
* Register a function to be executed when the debug menu is opened.
* @param {string} functionId Unique ID for the function.
* @param {string} name Name of the function.
* @param {string} description Description of the function.
* @param {function} func Function to be executed.
*/
export function registerDebugFunction(functionId, name, description, func) {
debug_functions.push({ functionId, name, description, func });
}
function showDebugMenu() {
const template = renderTemplate('debug', { functions: debug_functions });
callPopup(template, 'text', '', { wide: true, large: true });
}
switchUiMode();
applyFontScale('forced');
applyThemeColor();
@ -2113,6 +2131,21 @@ $(document).ready(() => {
saveSettingsDebounced();
});
$('#debug_menu').on('click', function () {
showDebugMenu();
});
$(document).on('click', '#debug_table [data-debug-function]', function () {
const functionId = $(this).data('debug-function');
const functionRecord = debug_functions.find(f => f.functionId === functionId);
if (functionRecord) {
functionRecord.func();
} else {
console.warn(`Debug function ${functionId} not found`);
}
});
$(window).on('focus', function () {
browser_has_focus = true;
});