summaryrefslogtreecommitdiff
path: root/Library/SDK/Modules/Strawberry.SystemInfo.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-07-03 14:23:25 +0200
committerMinteck <contact@minteck.org>2022-07-03 14:23:25 +0200
commitd25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc (patch)
treea8e538a8e32b66fece6a10c198fe700866d1e233 /Library/SDK/Modules/Strawberry.SystemInfo.js
downloadstrawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.tar.gz
strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.tar.bz2
strawberry-os-d25bdc9f3f3f6547d6c023ed7e192fc5913e9bbc.zip
Initial commit
Diffstat (limited to 'Library/SDK/Modules/Strawberry.SystemInfo.js')
-rw-r--r--Library/SDK/Modules/Strawberry.SystemInfo.js204
1 files changed, 204 insertions, 0 deletions
diff --git a/Library/SDK/Modules/Strawberry.SystemInfo.js b/Library/SDK/Modules/Strawberry.SystemInfo.js
new file mode 100644
index 0000000..b52b1c2
--- /dev/null
+++ b/Library/SDK/Modules/Strawberry.SystemInfo.js
@@ -0,0 +1,204 @@
+const os = require('os');
+const fs = require('fs');
+
+module.exports = {
+ GetHardwareMemory: () => {
+ return {
+ Total: os.totalmem(),
+ Free: os.freemem(),
+ Used: os.totalmem() - os.freemem(),
+ }
+ },
+
+ GetProcessors: () => {
+ let cpus = os.cpus();
+ return {
+ Count: cpus.length,
+ Model: cpus.map((i) => {
+ return i.model;
+ })
+ }
+ },
+
+ Version: () => {
+ return fs.readFileSync(_STRAWBERRY_SYSTEM_ROOT + "/Version").toString().trim().split("\n")[1].trim();
+ },
+
+ Processes: () => {
+ let list = [];
+
+ let p = Object.keys(require.cache).map((i) => {
+ let cid = -1;
+ return { name: i, children: [
+ ...(require.cache[i].children.map((j) => {
+ cid++;
+
+ if (require.cache[i].children[cid] === undefined) {
+ return { name: j.id, children: [] }
+ } else {
+ return { name: j.id, children: [
+ ...(require.cache[i].children[cid].children.map((k) => {
+ return { name: k.id, children: null }
+ }))
+ ]
+ }
+ }
+ }))
+ ] }
+ });
+
+ list.push("0000: " + chalk.magenta("strawberry-boot") + (global._STRAWBERRY_EMULATED ? chalk.gray(" (emulated)") : ""));
+
+ let index = 0;
+ let pid = 1;
+ for (let proc of p) {
+ if (proc === undefined) continue;
+
+ if (proc['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
+ proc['name'] = "/System" + proc['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
+ }
+ if (proc['name'].startsWith("/Strawberry")) {
+ proc['name'] = proc['name'].substring(11);
+ }
+ if (proc['name'].startsWith("/System/Library/SDK/")) {
+ proc['name'] = chalk.yellow(proc['name']);
+ }
+ if (proc['name'].startsWith("/System/StrawKit/")) {
+ proc['name'] = chalk.red(proc['name']);
+ }
+ if (proc['name'].startsWith("/System/Applications/")) {
+ proc['name'] = chalk.green(proc['name']);
+ }
+ if (!proc['name'].startsWith("/System")) {
+ proc['name'] = chalk.cyan(proc['name']);
+ }
+
+ let s = pid.toString();
+ let k = s;
+
+ if (s.length > 3) {
+ k = s;
+ } else if (s.length > 2) {
+ k = "0" + s;
+ } else if (s.length > 1) {
+ k = "00" + s;
+ } else {
+ k = "000" + s;
+ }
+
+ let childPrefix = " ";
+ if (index >= p.length - 1) {
+ list.push(" ┗ " + k + ": " + proc['name']);
+ childPrefix = " ";
+ } else {
+ list.push(" ┣ " + k + ": " + proc['name']);
+ childPrefix = "┃";
+ }
+
+ if (proc['children'].length > 0) {
+ let cIndex = 0;
+
+ for (let child of proc['children']) {
+ if (child === undefined) continue;
+
+ if (child['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
+ child['name'] = "/System" + child['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
+ }
+ if (child['name'].startsWith("/Strawberry")) {
+ child['name'] = child['name'].substring(11);
+ }
+ if (child['name'].startsWith("/System/Library/SDK/")) {
+ child['name'] = chalk.yellow(child['name']);
+ }
+ if (!child['name'].startsWith("/System")) {
+ child['name'] = chalk.cyan(child['name']);
+ }
+ if (child['name'].startsWith("/System/StrawKit/")) {
+ child['name'] = chalk.red(child['name']);
+ }
+ if (child['name'].startsWith("/System/Applications/")) {
+ child['name'] = chalk.green(child['name']);
+ }
+
+ pid++;
+ let o = pid.toString();
+ let j = o;
+
+ if (o.length > 3) {
+ j = o;
+ } else if (o.length > 2) {
+ j = "0" + o;
+ } else if (o.length > 1) {
+ j = "00" + o;
+ } else {
+ j = "000" + o;
+ }
+
+ let childChildPrefix = " ";
+ if (cIndex >= proc['children'].length - 1) {
+ childChildPrefix = " ";
+ list.push(" " + childPrefix + " ┗ " + j + ": " + child['name']);
+ } else {
+ childChildPrefix = "┃";
+ list.push(" " + childPrefix + " ┣ " + j + ": " + child['name']);
+ }
+
+ cIndex++;
+
+ if (child['children'].length > 0) {
+ let cIndex = 0;
+
+ for (let child2 of child['children']) {
+ if (child2 === undefined) continue;
+
+ if (child2['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) {
+ child2['name'] = "/System" + child2['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length);
+ }
+ if (child2['name'].startsWith("/Strawberry")) {
+ child2['name'] = child2['name'].substring(11);
+ }
+ if (child2['name'].startsWith("/System/Library/SDK/")) {
+ child2['name'] = chalk.yellow(child2['name']);
+ }
+ if (!child2['name'].startsWith("/System")) {
+ child2['name'] = chalk.cyan(child2['name']);
+ }
+ if (child2['name'].startsWith("/System/StrawKit/")) {
+ child2['name'] = chalk.red(child2['name']);
+ }
+ if (child2['name'].startsWith("/System/Applications/")) {
+ child2['name'] = chalk.green(child2['name']);
+ }
+
+ pid++;
+ let o = pid.toString();
+ let j = o;
+
+ if (o.length > 3) {
+ j = o;
+ } else if (o.length > 2) {
+ j = "0" + o;
+ } else if (o.length > 1) {
+ j = "00" + o;
+ } else {
+ j = "000" + o;
+ }
+
+ if (cIndex >= child['children'].length - 1) {
+ list.push(" " + childPrefix + " " + childChildPrefix + " ┗ " + j + ": " + child2['name']);
+ } else {
+ list.push(" " + childPrefix + " " + childChildPrefix + " ┣ " + j + ": " + child2['name']);
+ }
+
+ cIndex++;
+ }
+ }
+ }
+ }
+
+ pid++; index++;
+ }
+
+ return list;
+ }
+} \ No newline at end of file