Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
fix: move storing old loader config into settings + other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmDevs authored and PalmDevs committed Mar 19, 2024
1 parent 7c17223 commit 90c910c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
8 changes: 1 addition & 7 deletions src/def.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ interface Settings {

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

interface ApplicationCommand {
Expand Down Expand Up @@ -397,13 +398,6 @@ interface LoaderConfig {
loadReactDevTools: boolean;
}

interface ExtendedVeryPrivateSoonToBeMovedLoaderConfig extends LoaderConfig {
__previousCustomLoadUrlConfig?: {
enabled: boolean;
url: string;
}
}

interface LoaderIdentity {
name: string;
features: {
Expand Down
23 changes: 17 additions & 6 deletions src/lib/debug.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DEVELOPMENT_DISTRIBUTION_URL } from "@lib/constants";
import logger from "@lib/logger";
import { 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 { type RNConstants } from "@types";
import { ButtonColors, type RNConstants } from "@types";
import { showConfirmationAlert } from '@ui/alerts'
import { getAssetIDByName } from "@ui/assets";
import { showToast } from "@ui/toasts";
import { removeCachedScript } from "./storage";
Expand Down Expand Up @@ -141,25 +142,35 @@ export function getDebugInfo() {
};
}

export async function setDevelopmentBuildEnabled(enabled: boolean) {
export async function setDevelopmentBuildEnabled(enabled: boolean, showReloadPopup = true) {
if (enabled) {
loaderConfig.__previousCustomLoadUrlConfig = loaderConfig.customLoadUrl;
settings.__previousCustomLoadUrlConfig = loaderConfig.customLoadUrl;
loaderConfig.customLoadUrl = {
enabled: true,
url: DEVELOPMENT_DISTRIBUTION_URL
};
} else {
const previousConfig = loaderConfig.__previousCustomLoadUrlConfig;
const previousConfig = settings.__previousCustomLoadUrlConfig;
if (previousConfig) loaderConfig.customLoadUrl = previousConfig;
else
loaderConfig.customLoadUrl = {
enabled: false,
url: "http://localhost:4040/revenge.js"
};
loaderConfig.__previousCustomLoadUrlConfig = undefined;
settings.__previousCustomLoadUrlConfig = undefined;
}

settings.developmentBuildEnabled = enabled;

await removeCachedScript();

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
});
}
4 changes: 2 additions & 2 deletions src/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
createStorage,
wrapSync
} from "@lib/storage";
import type { ExtendedVeryPrivateSoonToBeMovedLoaderConfig, ExtendedVeryPrivateSoonToBeMovedSettings } from "@types";
import type { LoaderConfig, ExtendedVeryPrivateSoonToBeMovedSettings } from "@types";

export default wrapSync(
createStorage<ExtendedVeryPrivateSoonToBeMovedSettings>(createMMKVBackend("VENDETTA_SETTINGS"))
);
export const loaderConfig = wrapSync(
createStorage<ExtendedVeryPrivateSoonToBeMovedLoaderConfig>(createFileBackend("vendetta_loader.json"))
createStorage<LoaderConfig>(createFileBackend("vendetta_loader.json"))
);
10 changes: 8 additions & 2 deletions src/ui/settings/pages/Developer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AssetBrowser from "@ui/settings/pages/AssetBrowser";
const { FormSection, FormRow, FormSwitchRow, FormInput, FormDivider } = Forms;
const { hideActionSheet } = findByProps("openLazy", "hideActionSheet");
const { showSimpleActionSheet } = findByProps("showSimpleActionSheet");
const { TextStyleSheet } = findByProps("TextStyleSheet");

export default function Developer() {
const navigation = NavigationNative.useNavigation();
Expand Down Expand Up @@ -67,8 +68,13 @@ export default function Developer() {
onPress={() =>
showConfirmationAlert({
title: "Stop using development builds?",
content:
"You will revert back to using a stable build of Revenge after next app launch or reload.",
content: [
"To use the ",
<RN.Text style={TextStyleSheet["text-md/semibold"]}>
Load from custom URL
</RN.Text>,
" option, you will have to stop using development builds as it overrides this setting."
],
confirmText: "Revert",
cancelText: "Cancel",
confirmColor: ButtonColors.PRIMARY,
Expand Down
21 changes: 4 additions & 17 deletions src/ui/settings/pages/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,14 @@ export default function General() {
<FormSection title="Advanced">
<FormSwitchRow
label="Use Development Builds"
sublabel="Use development builds for testing new features or bug fixes, may be unstable."
leading={
<FormRow.Icon
source={getAssetIDByName("ic_progress_wrench_24px")}
/>
}
value={settings.developmentBuildEnabled}
onValueChange={(v: boolean) => {
const callback = () =>
setDevelopmentBuildEnabled(v).then(showReloadRequiredAlert);

if (v)
showConfirmationAlert({
title: "Use development builds?",
Expand All @@ -195,9 +193,9 @@ export default function General() {
confirmText: "Continue",
cancelText: "Nevermind",
confirmColor: ButtonColors.RED,
onConfirm: callback
onConfirm: () => setDevelopmentBuildEnabled(v)
});
else callback()
else setDevelopmentBuildEnabled(v)
}}
/>
<FormDivider />
Expand Down Expand Up @@ -246,15 +244,4 @@ export default function General() {
</RN.ScrollView>
</ErrorBoundary>
);
}

const showReloadRequiredAlert = () =>
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
});
};

0 comments on commit 90c910c

Please sign in to comment.