[Global] Code cleanup pass
This commit is contained in:
parent
ffbb507125
commit
85d0bd263b
30 changed files with 65 additions and 80 deletions
|
@ -5,7 +5,7 @@ import { after } from "@lib/patcher";
|
|||
let commands: ApplicationCommand[] = [];
|
||||
|
||||
export function patchCommands() {
|
||||
const unpatch = after("getBuiltInCommands", commandsModule, (args, res) => res.concat(commands));
|
||||
const unpatch = after("getBuiltInCommands", commandsModule, (_, res) => res.concat(commands));
|
||||
return () => {
|
||||
commands = [];
|
||||
unpatch();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { RNConstants } from "@types";
|
||||
import { ReactNative as RN } from "@metro/common";
|
||||
import { after } from "@lib/patcher";
|
||||
import { ClientInfoManager, DeviceManager, BundleUpdaterManager } from "@lib/native";
|
||||
import { getCurrentTheme, selectTheme } from "@lib/themes";
|
||||
import { ClientInfoManager, DeviceManager, BundleUpdaterManager } from "@lib/native";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { showToast } from "@ui/toasts";
|
||||
import settings from "@lib/settings";
|
||||
|
|
|
@ -11,8 +11,7 @@ function onDispatch({ locale }: { locale: string }) {
|
|||
// Theming
|
||||
// Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts
|
||||
try {
|
||||
const theme = ThemeStore.theme || "dark";
|
||||
ThemeManager.overrideTheme(theme);
|
||||
ThemeManager.overrideTheme(ThemeStore?.theme ?? "dark");
|
||||
if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) AMOLEDThemeManager.setAMOLEDThemeEnabled(true);
|
||||
} catch(e) {
|
||||
logger.error("Failed to fix theme...", e);
|
||||
|
|
|
@ -4,14 +4,12 @@ import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
|
|||
declare const __r: (moduleId: number) => any;
|
||||
|
||||
// Function to blacklist a module, preventing it from being searched again
|
||||
function blacklist(id: number) {
|
||||
Object.defineProperty(window.modules, id, {
|
||||
value: window.modules[id],
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
})
|
||||
}
|
||||
const blacklist = (id: number) => Object.defineProperty(window.modules, id, {
|
||||
value: window.modules[id],
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
|
||||
// Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules
|
||||
for (const key in window.modules) {
|
||||
|
@ -34,25 +32,21 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
|
|||
|
||||
if (!modules[id].isInitialized) try {
|
||||
__r(id);
|
||||
} catch {};
|
||||
} catch {}
|
||||
|
||||
if (!module) {
|
||||
blacklist(id);
|
||||
continue;
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
if (module.default && module.__esModule && filter(module.default)) {
|
||||
if (single) return module.default;
|
||||
found.push(module.default);
|
||||
}
|
||||
if (module.default && module.__esModule && filter(module.default)) {
|
||||
if (single) return module.default;
|
||||
found.push(module.default);
|
||||
}
|
||||
|
||||
if (filter(module)) {
|
||||
if (single) return module;
|
||||
else found.push(module);
|
||||
}
|
||||
} catch (e: Error | any) {
|
||||
console.error(`Failed to filter modules... ${e.stack || e.toString()}`);
|
||||
if (filter(module)) {
|
||||
if (single) return module;
|
||||
else found.push(module);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { PluginManifest, Plugin } from "@types";
|
||||
import { safeFetch } from "@lib/utils";
|
||||
import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage";
|
||||
import { MMKVManager } from "@lib/native";
|
||||
import settings from "@lib/settings";
|
||||
import logger, { logModule } from "@lib/logger";
|
||||
import safeFetch from "@utils/safeFetch";
|
||||
import settings from "@lib/settings";
|
||||
|
||||
type EvaledPlugin = {
|
||||
onLoad?(): void;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { initThemes } from "@lib/themes";
|
||||
|
||||
// Hoist required modules
|
||||
// This used to be in filters.ts, but things became convoluted
|
||||
|
||||
import { initThemes } from "@lib/themes";
|
||||
|
||||
// Early find logic
|
||||
const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Emitter, StorageBackend } from "@types";
|
||||
import createEmitter from "../emitter";
|
||||
import createEmitter from "@lib/emitter";
|
||||
|
||||
const emitterSymbol = Symbol("emitter accessor");
|
||||
const syncAwaitSymbol = Symbol("wrapSync promise accessor");
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ReactNative as RN, chroma } from "@metro/common";
|
|||
import { findByName, findByProps } from "@metro/filters";
|
||||
import { instead, after } from "@lib/patcher";
|
||||
import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage";
|
||||
import { safeFetch } from "@utils";
|
||||
import { safeFetch } from "@lib/utils";
|
||||
|
||||
//! As of 173.10, early-finding this does not work.
|
||||
// Somehow, this is late enough, though?
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { SearchFilter } from "@types";
|
||||
import findInTree from "@utils/findInTree";
|
||||
import { findInTree } from "@lib/utils";
|
||||
|
||||
export default (tree: { [key: string]: any }, filter: SearchFilter): any => findInTree(tree, filter, {
|
||||
walkable: ["props", "children", "child", "sibling"],
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Makes mass-importing utils cleaner, chosen over moving utils to one file
|
||||
export { default as findInReactTree } from "@utils/findInReactTree";
|
||||
export { default as findInTree } from "@utils/findInTree";
|
||||
export { default as safeFetch } from "@utils/safeFetch";
|
||||
export { default as unfreeze } from "@utils/unfreeze";
|
||||
export { default as without } from "@utils/without";
|
||||
|
||||
export { default as findInReactTree } from "@lib/utils/findInReactTree";
|
||||
export { default as findInTree } from "@lib/utils/findInTree";
|
||||
export { default as safeFetch } from "@lib/utils/safeFetch";
|
||||
export { default as unfreeze } from "@lib/utils/unfreeze";
|
||||
export { default as without } from "@lib/utils/without";
|
|
@ -15,7 +15,7 @@ import * as toasts from "@ui/toasts";
|
|||
import * as alerts from "@ui/alerts";
|
||||
import * as assets from "@ui/assets";
|
||||
import * as color from "@ui/color";
|
||||
import * as utils from "@utils";
|
||||
import * as utils from "@lib/utils";
|
||||
|
||||
export default async (unloads: any[]): Promise<VendettaObject> => ({
|
||||
patcher: utils.without(patcher, "unpatchAll"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue