[Global] Major refactors, allow unloading!
This commit is contained in:
parent
0be8cdac05
commit
0ba9ee600c
10 changed files with 137 additions and 116 deletions
|
@ -1,23 +1,23 @@
|
|||
import { Asset, Indexable, } from "@types";
|
||||
import { Asset, Indexable } from "@types";
|
||||
import { after } from "@lib/patcher";
|
||||
import { assets } from "@metro/common";
|
||||
|
||||
export const all: Indexable<Asset> = {};
|
||||
|
||||
export function patchAssets() {
|
||||
try {
|
||||
after("registerAsset", assets, (args: Asset[], id: number) => {
|
||||
const asset = args[0];
|
||||
all[asset.name] = { ...asset, id: id };
|
||||
});
|
||||
const unpatch = after("registerAsset", assets, (args: Asset[], id: number) => {
|
||||
const asset = args[0];
|
||||
all[asset.name] = { ...asset, id: id };
|
||||
});
|
||||
|
||||
for (let id = 1; ; id++) {
|
||||
const asset = assets.getAssetByID(id);
|
||||
if (!asset) break;
|
||||
if (all[asset.name]) continue;
|
||||
all[asset.name] = { ...asset, id: id };
|
||||
};
|
||||
} catch {};
|
||||
for (let id = 1; ; id++) {
|
||||
const asset = assets.getAssetByID(id);
|
||||
if (!asset) break;
|
||||
if (all[asset.name]) continue;
|
||||
all[asset.name] = { ...asset, id: id };
|
||||
};
|
||||
|
||||
return unpatch;
|
||||
}
|
||||
|
||||
export const find = (filter: (a: any) => void): Asset | null | undefined => Object.values(all).find(filter);
|
||||
|
|
|
@ -18,7 +18,7 @@ function override() {
|
|||
FluxDispatcher.unsubscribe("I18N_LOAD_START", override);
|
||||
}
|
||||
|
||||
export function fixTheme() {
|
||||
export default function fixTheme() {
|
||||
try {
|
||||
if (ThemeStore) FluxDispatcher.subscribe("I18N_LOAD_START", override);
|
||||
} catch(e) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { NavigationNative } from "@metro/common";
|
||||
import { Forms } from "@ui/components";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { useProxy } from "@lib/storage";
|
||||
|
@ -5,11 +6,8 @@ import settings from "@lib/settings";
|
|||
|
||||
const { FormRow, FormSection, FormDivider } = Forms;
|
||||
|
||||
interface SettingsSectionProps {
|
||||
navigation: any;
|
||||
}
|
||||
|
||||
export default function SettingsSection({ navigation }: SettingsSectionProps) {
|
||||
export default function SettingsSection() {
|
||||
const navigation = NavigationNative.useNavigation();
|
||||
useProxy(settings);
|
||||
|
||||
return (
|
||||
|
|
|
@ -9,10 +9,11 @@ import Developer from "@ui/settings/pages/Developer";
|
|||
|
||||
const screensModule = findByDisplayName("getScreens", false);
|
||||
const settingsModule = findByDisplayName("UserSettingsOverviewWrapper", false);
|
||||
let prevPatches: Function[] = [];
|
||||
|
||||
export default function initSettings() {
|
||||
after("default", screensModule, (args, existingScreens) => {
|
||||
const patches = new Array<Function>;
|
||||
|
||||
patches.push(after("default", screensModule, (args, existingScreens) => {
|
||||
return {
|
||||
...existingScreens,
|
||||
VendettaSettings: {
|
||||
|
@ -28,24 +29,23 @@ export default function initSettings() {
|
|||
render: Developer
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
after("default", settingsModule, (args, ret) => {
|
||||
for (let p of prevPatches) p();
|
||||
prevPatches = [];
|
||||
}));
|
||||
|
||||
after("default", settingsModule, (_, ret) => {
|
||||
const Overview = findInReactTree(ret.props.children, i => i.type && i.type.name === "UserSettingsOverview");
|
||||
|
||||
// Upload logs button gone
|
||||
prevPatches.push(after("renderSupportAndAcknowledgements", Overview.type.prototype, (args, { props: { children } }) => {
|
||||
patches.push(after("renderSupportAndAcknowledgements", Overview.type.prototype, (_, { props: { children } }) => {
|
||||
const index = children.findIndex((c: any) => c?.type?.name === "UploadLogsButton");
|
||||
if (index !== -1) children.splice(index, 1);
|
||||
}));
|
||||
|
||||
prevPatches.push(after("render", Overview.type.prototype, (args, { props: { children } }) => {
|
||||
patches.push(after("render", Overview.type.prototype, (_, { props: { children } }) => {
|
||||
const titles = [i18n.Messages["BILLING_SETTINGS"], i18n.Messages["PREMIUM_SETTINGS"]];
|
||||
const index = children.findIndex((c: any) => titles.includes(c.props.title));
|
||||
children.splice(index === -1 ? 4 : index, 0, <SettingsSection navigation={Overview.props.navigation} />);
|
||||
children.splice(index === -1 ? 4 : index, 0, <SettingsSection />);
|
||||
}));
|
||||
});
|
||||
}, true);
|
||||
|
||||
return () => patches.forEach(p => p());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue