@sailingrotevista/rotevista-dash 4.0.3 → 4.0.5
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.
- package/app.js +26 -17
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -560,16 +560,17 @@ function startDisplayLoop() {
|
|
|
560
560
|
// 8. CONFIGURAZIONE E GRAFICI UTILS
|
|
561
561
|
// ==========================================================================
|
|
562
562
|
/**
|
|
563
|
-
* Recupera la configurazione
|
|
564
|
-
*
|
|
563
|
+
* Recupera la configurazione tramite le API ufficiali di Signal K.
|
|
564
|
+
* Sovrascrive i default locali con i parametri impostati nel server.
|
|
565
565
|
*/
|
|
566
566
|
async function fetchServerConfig() {
|
|
567
|
+
// Evita di cercare il server se siamo in locale (file://)
|
|
567
568
|
if (!window.location.protocol.includes("http")) return;
|
|
568
569
|
|
|
569
|
-
//
|
|
570
|
+
// Percorsi API ufficiali di Signal K per i plugin
|
|
570
571
|
const urls = [
|
|
571
|
-
'/plugins/rotevista-dash
|
|
572
|
-
'/plugins/@sailingrotevista%2frotevista-dash
|
|
572
|
+
'/signalk/v1/api/plugins/rotevista-dash',
|
|
573
|
+
'/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash'
|
|
573
574
|
];
|
|
574
575
|
|
|
575
576
|
for (let url of urls) {
|
|
@@ -577,20 +578,24 @@ async function fetchServerConfig() {
|
|
|
577
578
|
const response = await fetch(url);
|
|
578
579
|
if (response.ok) {
|
|
579
580
|
const data = await response.json();
|
|
580
|
-
// Signal K mette i dati reali dentro l'oggetto configuration o direttamente nel body
|
|
581
|
-
const actual = data.configuration || data;
|
|
582
581
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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.)
|
|
584
|
+
const actual = data.settings || data.configuration || data.options || data;
|
|
585
|
+
|
|
586
|
+
if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
|
|
587
|
+
// FUNZIONE DI PARSING: Trasforma eventuali testi "12.5" in numeri 12.5 reali
|
|
588
|
+
const parseNumbers = (obj) => {
|
|
586
589
|
for (let k in obj) {
|
|
587
|
-
if (typeof obj[k] === 'object')
|
|
588
|
-
else if (!isNaN(obj[k]) && obj[k] !== ""
|
|
590
|
+
if (typeof obj[k] === 'object') parseNumbers(obj[k]);
|
|
591
|
+
else if (!isNaN(obj[k]) && obj[k] !== "" && typeof obj[k] === 'string') {
|
|
592
|
+
obj[k] = parseFloat(obj[k]);
|
|
593
|
+
}
|
|
589
594
|
}
|
|
590
595
|
};
|
|
591
|
-
|
|
596
|
+
parseNumbers(actual);
|
|
592
597
|
|
|
593
|
-
// MAPPATURA
|
|
598
|
+
// MAPPATURA DEI PARAMETRI NEL CONFIG LOCALE
|
|
594
599
|
if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
|
|
595
600
|
if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
|
|
596
601
|
if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
|
|
@@ -599,11 +604,15 @@ async function fetchServerConfig() {
|
|
|
599
604
|
CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
|
|
600
605
|
}
|
|
601
606
|
}
|
|
602
|
-
console.log("Configurazione caricata correttamente da:", url);
|
|
603
|
-
return; //
|
|
607
|
+
console.log("✅ Configurazione caricata correttamente da:", url);
|
|
608
|
+
return; // Successo: usciamo dal ciclo dei tentativi
|
|
604
609
|
}
|
|
610
|
+
} else if (response.status === 401) {
|
|
611
|
+
console.error("❌ Errore 401: Accesso negato. Abilita 'Anonymous Read' in Signal K Security.");
|
|
605
612
|
}
|
|
606
|
-
} catch (e) {
|
|
613
|
+
} catch (e) {
|
|
614
|
+
console.warn(`⚠️ Tentativo fallito su ${url}:`, e.message);
|
|
615
|
+
}
|
|
607
616
|
}
|
|
608
617
|
}
|
|
609
618
|
|