Skip to content

Commit

Permalink
fix: freezing on 221206 and above
Browse files Browse the repository at this point in the history
Co-authored-by: amsyarasyiq <[email protected]>
  • Loading branch information
2 people authored and PalmDevs committed Mar 9, 2024
1 parent 67972ed commit ed6e069
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/lib/metro/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ for (const key in window.modules) {
const id = Number(key);
const module = window.modules[id]?.publicModule?.exports;

if (!module || module === window || module["proxygone"] === null) {
if (!module || module === window || module.proxygone === null) {
blacklist(id);
continue;
}
}

Expand All @@ -33,14 +32,30 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
const id = Number(key);
const module = modules[id]?.publicModule?.exports;

// HACK: Override the function used to report fatal JavaScript errors (that crash the app) to prevent module-requiring side effects
// Credit to @pylixonly (492949202121261067) for the initial version of this fix
if (!modules[id].isInitialized) try {
window.ErrorUtils.setGlobalHandler(() => {});
// Credit to @pylixonly (492949202121261067) for this fix
// https://github.com/pyoncord/Bunny/blob/1d359b663346aa0db12ee844f43a5899291b5fa3/src/lib/metro/filters.ts#L46-L73
// Discord has a polyfill for Function.prototype.toString that causes freezing
const originalToString = Function.prototype.toString;
Object.defineProperty(Function.prototype, "toString", {
value: originalToString,
configurable: true,
writable: false
});

// HACK: Override the function used to report fatal JavaScript errors (that crash the app) to prevent module-requiring side effects
// Credit to @pylixonly (492949202121261067) for the initial version of this fix
window.ErrorUtils.setGlobalHandler(null);
__r(id);
window.ErrorUtils.setGlobalHandler(originalHandler);
} catch {}

Object.defineProperty(Function.prototype, "toString", {
value: originalToString,
configurable: true,
writable: true
});
} catch {}

if (!module) {
blacklist(id);
continue;
Expand All @@ -50,13 +65,14 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
if (single) return module.default;
found.push(module.default);
}

if (filter(module)) {
if (single) return module;
else found.push(module);
found.push(module);
}
}


if (!single) return found;
}

Expand Down

0 comments on commit ed6e069

Please sign in to comment.