Skip to content

Commit fadb9e9

Browse files
committed
move stuff to systeminformation.js
1 parent 84bc50d commit fadb9e9

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

js/systeminformation.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +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:
14
const mmVersion = require("../package").version;
2-
const { logSystemInformation } = require("./utils");
5+
const Log = require("./logger");
36

7+
const logSystemInformation = async (mirrorVersion) => {
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: ${mirrorVersion}`,
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;
439
logSystemInformation(`v${mmVersion}`);

js/utils.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
const os = require("node:os");
21
const fs = require("node:fs");
3-
const si = require("systeminformation");
4-
const Log = require("./logger"); // needed with relative path because logSystemInformation is called in an own process in app.js
2+
const Log = require("logger");
53

64
const modulePositions = []; // will get list from index.html
75
const regionRegEx = /"region ([^"]*)/i;
@@ -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)