diff --git a/js/app.js b/js/app.js index 43e1119bc9..263e5b4e0f 100644 --- a/js/app.js +++ b/js/app.js @@ -3,6 +3,7 @@ require("./alias-resolver"); const fs = require("node:fs"); const path = require("node:path"); +const Spawn = require("node:child_process").spawn; const envsub = require("envsub"); const Log = require("logger"); @@ -25,7 +26,7 @@ global.mmTestMode = process.env.mmTestMode === "true"; Log.log(`Starting MagicMirror: v${global.version}`); // Log system information. -Utils.logSystemInformation(global.version); +Spawn("node ./js/systeminformation.js", { cwd: this.root_path, shell: true, detached: true, stdio: "inherit" }); if (process.env.MM_CONFIG_FILE) { global.configuration_file = process.env.MM_CONFIG_FILE.replace(`${global.root_path}/`, ""); diff --git a/js/systeminformation.js b/js/systeminformation.js new file mode 100644 index 0000000000..26ea79fd17 --- /dev/null +++ b/js/systeminformation.js @@ -0,0 +1,39 @@ +const os = require("node:os"); +const si = require("systeminformation"); +// needed with relative path because logSystemInformation is called in an own process in app.js: +const mmVersion = require("../package").version; +const Log = require("./logger"); + +const logSystemInformation = async () => { + try { + const system = await si.system(); + const osInfo = await si.osInfo(); + const versions = await si.versions(); + + const usedNodeVersion = process.version.replace("v", ""); + const installedNodeVersion = versions.node; + const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2); + const freeRam = (os.freemem() / 1024 / 1024).toFixed(2); + const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2); + + let systemDataString = [ + "\n#### System Information ####", + `- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: v${mmVersion}`, + `- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`, + `- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`, + `- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`, + ` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`, + `- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`, + `- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}` + ].join("\n"); + Log.info(systemDataString); + + // Return is currently only for tests + return systemDataString; + } catch (error) { + Log.error(error); + } +}; + +module.exports = logSystemInformation; +logSystemInformation(); diff --git a/js/utils.js b/js/utils.js index 54a31da1c3..42a651dcc9 100644 --- a/js/utils.js +++ b/js/utils.js @@ -1,6 +1,4 @@ -const os = require("node:os"); const fs = require("node:fs"); -const si = require("systeminformation"); const Log = require("logger"); const modulePositions = []; // will get list from index.html @@ -10,37 +8,6 @@ const discoveredPositionsJSFilename = "js/positions.js"; module.exports = { - async logSystemInformation (mirrorVersion) { - try { - const system = await si.system(); - const osInfo = await si.osInfo(); - const versions = await si.versions(); - - const usedNodeVersion = process.version.replace("v", ""); - const installedNodeVersion = versions.node; - const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2); - const freeRam = (os.freemem() / 1024 / 1024).toFixed(2); - const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2); - - let systemDataString = [ - "\n#### System Information ####", - `- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: ${mirrorVersion}`, - `- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`, - `- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`, - `- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`, - ` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`, - `- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`, - `- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}` - ].join("\n"); - Log.info(systemDataString); - - // Return is currently only for tests - return systemDataString; - } catch (error) { - Log.error(error); - } - }, - // return all available module positions getAvailableModulePositions () { return modulePositions; diff --git a/tests/unit/classes/systeminformation_spec.js b/tests/unit/classes/systeminformation_spec.js new file mode 100644 index 0000000000..d9528c5410 --- /dev/null +++ b/tests/unit/classes/systeminformation_spec.js @@ -0,0 +1,7 @@ +const SystemInformation = require("../../../js/systeminformation"); + +describe("SystemInformation", () => { + it("should output system information", async () => { + await expect(SystemInformation()).resolves.toContain("platform: linux"); + }); +}); diff --git a/tests/unit/classes/utils_spec.js b/tests/unit/classes/utils_spec.js deleted file mode 100644 index 772bdf61df..0000000000 --- a/tests/unit/classes/utils_spec.js +++ /dev/null @@ -1,7 +0,0 @@ -const Utils = require("../../../js/utils"); - -describe("Utils", () => { - it("should output system information", async () => { - await expect(Utils.logSystemInformation()).resolves.toContain("platform: linux"); - }); -});