Skip to content

Commit 241921b

Browse files
authored
[core] run systeminformation in subprocess so the info is always displayed (#4002)
If an error occurs during startup, we request system information from the user. The problem is that this information is displayed too late, for example, if the configuration check fails. My initial idea was to use `await Utils.logSystemInformation(global.version);`, but this increased the startup time. Therefore, the function is now called in a subprocess. This approach provides the information in all cases and does not increase the startup time.
1 parent 950f551 commit 241921b

5 files changed

Lines changed: 48 additions & 41 deletions

File tree

js/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require("./alias-resolver");
33

44
const fs = require("node:fs");
55
const path = require("node:path");
6+
const Spawn = require("node:child_process").spawn;
67
const envsub = require("envsub");
78
const Log = require("logger");
89

@@ -25,7 +26,7 @@ global.mmTestMode = process.env.mmTestMode === "true";
2526
Log.log(`Starting MagicMirror: v${global.version}`);
2627

2728
// Log system information.
28-
Utils.logSystemInformation(global.version);
29+
Spawn("node ./js/systeminformation.js", { cwd: this.root_path, shell: true, detached: true, stdio: "inherit" });
2930

3031
if (process.env.MM_CONFIG_FILE) {
3132
global.configuration_file = process.env.MM_CONFIG_FILE.replace(`${global.root_path}/`, "");

js/systeminformation.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const os = require("node:os");
2+
const si = require("systeminformation");
3+
// needed with relative path because logSystemInformation is called in an own process in app.js:
4+
const mmVersion = require("../package").version;
5+
const Log = require("./logger");
6+
7+
const logSystemInformation = async () => {
8+
try {
9+
const system = await si.system();
10+
const osInfo = await si.osInfo();
11+
const versions = await si.versions();
12+
13+
const usedNodeVersion = process.version.replace("v", "");
14+
const installedNodeVersion = versions.node;
15+
const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2);
16+
const freeRam = (os.freemem() / 1024 / 1024).toFixed(2);
17+
const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2);
18+
19+
let systemDataString = [
20+
"\n#### System Information ####",
21+
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: v${mmVersion}`,
22+
`- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`,
23+
`- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`,
24+
`- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`,
25+
` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`,
26+
`- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`,
27+
`- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`
28+
].join("\n");
29+
Log.info(systemDataString);
30+
31+
// Return is currently only for tests
32+
return systemDataString;
33+
} catch (error) {
34+
Log.error(error);
35+
}
36+
};
37+
38+
module.exports = logSystemInformation;
39+
logSystemInformation();

js/utils.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const os = require("node:os");
21
const fs = require("node:fs");
3-
const si = require("systeminformation");
42
const Log = require("logger");
53

64
const modulePositions = []; // will get list from index.html
@@ -10,37 +8,6 @@ const discoveredPositionsJSFilename = "js/positions.js";
108

119
module.exports = {
1210

13-
async logSystemInformation (mirrorVersion) {
14-
try {
15-
const system = await si.system();
16-
const osInfo = await si.osInfo();
17-
const versions = await si.versions();
18-
19-
const usedNodeVersion = process.version.replace("v", "");
20-
const installedNodeVersion = versions.node;
21-
const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2);
22-
const freeRam = (os.freemem() / 1024 / 1024).toFixed(2);
23-
const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2);
24-
25-
let systemDataString = [
26-
"\n#### System Information ####",
27-
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: ${mirrorVersion}`,
28-
`- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`,
29-
`- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`,
30-
`- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`,
31-
` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`,
32-
`- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`,
33-
`- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`
34-
].join("\n");
35-
Log.info(systemDataString);
36-
37-
// Return is currently only for tests
38-
return systemDataString;
39-
} catch (error) {
40-
Log.error(error);
41-
}
42-
},
43-
4411
// return all available module positions
4512
getAvailableModulePositions () {
4613
return modulePositions;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const SystemInformation = require("../../../js/systeminformation");
2+
3+
describe("SystemInformation", () => {
4+
it("should output system information", async () => {
5+
await expect(SystemInformation()).resolves.toContain("platform: linux");
6+
});
7+
});

tests/unit/classes/utils_spec.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)