From a77f8f5c038814630b0857bc9486281db895cd4e Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sun, 28 May 2023 17:19:21 +0200 Subject: [PATCH] added mesh gui view --- gui/main.js | 31 ++++++++++++ gui/preload-main.js | 4 ++ gui/preload-mesh.js | 102 +++++++++++++++++++++++++++++++++++++++ gui/sock.js | 1 + gui/src/index.html | 4 ++ gui/src/mesh-module.html | 67 +++++++++++++++++++++++++ 6 files changed, 209 insertions(+) create mode 100644 gui/preload-mesh.js create mode 100644 gui/src/mesh-module.html diff --git a/gui/main.js b/gui/main.js index 482c8559..28fe54fc 100644 --- a/gui/main.js +++ b/gui/main.js @@ -165,6 +165,7 @@ fs.mkdir(receivedFilesFolder, { let win = null; let data = null; let logViewer = null; +let meshViewer = null; var daemonProcess = null; // create a splash screen @@ -248,6 +249,29 @@ function createWindow() { } }); + meshViewer = new BrowserWindow({ + height: 900, + width: 600, + show: false, + //parent: win, + webPreferences: { + preload: require.resolve("./preload-mesh.js"), + nodeIntegration: true, + }, + }); + + meshViewer.loadFile("src/mesh-module.html"); + meshViewer.setMenuBarVisibility(false); + + // Emitted when the window is closed. + meshViewer.on("close", function (evt) { + if (meshViewer !== null) { + evt.preventDefault(); + meshViewer.hide(); + } else { + this.close(); + } + }); // Emitted when the window is closed. win.on("closed", function () { console.log("closing all windows....."); @@ -398,6 +422,7 @@ ipcMain.on("request-update-daemon-ip", (event, data) => { ipcMain.on("request-update-tnc-state", (event, arg) => { win.webContents.send("action-update-tnc-state", arg); + meshViewer.send("action-update-mesh-table", arg) //data.webContents.send('action-update-tnc-state', arg); }); @@ -460,6 +485,11 @@ ipcMain.on("request-open-tnc-log", () => { logViewer.show(); }); +ipcMain.on("request-open-mesh-module", () => { + meshViewer.show(); +}); + + //file selector ipcMain.on("get-file-path", (event, data) => { dialog @@ -878,6 +908,7 @@ function close_all() { win.destroy(); chat.destroy(); logViewer.destroy(); + meshViewer.destroy(); app.quit(); } diff --git a/gui/preload-main.js b/gui/preload-main.js index b2da4b9a..8aecdb1c 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -1582,6 +1582,10 @@ window.addEventListener("DOMContentLoaded", () => { ipcRenderer.send("request-open-tnc-log"); }); + document.getElementById("meshtable").addEventListener("click", () => { + ipcRenderer.send("request-open-mesh-module"); + }); + // stopTNC button clicked document.getElementById("stopTNC").addEventListener("click", () => { if (!confirm("Stop the TNC?")) return; diff --git a/gui/preload-mesh.js b/gui/preload-mesh.js new file mode 100644 index 00000000..d9a5c8f8 --- /dev/null +++ b/gui/preload-mesh.js @@ -0,0 +1,102 @@ +const path = require("path"); +const { ipcRenderer } = require("electron"); + +// https://stackoverflow.com/a/26227660 +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); +var configFolder = path.join(appDataFolder, "FreeDATA"); +var configPath = path.join(configFolder, "config.json"); +const config = require(configPath); + +// WINDOW LISTENER +window.addEventListener("DOMContentLoaded", () => { + document + .getElementById("enable_mesh") + .addEventListener("click", () => { + if (document.getElementById("enable_mesh").checked) { + display_class("table-info", true); + } else { + display_class("table-info", false); + } + }); + + +}); + + +ipcRenderer.on("action-update-mesh-table", (event, arg) => { + var routes = arg.routing_table; + var tbl = document.getElementById("mesh-table"); + tbl.innerHTML = ""; + + +for (i = 0; i < routes.length; i++) { + + + /* + var myGrid = document.getElementById("myGrid").value; + try { + var dist = parseInt(distance(myGrid, dxGrid)) + " km"; + document.getElementById("dataModalPingDistance").textContent = dist; + } catch { + document.getElementById("dataModalPingDistance").textContent = "---"; + } + document.getElementById("dataModalPingDB").textContent = + arg.stations[i]["snr"]; + } + */ + + + + var row = document.createElement("tr"); + + var timestamp = document.createElement("td"); + var timestampText = document.createElement("span"); + timestampText.innerText = routes[i]["timestamp"]; + timestamp.appendChild(timestampText); + + var dxcall = document.createElement("td"); + var dxcallText = document.createElement("span"); + dxcallText.innerText = routes[i]["dxcall"]; + dxcall.appendChild(dxcallText); + + var router = document.createElement("td"); + var routerText = document.createElement("span"); + routerText.innerText = routes[i]["router"]; + router.appendChild(routerText); + + var hops = document.createElement("td"); + var hopsText = document.createElement("span"); + hopsText.innerText = routes[i]["hops"]; + hops.appendChild(hopsText); + + var score = document.createElement("td"); + var scoreText = document.createElement("span"); + scoreText.innerText = routes[i]["score"]; + score.appendChild(scoreText); + + var snr = document.createElement("td"); + var snrText = document.createElement("span"); + snrText.innerText = routes[i]["snr"]; + snr.appendChild(snrText); + + row.appendChild(timestamp); + row.appendChild(dxcall); + row.appendChild(router); + row.appendChild(hops); + row.appendChild(score); + row.appendChild(snr); + + + + tbl.appendChild(row); +} + + + // scroll to bottom of page + // https://stackoverflow.com/a/11715670 + window.scrollTo(0, document.body.scrollHeight); +}); diff --git a/gui/sock.js b/gui/sock.js index ec3893c9..eeb1c487 100644 --- a/gui/sock.js +++ b/gui/sock.js @@ -218,6 +218,7 @@ client.on("data", function (socketdata) { total_bytes: data["total_bytes"], arq_transmission_percent: data["arq_transmission_percent"], stations: data["stations"], + routing_table: data["routing_table"], beacon_state: data["beacon_state"], hamlib_status: data["hamlib_status"], listen: data["listen"], diff --git a/gui/src/index.html b/gui/src/index.html index eff74b0d..fb187444 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -219,6 +219,10 @@ TNC Live Logs +