@sailingrotevista/rotevista-dash 4.0.3 → 4.0.4

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 +46 -4
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -567,10 +567,52 @@ async function fetchServerConfig() {
567
567
  if (!window.location.protocol.includes("http")) return;
568
568
 
569
569
  // Proviamo i due percorsi standard di Signal K per i settings dei plugin
570
- const urls = [
571
- '/plugins/rotevista-dash/settings',
572
- '/plugins/@sailingrotevista%2frotevista-dash/settings'
573
- ];
570
+ /**
571
+ * Recupera la configurazione tramite le API ufficiali di Signal K.
572
+ */
573
+ async function fetchServerConfig() {
574
+ if (!window.location.protocol.includes("http")) return;
575
+
576
+ // Usiamo il percorso API ufficiale di Signal K per i plugin
577
+ const urls = [
578
+ '/signalk/v1/api/plugins/rotevista-dash',
579
+ '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash'
580
+ ];
581
+
582
+ for (let url of urls) {
583
+ try {
584
+ const response = await fetch(url);
585
+ if (response.ok) {
586
+ const data = await response.json();
587
+
588
+ // Nelle API ufficiali, i tuoi dati sono dentro 'data.settings' o 'data.configuration'
589
+ const actual = data.settings || data.configuration || data;
590
+
591
+ if (actual) {
592
+ const parseObj = (obj) => {
593
+ for (let k in obj) {
594
+ if (typeof obj[k] === 'object') parseObj(obj[k]);
595
+ else if (!isNaN(obj[k]) && obj[k] !== "") obj[k] = parseFloat(obj[k]);
596
+ }
597
+ };
598
+ parseObj(actual);
599
+
600
+ if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
601
+ if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
602
+ if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
603
+ if (actual.scales) {
604
+ for (let k in actual.scales) {
605
+ CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
606
+ }
607
+ }
608
+ console.log("Configurazione caricata con successo dall'API ufficiale.");
609
+ return;
610
+ }
611
+ }
612
+ } catch (e) { }
613
+ }
614
+ console.warn("Impossibile caricare la configurazione. Verificare 'Anonymous Read' nelle impostazioni di Signal K.");
615
+ }
574
616
 
575
617
  for (let url of urls) {
576
618
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {