diff options
Diffstat (limited to 'Library')
-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 |
7 files changed, 118 insertions, 22 deletions
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 |