From 3e064be8020ed1eccc5cddcac5ab355320ebccb5 Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 7 Jul 2022 11:06:12 +0200 Subject: m. working on features scoots doesn't want to work on --- Applications/Debugger.app/Main.js | 70 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'Applications/Debugger.app') 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("")); + }).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.", -- cgit