diff options
author | Minteck <contact@minteck.org> | 2022-07-07 11:06:12 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-07-07 11:06:12 +0200 |
commit | 3e064be8020ed1eccc5cddcac5ab355320ebccb5 (patch) | |
tree | 37ca0fa0141b5600955ce5d001a4c7a7745902a0 | |
parent | 0e9f2dc57e9df8fbc5a5da6d68d1268278aa4129 (diff) | |
download | strawberry-os-mane.tar.gz strawberry-os-mane.tar.bz2 strawberry-os-mane.zip |
-rw-r--r-- | .idea/vcs.xml | 1 | ||||
-rw-r--r-- | Applications/Debugger.app/Main.js | 70 | ||||
-rw-r--r-- | Applications/System Profiler.app/Main.js | 81 | ||||
-rw-r--r-- | Library/CrashHandler.js | 65 | ||||
-rw-r--r-- | Library/SDK/Entrypoint.js | 18 | ||||
-rw-r--r-- | Library/SDK/Modules/Strawberry.Dialog.js | 23 | ||||
-rw-r--r-- | Library/SDK/Modules/Strawberry.MenuBar.js | 15 | ||||
-rw-r--r-- | Library/SDK/Modules/Strawberry.SystemInfo.js | 9 | ||||
-rw-r--r-- | Library/SDK/test.txt | 1 | ||||
-rw-r--r-- | Library/SystemSoftware.js | 9 | ||||
-rwxr-xr-x | Startup.js | 1 | ||||
-rw-r--r-- | StrawKit/Applications/Test MPA Application.app/Main.js | 7 | ||||
-rw-r--r-- | Version | 4 |
13 files changed, 278 insertions, 26 deletions
diff --git a/.idea/vcs.xml b/.idea/vcs.xml index de1cec7..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> - <mapping directory="$PROJECT_DIR$/Library/SDK" vcs="Git" /> </component> </project>
\ No newline at end of file diff --git a/Applications/Debugger.app/Main.js b/Applications/Debugger.app/Main.js index 6e25339..5ab57bd 100644 --- a/Applications/Debugger.app/Main.js +++ b/Applications/Debugger.app/Main.js @@ -8,12 +8,80 @@ module.exports = () => { Strawberry.StartLoad(); Strawberry.WhenLoaded = () => { + global._STRAWBERRY_DEBUG_MODE = true; + load("Strawberry.Dialog"); load("Strawberry.AppManager"); + load("Strawberry.SystemInfo"); + + process.removeAllListeners("uncaughtException"); + process.on('uncaughtException', (error) => { + let systemInfo = require(global._STRAWBERRY_SYSTEM_ROOT + "/Library/SDK/Modules/Strawberry.SystemInfo"); + console.clear(); + + let processes = systemInfo.Processes(); + let stack = error.stack.split("\n") + .filter(i => { + return i.startsWith(" at"); + }) + .map(i => { + return i.split("at ")[1].replace(/(.*) \((.*):(.*):(.*)\)/gm, "$1|$2|$3").split("|") + }) + .filter(i => { + return i.length === 3 + }) + .map(i => { + return { + method: i[0], + file: i[1], + position: parseInt(i[2]), + column: parseInt(i[3]), + line: ( + i[1].startsWith("/") ? + require('fs').readFileSync(i[1]).toString().trim().split("\n")[parseInt(i[2]) - 1].trim() : + null + ) + } + }) + + require('fs').writeFileSync("/tmp/crash.txt", "\n" + + color.underline("Strawberry OS Crash Report") + "\n" + + "\n" + + "You are seeing this message because an error occurred within Strawberry OS itself or an application running on the system. The system has been stopped to prevent further instabilities, and since you have enabled the debugger, additional data has been collected and a crash report is shown." + + "\n" + + "\n" + + "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + "\n" + + "Your error is most likely here:" + "\n" + + " " + stack[0].line + "\n" + + " " + " ".repeat(stack[0].column - 1) + "^" + "\n" + + "\n" + + "If it is not, here is the entire crash report:" + "\n" + + "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + "\n\n" + + color.underline.green("Crash Summary:") + "\n" + + color.green(" Error Code: ") + " 0xF" + require('crypto').createHash('md5').update(error.message).digest('hex').substring(0, 7).toUpperCase() + "\n" + + color.green(" Error Type: ") + error.name + "\n" + + color.green(" Error Message: ") + error.message + "\n" + + "\n" + + color.underline.green("Stack Dump:") + "\n" + + stack.map(i => { + return " " + color.green(i.file) + ": " + i.method + ", line " + i.position + "\n " + (i.line ? chalk.cyan(i.line) : chalk.cyan("<no source link>")); + }).join("\n") + + "\n\n" + + color.underline.green("Open Processes:") + "\n" + + processes.map(i => { return " " + i; }).join("\n") + "\n" + + "\n" + + color.bgGreen.black("Press Q to close this crash report; press Ctrl+Opt+Del to restart your Strawberry device.\n") + ); + require('child_process').spawnSync("bash", [ "-c", "cat /tmp/crash.txt | more -r" ], { stdio: "inherit" }); + console.clear(); + require('fs').unlinkSync("/tmp/crash.txt"); + try { require(global._STRAWBERRY_SYSTEM_ROOT + '/Library/SDK/node_modules/show-terminal-cursor')(); } catch (e) {} + process.exit(); + }) Strawberry.Audio.SystemSound("Strawberry.System.Window"); Strawberry.Dialog.ConfirmLines([ - color.underline("Strawberry Debugger"), + "Strawberry Debugger", "", "The Strawberry Debugger has been enabled. It will stay enabled", "until the system is restarted.", diff --git a/Applications/System Profiler.app/Main.js b/Applications/System Profiler.app/Main.js new file mode 100644 index 0000000..563ed01 --- /dev/null +++ b/Applications/System Profiler.app/Main.js @@ -0,0 +1,81 @@ +// noinspection JSUnresolvedVariable + +module.exports = () => { + Strawberry.App = "System Profiler"; + Strawberry.MultiPanes = true; + Strawberry.Menus = [ + "Quit" + ] + + Strawberry.WhenLoaded = () => { + load("Strawberry.Display"); + load("Strawberry.Menubar"); + } + + Strawberry.Panes[0] = { + name: "System Software", + load: () => {} + } + + Strawberry.Panes[1] = { + name: "Extensions", + load: () => {} + } + + Strawberry.Panes[2] = { + name: "Diagnostics", + load: () => {} + } + + Strawberry.Panes[3] = { + name: "Applications", + load: () => {} + } + + Strawberry.Panes[4] = { + name: "Security and integrity", + load: () => {} + } + + Strawberry.Panes[5] = { + name: "Physical and virtual memory", + load: () => {} + } + + Strawberry.Panes[6] = { + name: "Processors and graphics", + load: () => {} + } + + Strawberry.Panes[7] = { + name: "Applications", + load: () => {} + } + + Strawberry.Panes[8] = { + name: "Disks", + load: () => {} + } + + Strawberry.Panes[9] = { + name: "Startup", + load: () => {} + } + + Strawberry.Panes[10] = { + name: "Network", + load: () => {} + } + + Strawberry.Panes[11] = { + name: "Audio", + load: () => {} + } + + Strawberry.Panes[12] = { + name: "Processes", + load: () => {} + } + + Strawberry.StartLoad(); +}
\ No newline at end of file diff --git a/Library/CrashHandler.js b/Library/CrashHandler.js new file mode 100644 index 0000000..86e14b4 --- /dev/null +++ b/Library/CrashHandler.js @@ -0,0 +1,65 @@ +global._STRAWBERRY_CURRENT_APP = "#SYSTEM#"; + +process.removeAllListeners("uncaughtException"); +process.on('uncaughtException', (error) => { + Strawberry.Tick.Events = []; + Strawberry.ProcessKeyboard = false; + + let lines = [ + "Sorry, a system error occurred.", + "\"" + global._STRAWBERRY_CURRENT_APP + "\"", + " error type " + parseInt(require('crypto').createHash('md5').update(error.name).digest('hex').substring(0, 2), 16) + ]; + + let longest = lines.reduce(function(a, b) { + return a.length > b.length ? a : b + }, ''); + + let col = "red"; + let confirm = "Restart"; + longest = longest + 5; + + let v = Math.round((process.stdout.rows / 2 + 1) - 5 - (lines.length / 2)); + let horizontal = Math.round(process.stdout.columns / 2 - (1 + ((longest.length + 11) / 2))); + + process.stdout.cursorTo(horizontal, v); + process.stdout.write(color.bgWhite[col]("┏━━━━━━" + "━".repeat(longest.length) + "━━━┓")); + + process.stdout.cursorTo(horizontal, v + 1); + process.stdout.write(color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + + let index = 1; + for (let line of lines) { + process.stdout.cursorTo(horizontal, v + 1 + index); + + if (index === 1) { + process.stdout.write(color.bgWhite.black(color[col]("┃") + " " + chalk.bgRed.black("<!>") + " " + line + " ".repeat(longest.length - line.length) + " " + color[col]("┃"))); + } else { + process.stdout.write(color.bgWhite.black(color[col]("┃") + " " + line + " ".repeat(longest.length - line.length) + " " + color[col]("┃"))); + } + + index++; + } + + process.stdout.cursorTo(horizontal, v + 1 + index); + process.stdout.write(color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + + process.stdout.cursorTo(horizontal, v + 2 + index); + process.stdout.write(color.bgWhite[col]("┃ " + " ".repeat(longest.length - (confirm.length + 2)) + chalk.bgBlack.white(" " + confirm + " ") + " ┃")); + + process.stdout.cursorTo(horizontal, v + 3 + index); + process.stdout.write(color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + + process.stdout.cursorTo(horizontal, v + 4 + index); + process.stdout.write(color.bgWhite[col]("┗━━━━━━" + "━".repeat(longest.length) + "━━━┛")); + + process.stdin.on('keypress', (str, key) => { + if (key.sequence === "\r") { + console.clear(); + process.stdout.cursorTo(0, 0); + setTimeout(() => { + require('child_process').spawnSync(process.argv[0], process.argv.filter((_, i) => { return i > 0 }), { stdio: "inherit" }); + }, 1000) + } + }); +})
\ No newline at end of file diff --git a/Library/SDK/Entrypoint.js b/Library/SDK/Entrypoint.js index d55d823..9d7e4a2 100644 --- a/Library/SDK/Entrypoint.js +++ b/Library/SDK/Entrypoint.js @@ -13,10 +13,6 @@ readline.emitKeypressEvents(process.stdin); Launcher = require("../Launcher"); process.stdin.on('keypress', (str, key) => { - for (let func of Strawberry.KeyboardEvents) { - func(key.sequence); - } - if (key.sequence === '\u0003') { require('show-terminal-cursor')(); process.exit(); @@ -24,6 +20,10 @@ process.stdin.on('keypress', (str, key) => { if (!Strawberry.ProcessKeyboard) return; + for (let func of Strawberry.KeyboardEvents) { + func(key.sequence); + } + if (!global._STRAWBERRY_APPMENU_OPEN) { try { Strawberry.MenuBar.Reset(); @@ -362,6 +362,8 @@ global._STRAWBERRY_INIT_APP = () => { ProcessKeyboard: true, WhenLoaded: () => {}, StartLoad: (skipCoolLoading) => { + global._STRAWBERRY_CURRENT_APP = Strawberry.App; + load("Strawberry.Audio"); if (!skipCoolLoading) skipCoolLoading = false; @@ -433,7 +435,7 @@ global._STRAWBERRY_INIT_APP = () => { global._STRAWBERRY_INIT_APP(); global.load = (module) => { - if (require('os').platform() === "linux" && module === "Strawberry.Menubar") { + if (module === "Strawberry.Menubar") { module = "Strawberry.MenuBar"; } @@ -451,11 +453,7 @@ global.load = (module) => { Strawberry[parts[1]] = require("./Modules/" + module); } - if (module === "Strawberry.Menubar") { - load("Strawberry.MenuBar"); - } - - if (require('os').platform() === "linux" && module === "Strawberry.MenuBar") { + if (module === "Strawberry.MenuBar") { Strawberry.Menubar = Strawberry.MenuBar; } }
\ No newline at end of file diff --git a/Library/SDK/Modules/Strawberry.Dialog.js b/Library/SDK/Modules/Strawberry.Dialog.js index 95b0d9d..c5d2bac 100644 --- a/Library/SDK/Modules/Strawberry.Dialog.js +++ b/Library/SDK/Modules/Strawberry.Dialog.js @@ -10,11 +10,11 @@ let self = { process.stdout.write("\n"); } - console.log(" ".repeat(horizontal) + color.bgWhite[col]("╭───" + "─".repeat(message.length) + "───╮")); - console.log(" ".repeat(horizontal) + color.bgWhite[col]("│ " + " ".repeat(message.length) + " │")); - console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("│") + " " + message + " " + color[col]("│"))); - console.log(" ".repeat(horizontal) + color.bgWhite[col]("│ " + " ".repeat(message.length) + " │")); - console.log(" ".repeat(horizontal) + color.bgWhite[col]("╰───" + "─".repeat(message.length) + "───╯")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┏━━━" + "━".repeat(message.length) + "━━━┓")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(message.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("┃") + " " + message + " " + color[col]("┃"))); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(message.length) + " ┃")); + console.log(" ".repeat(horizontal) + color.bgWhite[col]("┗━━━" + "─".repeat(message.length) + "━━━┛")); for (let n = 0; n < (vertical - 3); n++) { process.stdout.write("\n"); @@ -27,7 +27,7 @@ let self = { return a.length > b.length ? a : b }, ''); - global.vertical = Math.round(process.stdout.rows / 2 + 1) - 5; + global.vertical = Math.round(process.stdout.rows / 2 + 1) - 5 - (lines.length / 2); let horizontal = Math.round(process.stdout.columns / 2 - (1 + ((longest.length + 8) / 2))); for (let n = 0; n < vertical; n++) { @@ -37,8 +37,15 @@ let self = { console.log(" ".repeat(horizontal) + color.bgWhite[col]("┏━━━" + "━".repeat(longest.length) + "━━━┓")); console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); + let index = 0; for (let line of lines) { - console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("┃") + " " + line + " ".repeat(longest.length - line.length) + " " + color[col]("┃"))); + if (index === 0) { + console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("┃") + " " + chalk.underline(line) + " ".repeat(longest.length - line.length) + " " + color[col]("┃"))); + } else { + console.log(" ".repeat(horizontal) + color.bgWhite.black(color[col]("┃") + " " + line + " ".repeat(longest.length - line.length) + " " + color[col]("┃"))); + } + + index++; } console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); @@ -46,7 +53,7 @@ let self = { console.log(" ".repeat(horizontal) + color.bgWhite[col]("┃ " + " ".repeat(longest.length) + " ┃")); console.log(" ".repeat(horizontal) + color.bgWhite[col]("┗━━━" + "━".repeat(longest.length) + "━━━┛")); - for (let n = 0; n < (vertical - 3); n++) { + for (let n = 0; n < (vertical - 3 - lines.length); n++) { process.stdout.write("\n"); } diff --git a/Library/SDK/Modules/Strawberry.MenuBar.js b/Library/SDK/Modules/Strawberry.MenuBar.js index 957dcf1..35eced6 100644 --- a/Library/SDK/Modules/Strawberry.MenuBar.js +++ b/Library/SDK/Modules/Strawberry.MenuBar.js @@ -28,8 +28,13 @@ self = { }, Reset: () => { process.stdout.cursorTo(0, 0); - process.stdout.write(color.reset(color.bgBlue(" " + color.black.bgYellowBright(" O ") + " " + menus + " ".repeat(process.stdout.columns - (15 + Strawberry.App.length + menusText.length)) + new Date().toTimeString().substring(0, 5) + " " + name + " "))) - process.stdout.cursorTo(0, process.stdout.rows); + if (global._STRAWBERRY_DEBUG_MODE) { + process.stdout.write(color.reset(color.bgBlue(" " + color.black.bgYellowBright(" O ") + " " + menus + " ".repeat(process.stdout.columns - (15 + Strawberry.App.length + menusText.length + 4)) + new Date().toTimeString().substring(0, 5) + " " + name + " " + color.bgRed.black(" D ") + " "))) + process.stdout.cursorTo(0, process.stdout.rows); + } else { + process.stdout.write(color.reset(color.bgBlue(" " + color.black.bgYellowBright(" O ") + " " + menus + " ".repeat(process.stdout.columns - (15 + Strawberry.App.length + menusText.length)) + new Date().toTimeString().substring(0, 5) + " " + name + " "))) + process.stdout.cursorTo(0, process.stdout.rows); + } }, Active: (item) => { let a = Strawberry.Menus.filter((_, i) => { @@ -129,7 +134,11 @@ self = { }, UpdateClock: () => { - process.stdout.cursorTo(process.stdout.columns - (10 + Strawberry.App.length), 0); + if (global._STRAWBERRY_DEBUG_MODE) { + process.stdout.cursorTo(process.stdout.columns - (10 + Strawberry.App.length + 4), 0); + } else { + process.stdout.cursorTo(process.stdout.columns - (10 + Strawberry.App.length), 0); + } process.stdout.write(color.bgBlue(new Date().toTimeString().substring(0, 5))); process.stdout.cursorTo(0, process.stdout.rows); } diff --git a/Library/SDK/Modules/Strawberry.SystemInfo.js b/Library/SDK/Modules/Strawberry.SystemInfo.js index b52b1c2..cf44c52 100644 --- a/Library/SDK/Modules/Strawberry.SystemInfo.js +++ b/Library/SDK/Modules/Strawberry.SystemInfo.js @@ -57,6 +57,9 @@ module.exports = { if (proc['name'].startsWith(global._STRAWBERRY_SYSTEM_ROOT)) { proc['name'] = "/System" + proc['name'].substring(global._STRAWBERRY_SYSTEM_ROOT.length); } + if (proc['name'].includes("/node_modules/")) { + proc['name'] = chalk.gray(proc['name']); + } if (proc['name'].startsWith("/Strawberry")) { proc['name'] = proc['name'].substring(11); } @@ -107,6 +110,9 @@ module.exports = { if (child['name'].startsWith("/Strawberry")) { child['name'] = child['name'].substring(11); } + if (child['name'].includes("/node_modules/")) { + child['name'] = chalk.gray(child['name']); + } if (child['name'].startsWith("/System/Library/SDK/")) { child['name'] = chalk.yellow(child['name']); } @@ -157,6 +163,9 @@ module.exports = { if (child2['name'].startsWith("/Strawberry")) { child2['name'] = child2['name'].substring(11); } + if (child2['name'].includes("/node_modules/")) { + child2['name'] = chalk.gray(child2['name']); + } if (child2['name'].startsWith("/System/Library/SDK/")) { child2['name'] = chalk.yellow(child2['name']); } diff --git a/Library/SDK/test.txt b/Library/SDK/test.txt new file mode 100644 index 0000000..6fb1bde --- /dev/null +++ b/Library/SDK/test.txt @@ -0,0 +1 @@ +[41m[33mhello[39m[49m
\ No newline at end of file diff --git a/Library/SystemSoftware.js b/Library/SystemSoftware.js index 6737410..471ea26 100644 --- a/Library/SystemSoftware.js +++ b/Library/SystemSoftware.js @@ -69,6 +69,12 @@ global._STRAWBERRY_SYSTEMSOFTWARE_INIT = () => { }, 1000) } + Strawberry.MenuAction[3] = () => { + setTimeout(() => { + Strawberry.AppManager.Start(global._STRAWBERRY_SYSTEM_ROOT + "/Applications/Debugger.app"); + }, 200) + } + Strawberry.DisplayRaw.Write(color.bold.underline("Strawberry OS " + Strawberry.SystemInfo.Version()), 5, 3) Strawberry.DisplayRaw.Write(Math.round(Strawberry.SystemInfo.GetHardwareMemory().Total / 1024) + "K memory", 5, 4) Strawberry.DisplayRaw.Write(Strawberry.SystemInfo.GetProcessors().Count + " processors", 5, 5) @@ -91,4 +97,5 @@ global._STRAWBERRY_SYSTEMSOFTWARE_INIT = () => { initialized = true; } -global._STRAWBERRY_SYSTEMSOFTWARE_INIT();
\ No newline at end of file +global._STRAWBERRY_SYSTEMSOFTWARE_INIT(); +require("./CrashHandler");
\ No newline at end of file @@ -6,6 +6,7 @@ global._STRAWBERRY_APPLICATIONS_ROOT = __dirname + "/StrawKit/Applications"; global._STRAWBERRY_SYSTEMAPPS_ROOT = __dirname + "/Applications"; global._STRAWBERRY_APPMENU_OPEN = false; global._STRAWBERRY_EMULATED = false; +global._STRAWBERRY_DEBUG_MODE = false; let fileList = []; function files(dir) { diff --git a/StrawKit/Applications/Test MPA Application.app/Main.js b/StrawKit/Applications/Test MPA Application.app/Main.js index 20e30c5..f2d70da 100644 --- a/StrawKit/Applications/Test MPA Application.app/Main.js +++ b/StrawKit/Applications/Test MPA Application.app/Main.js @@ -41,5 +41,12 @@ module.exports = () => { } } + Strawberry.Panes[3] = { + name: "Make the app/OS crash", + load: () => { + throw new Error("Activated crash item"); + } + } + Strawberry.StartLoad(); }
\ No newline at end of file @@ -1,2 +1,2 @@ -11 -1.3
\ No newline at end of file +12 +1.4
\ No newline at end of file |