[Init] Implement error dialog for failed mod loading (#37)

* [Main] Implement error dialog for failed mod loading

* [Main] Initialize Vendetta from entry.js
This commit is contained in:
Amsyar Rasyiq 2023-03-16 00:36:12 +08:00 committed by GitHub
parent 388b306e88
commit 7dc0b1286a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 25 deletions

View file

@ -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);

18
entry.js Normal file
View file

@ -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());
}
})();

View file

@ -7,11 +7,7 @@ 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!");
(async () => {
try {
export default async () => {
// Load everything in parallel
const unloads = await Promise.all([
patchLogHook(),
@ -29,7 +25,4 @@ console.log("Hello from Vendetta!");
// We good :)
logger.log("Vendetta is ready!");
} catch (e: any) {
alert(`Vendetta failed to initialize... ${e.stack || e.toString()}`);
}
})();
}