MCPcopy
hub / github.com/koala73/worldmonitor / initSettingsWindow

Function initSettingsWindow

src/settings-window.ts:22–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22export function initSettingsWindow(): void {
23 const appEl = document.getElementById('app');
24 if (!appEl) return;
25
26 // This window shows only "which panels to display" (panel display settings).
27 document.title = `${t('header.settings')} - World Monitor`;
28
29 let panelSettings = loadFromStorage<Record<string, PanelConfig>>(
30 STORAGE_KEYS.panels,
31 DEFAULT_PANELS
32 );
33
34 const isDesktopApp = isDesktopRuntime();
35
36 function render(): void {
37 const panelEntries = Object.entries(panelSettings).filter(
38 ([key]) => key !== 'runtime-config' || isDesktopApp
39 );
40 const panelHtml = panelEntries
41 .map(
42 ([key, panel]) => `
43 <div class="panel-toggle-item ${panel.enabled ? 'active' : ''}" data-panel="${key}">
44 <div class="panel-toggle-checkbox">${panel.enabled ? '✓' : ''}</div>
45 <span class="panel-toggle-label">${getLocalizedPanelName(key, panel.name)}</span>
46 </div>
47 `
48 )
49 .join('');
50
51 const grid = document.getElementById('panelToggles');
52 if (grid) {
53 grid.innerHTML = panelHtml;
54 grid.querySelectorAll('.panel-toggle-item').forEach((item) => {
55 item.addEventListener('click', () => {
56 const panelKey = (item as HTMLElement).dataset.panel!;
57 const config = panelSettings[panelKey];
58 if (config) {
59 config.enabled = !config.enabled;
60 saveToStorage(STORAGE_KEYS.panels, panelSettings);
61 render();
62 }
63 });
64 });
65 }
66 }
67
68 appEl.innerHTML = `
69 <div class="settings-window-shell">
70 <div class="settings-window-header">
71 <div class="settings-window-header-text">
72 <span class="settings-window-title">${escapeHtml(t('header.settings'))}</span>
73 <p class="settings-window-caption">${escapeHtml(t('header.panelDisplayCaption'))}</p>
74 </div>
75 <button type="button" class="modal-close" id="settingsWindowClose">×</button>
76 </div>
77 <div class="panel-toggle-grid" id="panelToggles"></div>
78 </div>
79 `;

Callers

nothing calls this directly

Calls 6

tFunction · 0.90
loadFromStorageFunction · 0.90
isDesktopRuntimeFunction · 0.90
escapeHtmlFunction · 0.90
renderFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected