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 1ef9fa4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 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
33 changes: 20 additions & 13 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 @@ -91,7 +95,7 @@ export function getDebugInfo() {
vendetta: {
version: versionHash,
loader: window.__vendetta_loader?.name ?? "Unknown",
branch,
branch
},
discord: {
version: ClientInfoManager.Version,
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
3 changes: 3 additions & 0 deletions src/ui/settings/pages/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export default function General() {
}
];

// Workaround so it restores the config correctly even when the dev build option is turned off
settings.__previousCustomLoadUrlConfig ??= loaderConfig.customLoadUrl;

return (
<ErrorBoundary>
<RN.ScrollView
Expand Down

0 comments on commit 1ef9fa4

Please sign in to comment.