Skip to content

Commit

Permalink
fix: loader config not restoring correctly in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmDevs authored and PalmDevs committed Mar 19, 2024
1 parent ec63ce0 commit 0db174a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/def.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ interface Settings {

interface ExtendedVeryPrivateSoonToBeMovedSettings extends Settings {
developmentBuildEnabled: boolean;
__previousCustomLoadUrlConfig?: LoaderConfig['customLoadUrl']
__previousCustomLoadUrlConfig?: LoaderConfig["customLoadUrl"];
}

interface ApplicationCommand {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const THEMES_CHANNEL_ID = "1091880434939482202";
export const GITHUB = "https://github.com/revenge-mod";
export const PROXY_PREFIX = "https://vd-plugins.github.io/proxy";
export const PROXY_PREFIXES = ["https://vd-plugins.github.io/proxy"];
export const DEVELOPMENT_DISTRIBUTION_URL = "https://raw.githubusercontent.com/revenge-mod/builds/dev/revenge.js"
export const DEVELOPMENT_DISTRIBUTION_URL =
"https://raw.githubusercontent.com/revenge-mod/builds/dev/revenge.js";
export const HTTP_REGEX =
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
export const HTTP_REGEX_MULTI =
Expand Down
31 changes: 19 additions & 12 deletions src/lib/debug.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { DEVELOPMENT_DISTRIBUTION_URL } from "@lib/constants";
import logger from "@lib/logger";
import { BundleUpdaterManager, ClientInfoManager, DeviceManager } from "@lib/native";
import {
BundleUpdaterManager,
ClientInfoManager,
DeviceManager
} from "@lib/native";
import { after } from "@lib/patcher";
import settings, { loaderConfig } from "@lib/settings";
import { getCurrentTheme, selectTheme } from "@lib/themes";
import { ReactNative as RN } from "@metro/common";
import { ButtonColors, type RNConstants } from "@types";
import { showConfirmationAlert } from '@ui/alerts'
import { showConfirmationAlert } from "@ui/alerts";
import { getAssetIDByName } from "@ui/assets";
import { showToast } from "@ui/toasts";
import { removeCachedScript } from "./storage";
Expand Down Expand Up @@ -144,7 +148,10 @@ export function getDebugInfo() {
};
}

export async function setDevelopmentBuildEnabled(enabled: boolean, showReloadPopup = true) {
export async function setDevelopmentBuildEnabled(
enabled: boolean,
showReloadPopup = true
) {
if (enabled) {
settings.__previousCustomLoadUrlConfig = loaderConfig.customLoadUrl;
loaderConfig.customLoadUrl = {
Expand All @@ -166,13 +173,13 @@ export async function setDevelopmentBuildEnabled(enabled: boolean, showReloadPop

await removeCachedScript();

if (showReloadPopup) showConfirmationAlert({
title: "Reload required",
content:
"Changes will only apply next time the app launches or reloads.",
confirmText: "Reload now",
cancelText: "Later",
confirmColor: ButtonColors.PRIMARY,
onConfirm: BundleUpdaterManager.reload
});
if (showReloadPopup)
showConfirmationAlert({
title: "Reload required",
content: "Changes will only apply next time the app launches or reloads.",
confirmText: "Reload now",
cancelText: "Later",
confirmColor: ButtonColors.PRIMARY,
onConfirm: BundleUpdaterManager.reload
});
}
9 changes: 7 additions & 2 deletions src/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import {
createStorage,
wrapSync
} from "@lib/storage";
import type { LoaderConfig, ExtendedVeryPrivateSoonToBeMovedSettings } from "@types";
import type {
ExtendedVeryPrivateSoonToBeMovedSettings,
LoaderConfig
} from "@types";

export default wrapSync(
createStorage<ExtendedVeryPrivateSoonToBeMovedSettings>(createMMKVBackend("VENDETTA_SETTINGS"))
createStorage<ExtendedVeryPrivateSoonToBeMovedSettings>(
createMMKVBackend("VENDETTA_SETTINGS")
)
);
export const loaderConfig = wrapSync(
createStorage<LoaderConfig>(createFileBackend("vendetta_loader.json"))
Expand Down
9 changes: 6 additions & 3 deletions src/ui/settings/pages/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ export default function General() {
leading={
<FormRow.Icon source={getAssetIDByName("ic_message_retry")} />
}
onPress={() =>
setDevelopmentBuildEnabled(settings.developmentBuildEnabled)
}
onPress={() => {
// Workaround so it restores the config correctly even when the dev build option is turned off
settings.__previousCustomLoadUrlConfig =
loaderConfig.customLoadUrl;
setDevelopmentBuildEnabled(settings.developmentBuildEnabled);
}}
/>
<FormDivider />
<FormSwitchRow
Expand Down
44 changes: 22 additions & 22 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"include": ["src"],
"exclude": ["node_modules"],
"compilerOptions": {
"baseUrl": ".",
"sourceMap": true,
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "react",
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"paths": {
"@/*": ["src/*"],
"@types": ["src/def.d.ts"],
"@lib/*": ["src/lib/*"],
"@metro/*": ["src/lib/metro/*"],
"@ui/*": ["src/ui/*"]
}
}
"include": ["src"],
"exclude": ["node_modules"],
"compilerOptions": {
"baseUrl": ".",
"sourceMap": true,
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"jsx": "react",
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"paths": {
"@/*": ["src/*"],
"@types": ["src/def.d.ts"],
"@lib/*": ["src/lib/*"],
"@metro/*": ["src/lib/metro/*"],
"@ui/*": ["src/ui/*"]
}
}
}

0 comments on commit 0db174a

Please sign in to comment.