@sailingrotevista/rotevista-dash 4.0.5 → 4.0.6
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 +19 -15
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -563,28 +563,33 @@ function startDisplayLoop() {
|
|
|
563
563
|
* Recupera la configurazione tramite le API ufficiali di Signal K.
|
|
564
564
|
* Sovrascrive i default locali con i parametri impostati nel server.
|
|
565
565
|
*/
|
|
566
|
+
/**
|
|
567
|
+
* Recupera la configurazione dal server Signal K provando diversi percorsi.
|
|
568
|
+
* Gestisce i permessi e converte i dati in formato numerico.
|
|
569
|
+
*/
|
|
566
570
|
async function fetchServerConfig() {
|
|
567
|
-
// Evita di cercare il server se siamo in locale (file://)
|
|
568
571
|
if (!window.location.protocol.includes("http")) return;
|
|
569
|
-
|
|
570
|
-
//
|
|
572
|
+
|
|
573
|
+
// Elenco percorsi dal più probabile (WebApp Data) al più tecnico (Plugin API)
|
|
571
574
|
const urls = [
|
|
575
|
+
'/signalk/v1/applicationData/user/rotevista-dash/1.0/settings',
|
|
572
576
|
'/signalk/v1/api/plugins/rotevista-dash',
|
|
573
|
-
'/
|
|
577
|
+
'/plugins/rotevista-dash/config'
|
|
574
578
|
];
|
|
575
579
|
|
|
576
580
|
for (let url of urls) {
|
|
577
581
|
try {
|
|
582
|
+
console.log(`Tentativo di caricamento configurazione da: ${url}`);
|
|
578
583
|
const response = await fetch(url);
|
|
584
|
+
|
|
579
585
|
if (response.ok) {
|
|
580
586
|
const data = await response.json();
|
|
581
587
|
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
588
|
+
// Signal K può incapsulare i dati in 'settings', 'configuration' o 'value'
|
|
589
|
+
const actual = data.settings || data.configuration || data.value || data;
|
|
590
|
+
|
|
586
591
|
if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
|
|
587
|
-
// FUNZIONE DI PARSING:
|
|
592
|
+
// FUNZIONE DI PARSING: Garantisce che i valori siano numeri reali
|
|
588
593
|
const parseNumbers = (obj) => {
|
|
589
594
|
for (let k in obj) {
|
|
590
595
|
if (typeof obj[k] === 'object') parseNumbers(obj[k]);
|
|
@@ -595,7 +600,7 @@ async function fetchServerConfig() {
|
|
|
595
600
|
};
|
|
596
601
|
parseNumbers(actual);
|
|
597
602
|
|
|
598
|
-
//
|
|
603
|
+
// APPLICAZIONE DEI PARAMETRI (Inclusi i grafici che prima mancavano)
|
|
599
604
|
if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
|
|
600
605
|
if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
|
|
601
606
|
if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
|
|
@@ -604,16 +609,15 @@ async function fetchServerConfig() {
|
|
|
604
609
|
CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
|
|
605
610
|
}
|
|
606
611
|
}
|
|
607
|
-
console.log("✅ Configurazione
|
|
608
|
-
return; //
|
|
612
|
+
console.log("✅ Configurazione applicata con successo da:", url);
|
|
613
|
+
return; // Uscita al primo successo
|
|
609
614
|
}
|
|
610
|
-
} else if (response.status === 401) {
|
|
611
|
-
console.error("❌ Errore 401: Accesso negato. Abilita 'Anonymous Read' in Signal K Security.");
|
|
612
615
|
}
|
|
613
616
|
} catch (e) {
|
|
614
|
-
console.warn(`⚠️
|
|
617
|
+
console.warn(`⚠️ Errore durante il fetch su ${url}:`, e.message);
|
|
615
618
|
}
|
|
616
619
|
}
|
|
620
|
+
console.warn("⚠️ Nessun percorso di configurazione valido trovato. Uso i default locali.");
|
|
617
621
|
}
|
|
618
622
|
|
|
619
623
|
function manageHistory(t, v) {
|