Files
MagicMirror/js/systeminformation.js
Kristjan ESPERANTO d203fefed1 feat(systeminfo): include Git hash and branch in system information log (#4167)
I suggest to add the commit hash and branch to the system information.
This should help trouble shooting issues from developers. Like in #4165.

### before

```
####  System Information  ####
- SYSTEM:   manufacturer: Micro-Star International Co., Ltd.; model: MS-7D75; virtual: false; MM: v2.37.0-develop
- OS:       ...
...
```

### after

```
####  System Information  ####
- MM:       version: v2.37.0-develop; git: 03e4eef3d; branch: develop
- SYSTEM:   manufacturer: Micro-Star International Co., Ltd.; model: MS-7D75; virtual: false
- OS:       ...
...
```
2026-05-27 23:25:49 +02:00

50 lines
2.3 KiB
JavaScript

const os = require("node:os");
const { execFileSync } = require("node:child_process");
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");
let mmGitHash = "";
let mmGitBranch = "";
try {
mmGitHash = execFileSync("git", ["rev-parse", "--short", "HEAD"], { encoding: "utf8" }).trim();
mmGitBranch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], { encoding: "utf8" }).trim();
} catch {
// not a git repo or git not available
}
const logSystemInformation = async () => {
try {
const system = await si.system();
const osInfo = await si.osInfo();
const versions = await si.versions();
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 ####",
`- MM: version: v${mmVersion}${mmGitHash ? `; git: ${mmGitHash}` : ""}${mmGitBranch ? `; branch: ${mmGitBranch}` : ""}`,
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}`,
`- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`,
`- VERSIONS: electron: ${process.env.ELECTRON_VERSION}; used node: ${process.env.USED_NODE_VERSION}; 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();