@sailingrotevista/rotevista-dash 4.0.5 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app.js +16 -17
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -560,31 +560,33 @@ function startDisplayLoop() {
560
560
  // 8. CONFIGURAZIONE E GRAFICI UTILS
561
561
  // ==========================================================================
562
562
  /**
563
- * Recupera la configurazione tramite le API ufficiali di Signal K.
564
- * Sovrascrive i default locali con i parametri impostati nel server.
563
+ * Recupera la configurazione provando i percorsi standard e quelli "scoped".
564
+ * Gestisce il parsing dei numeri e la mappatura dei grafici.
565
565
  */
566
566
  async function fetchServerConfig() {
567
- // Evita di cercare il server se siamo in locale (file://)
568
567
  if (!window.location.protocol.includes("http")) return;
569
568
 
570
- // Percorsi API ufficiali di Signal K per i plugin
569
+ // Elenco di tutti i percorsi dove Signal K potrebbe aver salvato i settings
571
570
  const urls = [
572
- '/signalk/v1/api/plugins/rotevista-dash',
573
- '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash'
571
+ '/plugins/rotevista-dash/settings',
572
+ '/plugins/@sailingrotevista%2frotevista-dash/settings',
573
+ '/signalk/v1/api/plugins/rotevista-dash/settings',
574
+ '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash/settings',
575
+ '/plugins/rotevista-dash/config' // Quello che ti ha dato 401
574
576
  ];
575
577
 
576
578
  for (let url of urls) {
577
579
  try {
578
580
  const response = await fetch(url);
581
+
579
582
  if (response.ok) {
580
583
  const data = await response.json();
581
584
 
582
- // Nelle API SK, i dati utente sono spesso in 'data.enabled' o 'data.settings'
583
- // Noi cerchiamo l'oggetto che contiene le nostre chiavi (alarms, averaging, ecc.)
585
+ // Signal K può restituire i dati direttamente, in 'configuration' o in 'settings'
584
586
  const actual = data.settings || data.configuration || data.options || data;
585
587
 
586
588
  if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
587
- // FUNZIONE DI PARSING: Trasforma eventuali testi "12.5" in numeri 12.5 reali
589
+ // FUNZIONE DI PARSING: Trasforma i testi in numeri per i calcoli
588
590
  const parseNumbers = (obj) => {
589
591
  for (let k in obj) {
590
592
  if (typeof obj[k] === 'object') parseNumbers(obj[k]);
@@ -595,7 +597,7 @@ async function fetchServerConfig() {
595
597
  };
596
598
  parseNumbers(actual);
597
599
 
598
- // MAPPATURA DEI PARAMETRI NEL CONFIG LOCALE
600
+ // APPLICAZIONE CONFIGURAZIONE (Ora include anche i grafici!)
599
601
  if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
600
602
  if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
601
603
  if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
@@ -604,16 +606,13 @@ async function fetchServerConfig() {
604
606
  CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
605
607
  }
606
608
  }
607
- console.log("✅ Configurazione caricata correttamente da:", url);
608
- return; // Successo: usciamo dal ciclo dei tentativi
609
+ console.log("✅ CONFIGURAZIONE CARICATA DA:", url);
610
+ return; // Abbiamo trovato i dati, usciamo dal loop
609
611
  }
610
- } else if (response.status === 401) {
611
- console.error("❌ Errore 401: Accesso negato. Abilita 'Anonymous Read' in Signal K Security.");
612
612
  }
613
- } catch (e) {
614
- console.warn(`⚠️ Tentativo fallito su ${url}:`, e.message);
615
- }
613
+ } catch (e) { }
616
614
  }
615
+ console.warn("⚠️ Nessun dato di configurazione trovato nei percorsi standard. Uso i default.");
617
616
  }
618
617
 
619
618
  function manageHistory(t, v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {