MagicMirror/js/utils.js

86 lines
3.3 KiB
JavaScript
Raw Normal View History

const path = require("node:path");
const rootPath = path.resolve(`${__dirname}/../`);
const Log = require(`${rootPath}/js/logger.js`);
const os = require("node:os");
const fs = require("node:fs");
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
const si = require("systeminformation");
2017-02-28 01:41:21 -03:00
const modulePositions = []; // will get list from index.html
const regionRegEx = /"region ([^"]*)/i;
const indexFileName = "index.html";
const discoveredPositionsJSFilename = "js/positions.js";
2021-01-05 18:37:01 +01:00
module.exports = {
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
refactor: optimize system information logging (#3843) Additionally to #3839 did some rework on the system logging. - feat: include MagicMirror version (like Sam suggested in #3839) - refactor: use more variables to get the string array less complex - refactor: get `installedNodeVersion` from si.versions (with that it was possible to drop the import of `execSync`) - fix: `used node` was always the same as the installed one. Since Electron comes with its own node version, this can differ. This is now shown correctly (again?) with the use of `process.version`. - a bit formatting I think these changes make the code easier to understand and therefore easier to maintain. Except for showing the MM version there is no big difference for the user. ## before ```bash ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2716.90 MB; used: 13209.04 MB - UPTIME: 259 minutes ``` ## after ```bash #### System Information #### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; MM: 2.33.0-develop - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.1; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2814.49 MB; used: 13110.96 MB - OTHERS: uptime: 260 minutes; timeZone: Europe/Berlin ```
2025-07-12 08:24:09 +02:00
async logSystemInformation (mirrorVersion) {
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
try {
refactor: optimize system information logging (#3843) Additionally to #3839 did some rework on the system logging. - feat: include MagicMirror version (like Sam suggested in #3839) - refactor: use more variables to get the string array less complex - refactor: get `installedNodeVersion` from si.versions (with that it was possible to drop the import of `execSync`) - fix: `used node` was always the same as the installed one. Since Electron comes with its own node version, this can differ. This is now shown correctly (again?) with the use of `process.version`. - a bit formatting I think these changes make the code easier to understand and therefore easier to maintain. Except for showing the MM version there is no big difference for the user. ## before ```bash ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2716.90 MB; used: 13209.04 MB - UPTIME: 259 minutes ``` ## after ```bash #### System Information #### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; MM: 2.33.0-develop - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.1; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2814.49 MB; used: 13110.96 MB - OTHERS: uptime: 260 minutes; timeZone: Europe/Berlin ```
2025-07-12 08:24:09 +02:00
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);
feat: enhance system information logging format and include additional env and RAM details (#3839) When we introduced the system information, I selected `###` as the prefix for each line. While this doesn't cause any problems in the terminal, when someone copies the output to an issue or the forum, every line is formatted as a heading, which is not ideal. That's why I made some rework and suggest these changes. In addition to the formatting changes, I added some env and RAM details plus the uptime. These are just suggestions – if you don't think they're worth adding, I'm happy to remove them. We wanted to keep this block compact. @sdetweil, since you are often on the front line with the error messages from users: Is there any information missing in the system block that you often have to request additionally? Feel free to request changes! ----- ## in the terminal ### before ``` [2025-07-09 21:58:36.943] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ``` ----- ### after ``` [2025-07-09 21:57:47.604] [INFO] ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: undefined; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 967.75 MB; used: 14957.70 MB - UPTIME: 172 minutes ``` ----- ## as markdown (in an issue or the forum) ### before [2025-07-09 21:58:36.943] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ----- ### after [2025-07-09 21:57:47.604] [INFO] ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: undefined; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 967.75 MB; used: 14957.70 MB - UPTIME: 172 minutes
2025-07-10 07:39:23 +02:00
let systemDataString = [
refactor: optimize system information logging (#3843) Additionally to #3839 did some rework on the system logging. - feat: include MagicMirror version (like Sam suggested in #3839) - refactor: use more variables to get the string array less complex - refactor: get `installedNodeVersion` from si.versions (with that it was possible to drop the import of `execSync`) - fix: `used node` was always the same as the installed one. Since Electron comes with its own node version, this can differ. This is now shown correctly (again?) with the use of `process.version`. - a bit formatting I think these changes make the code easier to understand and therefore easier to maintain. Except for showing the MM version there is no big difference for the user. ## before ```bash ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2716.90 MB; used: 13209.04 MB - UPTIME: 259 minutes ``` ## after ```bash #### System Information #### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; MM: 2.33.0-develop - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.1; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2814.49 MB; used: 13110.96 MB - OTHERS: uptime: 260 minutes; timeZone: Europe/Berlin ```
2025-07-12 08:24:09 +02:00
"\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}`
feat: enhance system information logging format and include additional env and RAM details (#3839) When we introduced the system information, I selected `###` as the prefix for each line. While this doesn't cause any problems in the terminal, when someone copies the output to an issue or the forum, every line is formatted as a heading, which is not ideal. That's why I made some rework and suggest these changes. In addition to the formatting changes, I added some env and RAM details plus the uptime. These are just suggestions – if you don't think they're worth adding, I'm happy to remove them. We wanted to keep this block compact. @sdetweil, since you are often on the front line with the error messages from users: Is there any information missing in the system block that you often have to request additionally? Feel free to request changes! ----- ## in the terminal ### before ``` [2025-07-09 21:58:36.943] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ``` ----- ### after ``` [2025-07-09 21:57:47.604] [INFO] ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: undefined; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 967.75 MB; used: 14957.70 MB - UPTIME: 172 minutes ``` ----- ## as markdown (in an issue or the forum) ### before [2025-07-09 21:58:36.943] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 ### VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 ### OTHER: timeZone: Europe/Berlin; ELECTRON_ENABLE_GPU: undefined ----- ### after [2025-07-09 21:57:47.604] [INFO] ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 24.2.0; installed node: 24.2.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: undefined; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 967.75 MB; used: 14957.70 MB - UPTIME: 172 minutes
2025-07-10 07:39:23 +02:00
].join("\n");
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
Log.info(systemDataString);
// Return is currently only for jest
return systemDataString;
refactor: optimize system information logging (#3843) Additionally to #3839 did some rework on the system logging. - feat: include MagicMirror version (like Sam suggested in #3839) - refactor: use more variables to get the string array less complex - refactor: get `installedNodeVersion` from si.versions (with that it was possible to drop the import of `execSync`) - fix: `used node` was always the same as the installed one. Since Electron comes with its own node version, this can differ. This is now shown correctly (again?) with the use of `process.version`. - a bit formatting I think these changes make the code easier to understand and therefore easier to maintain. Except for showing the MM version there is no big difference for the user. ## before ```bash ##### System Information ##### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; timeZone: Europe/Berlin - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.0; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js; WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2716.90 MB; used: 13209.04 MB - UPTIME: 259 minutes ``` ## after ```bash #### System Information #### - SYSTEM: manufacturer: Notebook; model: N650DU; virtual: false; MM: 2.33.0-develop - OS: platform: linux; distro: Debian GNU/Linux; release: 12; arch: x64; kernel: 5.10.0-20-amd64 - VERSIONS: electron: 36.3.2; used node: 22.15.1; installed node: 22.15.0; npm: 10.9.0; pm2: 6.0.6 - ENV: XDG_SESSION_TYPE: wayland; MM_CONFIG_FILE: config/config_MMM-PublicTransportHafas.js WAYLAND_DISPLAY: wayland-0; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined - RAM: total: 15925.45 MB; free: 2814.49 MB; used: 13110.96 MB - OTHERS: uptime: 260 minutes; timeZone: Europe/Berlin ```
2025-07-12 08:24:09 +02:00
} catch (error) {
Log.error(error);
Add systeminfo (#3331) This is a first attempt to bring additional system information into the console (see #3328). It's certainly not yet perfect, but with the PR we have a better basis for discussion. I tried to keep the output small so that we get as much information as possible in screenshots. This is how it looks on my development system. ```bash [03.01.2024 00:50.19.226] [INFO] System information: ### SYSTEM: manufacturer: Notebook; model: N650DU; raspberry: undefined; virtual: false ### OS: platform: linux; distro: Debian GNU/Linux; release: 12 ### VERSIONS: MagicMirror: 2.27.0-develop; electron: 27.2.0; kernel: 5.10.0-20-amd64; node: 21.1.0; npm: 10.2.4; pm2: 5.3.0; docker: 20.10.24+dfsg1 ``` Why is it still a draft: - [x] I have doubts that utils.js is the right place for the function. What do you think? => Update: As long as there is no better idea, it stays there. - [x] Instead of working through all wishes you expressed in the issue #3328, I only implemented what was easy to achieve. And wanted to hear what you think about this approach. => Update: Some added. Of course, more information could be added later, as soon as experience has been gained in productive use. - [x] I don't quite like the introductory line ("The following lines provide information..."). Should I perhaps simply replace it with "System information:"? => Update: Changed to "System information:" [Here](https://github.com/sebhildebrandt/systeminformation#function-reference-and-os-support) you can see what information we could easily add with the systeminformation package. It would be interesting how the raspberry field is filled on a raspi system and with docker there should be another line, but I can't easily test that now.
2024-01-04 22:38:53 +01:00
}
},
// return all available module positions
getAvailableModulePositions () {
return modulePositions;
},
// return if position is on modulePositions Array (true/false)
moduleHasValidPosition (position) {
if (this.getAvailableModulePositions().indexOf(position) === -1) return false;
return true;
},
getModulePositions () {
// if not already discovered
if (modulePositions.length === 0) {
// get the lines of the index.html
const lines = fs.readFileSync(indexFileName).toString().split("\n");
// loop thru the lines
lines.forEach((line) => {
// run the regex on each line
const results = regionRegEx.exec(line);
// if the regex returned something
if (results && results.length > 0) {
// get the position parts and replace space with underscore
const positionName = results[1].replace(" ", "_");
// add it to the list
modulePositions.push(positionName);
}
});
try {
fs.writeFileSync(discoveredPositionsJSFilename, `const modulePositions=${JSON.stringify(modulePositions)}`);
}
catch (error) {
Log.error("unable to write js/positions.js with the discovered module positions\nmake the MagicMirror/js folder writeable by the user starting MagicMirror");
}
}
// return the list to the caller
return modulePositions;
2017-02-28 01:41:21 -03:00
}
};