Use $$vencordOriginal as fallback

This commit is contained in:
Nuckyz 2024-06-12 22:14:52 -03:00
parent 92653eaf96
commit 8d31f3cf62
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -209,6 +209,7 @@ function defineModulesFactoryGetter(id: PropertyKey, factory: PatchedModuleFacto
}, },
set(v: AnyModuleFactory) { set(v: AnyModuleFactory) {
if (factory.$$vencordOriginal != null) { if (factory.$$vencordOriginal != null) {
factory.toString = v.toString.bind(v);
factory.$$vencordOriginal = v; factory.$$vencordOriginal = v;
} else { } else {
factory = v; factory = v;
@ -367,7 +368,7 @@ function patchFactory(id: PropertyKey, factory: AnyModuleFactory) {
} }
if (IS_DEV) { if (IS_DEV) {
return originalFactory.apply(this, args); return patchedFactory.$$vencordOriginal?.apply(this, args);
} }
} }
@ -377,15 +378,19 @@ function patchFactory(id: PropertyKey, factory: AnyModuleFactory) {
factoryReturn = factory.apply(this, args); factoryReturn = factory.apply(this, args);
} catch (err) { } catch (err) {
// Just re-throw Discord errors // Just re-throw Discord errors
if (factory === originalFactory) throw err; if (factory === originalFactory) {
throw err;
}
logger.error("Error in patched module factory", err); logger.error("Error in patched module factory", err);
return originalFactory.apply(this, args); return patchedFactory.$$vencordOriginal?.apply(this, args);
} }
// Webpack sometimes sets the value of module.exports directly, so assign exports to it to make sure we properly handle it // Webpack sometimes sets the value of module.exports directly, so assign exports to it to make sure we properly handle it
exports = module?.exports; exports = module?.exports;
if (exports == null) return factoryReturn; if (exports == null) {
return factoryReturn;
}
// There are (at the time of writing) 11 modules exporting the window // There are (at the time of writing) 11 modules exporting the window
// Make these non enumerable to improve webpack search performance // Make these non enumerable to improve webpack search performance