diff --git a/app/js/websocket.js b/app/js/websocket.js index 6a6b10d7..c499a6f9 100644 --- a/app/js/websocket.js +++ b/app/js/websocket.js @@ -5,7 +5,7 @@ var grblParams = {} var smoothieParams = {} var nostatusyet = true; var safeToUpdateSliders = false; -var laststatus +var laststatus, lastsysinfo var simstopped = false; var bellstate = false; var toast = Metro.toast.create; @@ -555,6 +555,11 @@ function initSocket() { } }); + socket.on('sysinfo', function(sysinfo) { + console.log(sysinfo) + lastsysinfo = sysinfo; + }); + socket.on('status', function(status) { if (nostatusyet) { diff --git a/index.js b/index.js index f1986bf1..918978ca 100644 --- a/index.js +++ b/index.js @@ -381,7 +381,7 @@ var lastCommand = false var gcodeQueue = []; var queuePointer = 0; var statusLoop; -var frontEndUpdateLoop +var frontEndUpdateLoop, sysinfoUpdateLoop var queueCounter; var listPortsLoop; @@ -680,47 +680,27 @@ io.on("connection", function(socket) { debug_log("New IO Connection "); + io.sockets.emit("sysinfo", systemInformation); iosocket = socket; if (status.machine.firmware.type == 'grbl') { - debug_log("Is Grbl"); - - - // // handle Grbl RESET external input - // if (status.machine.inputs.length > 0) { - // for (i = 0; i < status.machine.inputs.length; i++) { - // switch (status.machine.inputs[i]) { - // case 'R': - // // debug_log('PIN: SOFTRESET'); - // safetosend = true; - // break; - // } - // } - // } else { - // setTimeout(function() { debug_log("Emit Grbl: 1"); io.sockets.emit('grbl', status.machine.firmware) - // }, 10000); - // } - // - // if (safetosend != undefined && safetosend == true) { - // setTimeout(function() { - // debug_log("Emit Grbl: 2"); - // io.sockets.emit('grbl', status.machine.firmware) - // }, 10000); - // } - } - // Global Update loop clearInterval(frontEndUpdateLoop); frontEndUpdateLoop = setInterval(function() { io.sockets.emit("status", status); }, 100); + clearInterval(sysinfoUpdateLoop); + sysinfoUpdateLoop = setInterval(function() { + io.sockets.emit("sysinfo", systemInformation); + }, 1000 * 60); + socket.on("scannetwork", function(data) { scanForTelnetDevices(data) }) @@ -3948,5 +3928,92 @@ function friendlyPort(port) { // End USB Port details +// System Info on startup + +const os = require('os'); +const si = require('systeminformation'); + +var systemInformation; + +async function getSystemInfo() { + // Basic OS and hardware details + const osType = os.type(); // 'Linux', 'Darwin' (Mac), 'Windows_NT' + const osPlatform = os.platform(); // 'win32', 'linux', 'darwin', etc. + const osRelease = os.release(); // OS version + const arch = os.arch(); // 'x64', 'arm', 'arm64', etc. + const totalMemory = os.totalmem(); + const networkInterfaces = os.networkInterfaces(); + const cpu = os.cpus(); + + // Additional system information using systeminformation + const [baseboard, graphics, osInfo] = await Promise.all([ + si.baseboard(), + si.graphics(), + si.osInfo() + ]); + + // Prepare systemInformation JSON object + systemInformation = { + operatingSystem: { + type: osType, + platform: osPlatform, + release: osRelease, + arch: arch, + distro: osInfo.distro || "N/A", + version: osInfo.release || "N/A", + codename: osInfo.codename || "N/A", + }, + hardware: { + cpu: cpu.map(core => ({ + model: core.model, + speed: core.speed, // in MHz + times: core.times + })), + motherboard: { + manufacturer: baseboard.manufacturer, + model: baseboard.model, + version: baseboard.version, + serialNumber: baseboard.serial, + }, + gpu: graphics.controllers.map(gpu => ({ + model: gpu.model, + vendor: gpu.vendor, + vram: gpu.vram, // in MB + bus: gpu.bus + })), + memory: { + total: (totalMemory / 1024 / 1024 / 1024).toFixed(2) + " GB", + free: (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + " GB", + }, + }, + network: Object.keys(networkInterfaces).map(iface => ({ + interface: iface, + addresses: networkInterfaces[iface].map(addr => ({ + address: addr.address, + family: addr.family, + internal: addr.internal, + })), + })), + }; + + // Timer to update free memory every minute + setInterval(() => { + systemInformation.hardware.memory.free = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + " GB"; + }, 60000); // 60,000 ms = 1 minute + + // Log the initial systemInformation object + console.log(JSON.stringify(systemInformation, null, 2)); + + // Return the systemInformation object (if needed for further use) + io.sockets.emit("sysinfo", systemInformation); + + return systemInformation; +} + +// Call the function +getSystemInfo().catch(err => console.error("Error retrieving system information:", err)); + + +// End system info on startup process.on('exit', () => debug_log('exit')) \ No newline at end of file diff --git a/package.json b/package.json index 00441280..27f50ab5 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "node-gyp": "^9.3.1", "serialport": "^12.0.0", "socket.io": "^4.6.1", + "systeminformation": "^5.23.5", "xmodem.js": "^0.1.0" }, "main": "index.js", @@ -58,7 +59,7 @@ "category": "public.app-category.graphics-design", "entitlements": "build/entitlements.mac.plist", "entitlementsInherit": "build/entitlements.mac.plist", - "hardenedRuntime":true, + "hardenedRuntime": true, "gatekeeperAssess": false, "notarize": false, "target": { @@ -138,7 +139,9 @@ ], "win": { "sign": "./signWin.js", - "signingHashAlgorithms": ["sha256"], + "signingHashAlgorithms": [ + "sha256" + ], "target": [ { "target": "nsis",