@sailingrotevista/rotevista-dash 1.0.15 → 1.0.17

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 +39 -14
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -74,30 +74,49 @@ const ui = {
74
74
  };
75
75
 
76
76
  // ==========================================================================
77
- // 3. CARICAMENTO CONFIGURAZIONE DA SIGNALK
77
+ // 3. CARICAMENTO CONFIGURAZIONE DAL SERVER (VERSIONE UNIVERSALE)
78
78
  // ==========================================================================
79
79
  async function fetchServerConfig() {
80
- if (window.location.protocol.includes("http")) {
80
+ if (!window.location.protocol.includes("http")) return;
81
+
82
+ // Elenco di tutti i percorsi possibili che SignalK usa per i plugin
83
+ const pluginID = 'rotevista-dash';
84
+ const scopeID = '@sailingrotevista/rotevista-dash';
85
+
86
+ const possibleUrls = [
87
+ `/plugins/${pluginID}/settings`,
88
+ `/plugins/${scopeID}/settings`,
89
+ `/signalk/v1/api/plugins/${pluginID}/settings`,
90
+ `/signalk/v1/api/plugins/${scopeID}/settings`
91
+ ];
92
+
93
+ console.log("Dashboard: Inizio scansione configurazione server...");
94
+
95
+ for (let url of possibleUrls) {
81
96
  try {
82
- // SignalK espone le configurazioni dei plugin a questo indirizzo
83
- const response = await fetch('/signalk/v1/plugins/rotevista-dash/settings');
97
+ const response = await fetch(url);
84
98
  if (response.ok) {
85
99
  const serverConfig = await response.json();
86
100
 
87
- // Sovrascrive CONFIG solo con i valori definiti dall'utente
88
- if (serverConfig && Object.keys(serverConfig).length > 0) {
89
- // Eseguiamo un merge profondo manuale o semplice
90
- if (serverConfig.alarms) Object.assign(CONFIG.alarms, serverConfig.alarms);
91
- if (serverConfig.graphs) Object.assign(CONFIG.graphs, serverConfig.graphs);
92
- if (serverConfig.averages) Object.assign(CONFIG.averages, serverConfig.averages);
101
+ // Se abbiamo ricevuto un oggetto valido
102
+ if (serverConfig && typeof serverConfig === 'object' && Object.keys(serverConfig).length > 0) {
103
+
104
+ // Merge profondo dei dati
105
+ if (serverConfig.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...serverConfig.alarms };
106
+ if (serverConfig.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...serverConfig.graphs };
107
+ if (serverConfig.averages) CONFIG.averages = { ...CONFIG.averages, ...serverConfig.averages };
93
108
 
94
- console.log("Configurazione Plugin caricata da SignalK:", CONFIG);
109
+ console.log("%c SUCCESS: Configurazione caricata da: " + url, "color: #2ecc71; font-weight: bold;");
110
+ console.log("Dati applicati:", CONFIG);
111
+ return; // Esci: abbiamo trovato i dati!
95
112
  }
96
113
  }
97
114
  } catch (e) {
98
- console.log("Errore nel caricamento della configurazione plugin, uso i default.");
115
+ // Ignora l'errore e prova il prossimo URL
99
116
  }
100
117
  }
118
+
119
+ console.warn("Dashboard: Nessuna impostazione trovata sul server (o plugin mai configurato). Uso i default.");
101
120
  }
102
121
 
103
122
  // ==========================================================================
@@ -331,13 +350,19 @@ if (ui.hotspot) {
331
350
  if (c) { for (let i = 0; i < 360; i += 10) { const l = document.createElementNS("http://www.w3.org/2000/svg", "line"); const m = i % 30 === 0; l.setAttribute("x1", "200"); l.setAttribute("y1", "40"); l.setAttribute("x2", "200"); l.setAttribute("y2", (m ? 60 : 50)); l.setAttribute("stroke", m ? "#fff" : "#666"); l.setAttribute("stroke-width", m ? "2" : "1"); l.setAttribute("transform", `rotate(${i}, 200, 200)`); c.appendChild(l); } }
332
351
  })();
333
352
 
334
- // Lancio Applicazione
353
+ // ==========================================================================
354
+ // 9. LANCIO APPLICAZIONE (Sincronizzato)
355
+ // ==========================================================================
335
356
  async function init() {
336
- await fetchServerConfig(); // Scarica prima i settaggi della barca
357
+ // 1. Prima scarichiamo la configurazione dal server
358
+ await fetchServerConfig();
359
+
360
+ // 2. Poi facciamo partire tutto il resto
337
361
  startDisplayLoop();
338
362
  connect();
339
363
  }
340
364
 
365
+ // Avvio al caricamento della pagina
341
366
  window.addEventListener('load', init);
342
367
 
343
368
  function checkDepthAlarm(m) { ui.depth.classList.remove('alarm-warning', 'alarm-danger'); if (m < CONFIG.alarms.depthDanger) { ui.depth.classList.add('alarm-danger'); playBingBing(); } else if (m < CONFIG.alarms.depthWarning) ui.depth.classList.add('alarm-warning'); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {