(event, filePath)
| 13334 | }, 1200); |
| 13335 | } |
| 13336 | |
| 13337 | function mcpClientConfigJson(url) { |
| 13338 | return JSON.stringify({ |
| 13339 | mcpServers: { |
| 13340 | printventory: { url } |
| 13341 | } |
| 13342 | }, null, 2); |
| 13343 | } |
| 13344 | |
| 13345 | function getMcpDialogPort() { |
| 13346 | return Math.min(65535, Math.max(1024, parseInt(document.getElementById('mcp-server-port')?.value || '5000', 10) || 5000)); |
| 13347 | } |
| 13348 | |
| 13349 | function updateMcpDialogPreview(info, serverMode) { |
| 13350 | const check = document.getElementById('enable-mcp-server'); |
| 13351 | const port = getMcpDialogPort(); |
| 13352 | const scheme = (info && info.url && String(info.url).startsWith('https:')) ? 'https' : 'http'; |
| 13353 | let url = `${scheme}://127.0.0.1:${port}/mcp`; |
| 13354 | if (serverMode && window.location && window.location.origin) { |
| 13355 | url = String(window.location.origin).replace(/\/$/, '') + '/mcp'; |
| 13356 | } else if (!serverMode && info && info.url) { |
| 13357 | url = String(info.url).replace(/:\d+(\/mcp)?$/, ':' + port + '/mcp'); |
| 13358 | } |
| 13359 | const urlInput = document.getElementById('mcp-server-url'); |
| 13360 | if (urlInput) urlInput.value = url; |
| 13361 | const configEl = document.getElementById('mcp-server-config'); |
| 13362 | if (configEl) configEl.textContent = mcpClientConfigJson(url); |
| 13363 | |
| 13364 | const statusEl = document.getElementById('mcp-server-status'); |
| 13365 | if (statusEl) { |
| 13366 | if (serverMode) { |
| 13367 | statusEl.textContent = 'Status: MCP endpoint is available on this server.'; |
| 13368 | } else if (check?.checked && info && info.running) { |
| 13369 | statusEl.textContent = 'Status: Listening at ' + url; |
| 13370 | } else if (check?.checked) { |
| 13371 | statusEl.textContent = 'Status: Enabled. Click Save to start the listener.'; |
| 13372 | } else { |
| 13373 | statusEl.textContent = 'Status: Disabled. Enable and Save to start the listener while Printventory is running.'; |
| 13374 | } |
| 13375 | } |
| 13376 | const extra = document.getElementById('mcp-server-extra-urls'); |
| 13377 | if (extra) { |
| 13378 | const alts = ((info && info.urls) || []).filter((u) => u && u !== url); |
| 13379 | extra.textContent = alts.length ? ('Also reachable at: ' + alts.join(' · ')) : ''; |
| 13380 | } |
| 13381 | } |
| 13382 | |
| 13383 | async function populateMcpServerSettingsDialog() { |
| 13384 | const dialog = document.getElementById('mcp-server-settings-dialog'); |
| 13385 | if (!dialog) return; |
| 13386 | const serverMode = await window.electron.isServerMode().catch(() => false); |
| 13387 | const desktopControls = document.getElementById('mcp-server-desktop-controls'); |
| 13388 | const serverNote = document.getElementById('mcp-server-server-mode-note'); |
| 13389 | const saveBtn = document.getElementById('save-mcp-server-settings'); |
| 13390 | const cancelBtn = document.getElementById('cancel-mcp-server-settings'); |
| 13391 | if (desktopControls) desktopControls.hidden = !!serverMode; |
| 13392 | if (serverNote) serverNote.hidden = !serverMode; |
| 13393 | if (saveBtn) saveBtn.hidden = !!serverMode; |
no test coverage detected