[Entry] Hook first module factory to init bundle
This commit is contained in:
parent
f66e62d13b
commit
0dae5b17e5
1 changed files with 20 additions and 10 deletions
30
src/entry.ts
30
src/entry.ts
|
@ -1,15 +1,25 @@
|
||||||
import { ClientInfoManager } from "@lib/native";
|
import { ClientInfoManager } from "@lib/native";
|
||||||
|
import { after } from "@lib/patcher";
|
||||||
|
|
||||||
// This logs in the native logging implementation, e.g. logcat
|
// This logs in the native logging implementation, e.g. logcat
|
||||||
console.log("Hello from Vendetta!");
|
console.log("Hello from Vendetta!");
|
||||||
|
|
||||||
import(".").then((m) => m.default()).catch((e) => {
|
async function initBundle() {
|
||||||
console.log(e?.stack ?? e.toString());
|
try {
|
||||||
alert([
|
await import(".").then(i => i.default());
|
||||||
"Failed to load Vendetta!\n",
|
} catch (e: any) {
|
||||||
`Build Number: ${ClientInfoManager.Build}`,
|
console.error(e?.stack ?? e?.toString());
|
||||||
// @ts-expect-error, replaced in build script
|
alert([
|
||||||
`Vendetta: ${__vendettaVersion}`,
|
"Failed to load Vendetta!\n",
|
||||||
e?.stack || e.toString(),
|
`Build Number: ${ClientInfoManager.Build}`,
|
||||||
].join("\n"));
|
// @ts-expect-error, replaced in build script
|
||||||
});
|
`Vendetta: ${__vendettaVersion}`,
|
||||||
|
e?.stack ?? e?.toString(),
|
||||||
|
].join("\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Discord iOS 178.0 (43557) introduced some changes that caused our bundle to load too early, resulting in the app crashing.
|
||||||
|
// As a workaround, we hook into the factory function of the first module that loads after the bundle to init the bundle.
|
||||||
|
// This delays our bundle initialization to a certain point where window.modules is ready.
|
||||||
|
after("factory", Object.values(window.modules).find(m => m.factory), initBundle, true);
|
||||||
|
|
Loading…
Reference in a new issue