From 7dc0b1286a912c3b2179727443215b254e25ddb8 Mon Sep 17 00:00:00 2001 From: Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Thu, 16 Mar 2023 00:36:12 +0800 Subject: [PATCH] [Init] Implement error dialog for failed mod loading (#37) * [Main] Implement error dialog for failed mod loading * [Main] Initialize Vendetta from entry.js --- build.mjs | 6 ++++-- entry.js | 18 ++++++++++++++++++ src/index.ts | 39 ++++++++++++++++----------------------- 3 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 entry.js diff --git a/build.mjs b/build.mjs index 25cbfe9..68a3a9c 100644 --- a/build.mjs +++ b/build.mjs @@ -13,7 +13,7 @@ const commit = (await exec("git rev-parse HEAD")).stdout.trim().substring(0, 7) try { await build({ - entryPoints: ["./src/index.ts"], + entryPoints: ["./entry.js"], outfile: "./dist/vendetta.js", minify: true, bundle: true, @@ -46,10 +46,12 @@ try { define: { __vendettaVersion: `"${commit}"`, }, + footer: { + js: "//# sourceURL=Vendetta", + }, legalComments: "none", }); - await fs.appendFile("./dist/vendetta.js", "//# sourceURL=Vendetta"); console.log("Build successful!"); } catch (e) { console.error("Build failed...", e); diff --git a/entry.js b/entry.js new file mode 100644 index 0000000..73411a5 --- /dev/null +++ b/entry.js @@ -0,0 +1,18 @@ +// This logs in the native logging implementation, e.g. logcat +console.log("Hello from Vendetta!"); + +(async () => { + try { + await (await import("./src/index.ts")).default(); + } catch (ex) { + const dialog = [ + "Failed to load Vendetta!\n", + `Build Number: ${nativeModuleProxy.InfoDictionaryManager.Build}`, + `Vendetta: ${__vendettaVersion}`, + ex?.stack || ex.toString(), + ].join("\n"); + + alert(dialog); + console.error(ex?.stack || ex.toString()); + } +})(); \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 4432600..1ef2bc8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,29 +7,22 @@ import initFixes from "@lib/fixes"; import logger from "@lib/logger"; import windowObject from "@lib/windowObject"; -// This logs in the native logging implementation, e.g. logcat -console.log("Hello from Vendetta!"); +export default async () => { + // Load everything in parallel + const unloads = await Promise.all([ + patchLogHook(), + patchAssets(), + patchCommands(), + initFixes(), + initSettings(), + ]); -(async () => { - try { - // Load everything in parallel - const unloads = await Promise.all([ - patchLogHook(), - patchAssets(), - patchCommands(), - initFixes(), - initSettings(), - ]); + // Assign window object + window.vendetta = await windowObject(unloads); - // Assign window object - window.vendetta = await windowObject(unloads); + // Once done, load plugins + unloads.push(await initPlugins()); - // Once done, load plugins - unloads.push(await initPlugins()); - - // We good :) - logger.log("Vendetta is ready!"); - } catch (e: any) { - alert(`Vendetta failed to initialize... ${e.stack || e.toString()}`); - } -})(); \ No newline at end of file + // We good :) + logger.log("Vendetta is ready!"); +}