diff options
| author | stonedDiscord <Tukz@gmx.de> | 2026-05-17 14:51:58 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2026-05-17 14:51:58 +0200 |
| commit | 2fce78540e20c4653f401456f3a9540c5e0aa287 (patch) | |
| tree | 9808ce19bae25f4c111a64d03686c9d06075c927 /webAO | |
| parent | 2f57c6c54bceb7d1be061d6f37b501dd6a58eaa4 (diff) | |
disable markdown if it fails getting chat_config
Diffstat (limited to 'webAO')
| -rw-r--r-- | webAO/viewport/utils/handleICSpeaking.ts | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/webAO/viewport/utils/handleICSpeaking.ts b/webAO/viewport/utils/handleICSpeaking.ts index a612e77..f9b9973 100644 --- a/webAO/viewport/utils/handleICSpeaking.ts +++ b/webAO/viewport/utils/handleICSpeaking.ts @@ -14,13 +14,31 @@ import request from "../../services/request"; import preloadMessageAssets from "./preloadMessageAssets"; let attorneyMarkdown: ReturnType<typeof mlConfig> | null = null; +export let markdownDisabled = false; +let markdownInitPromise: Promise<ReturnType<typeof mlConfig> | null> | null = null; const initAttorneyMarkdown = async () => { - if (!attorneyMarkdown) { - const iniContent = await request(`${AO_HOST}themes/default/chat_config.ini`); - attorneyMarkdown = mlConfig(iniContent); + if (markdownDisabled) { + return null; } - return attorneyMarkdown; + if (attorneyMarkdown !== null) { + return attorneyMarkdown; + } + if (markdownInitPromise) { + return markdownInitPromise; + } + markdownInitPromise = (async () => { + try { + const iniContent = await request(`${AO_HOST}themes/default/chat_config.ini`); + attorneyMarkdown = mlConfig(iniContent); + return attorneyMarkdown; + } catch (error) { + console.warn("Failed to load chat_config.ini, disabling markdown system:", error); + markdownDisabled = true; + return null; + } + })(); + return markdownInitPromise; }; export let startFirstTickCheck: boolean; @@ -331,14 +349,7 @@ export const handle_ic_speaking = async (playerChatMsg: ChatMsg) => { client.viewport.getChatmsg().effects[2]; } - try { - const markdown = await initAttorneyMarkdown(); - client.viewport.getChatmsg().parsed = markdown.applyMarkdown( - client.viewport.getChatmsg().content, - COLORS[client.viewport.getChatmsg().color], - ); - } catch (error) { - console.warn("markdown failed"); + const processTextOnly = () => { const output: HTMLSpanElement[] = []; for (const letter of client.viewport.getChatmsg().content) { const currentSelector = document.createElement("span"); @@ -347,6 +358,25 @@ export const handle_ic_speaking = async (playerChatMsg: ChatMsg) => { output.push(currentSelector); } client.viewport.getChatmsg().parsed = output; + }; + + if (!markdownDisabled) { + try { + const markdown = await initAttorneyMarkdown(); + if (markdown) { + client.viewport.getChatmsg().parsed = markdown.applyMarkdown( + client.viewport.getChatmsg().content, + COLORS[client.viewport.getChatmsg().color], + ); + } else { + processTextOnly(); + } + } catch (error) { + console.warn("markdown failed"); + processTextOnly(); + } + } else { + processTextOnly(); } client.viewport.chat_tick(); |
