File size: 1,152 Bytes
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';
// Settings page logic (no inline script: CSP script-src 'self'). Talks to the main process only via window.fptDesktop.
(async () => {
  const $ = (id) => document.getElementById(id);
  const params = new URLSearchParams(location.search);
  const show = (text) => { const m = $('message'); m.textContent = text; m.hidden = !text; };
  if (params.get('message')) show(params.get('message'));
  const cfg = (await window.fptDesktop.getConfig()) || { mode: 'local', serverUrl: '', projectRoot: '', autoStart: false };
  $(cfg.mode === 'remote' ? 'mode-remote' : 'mode-local').checked = true;
  $('serverUrl').value = cfg.serverUrl || '';
  $('projectRoot').value = cfg.projectRoot || '';
  $('autoStart').checked = !!cfg.autoStart;
  $('form').addEventListener('submit', async (e) => {
    e.preventDefault();
    const mode = document.querySelector('input[name=mode]:checked')?.value || 'local';
    const res = await window.fptDesktop.saveConfig({ mode, serverUrl: $('serverUrl').value, projectRoot: $('projectRoot').value, autoStart: $('autoStart').checked });
    if (!res.ok) show(res.errors.join('; '));
  });
})();