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

Commit

Permalink
feat: add reload CTA prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmDevs authored and PalmDevs committed Mar 18, 2024
1 parent 94c9643 commit 38bc47c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
17 changes: 14 additions & 3 deletions src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ 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";

export let socket: WebSocket;

export async function toggleSafeMode() {
Expand Down Expand Up @@ -144,7 +146,7 @@ export function getDebugInfo() {
};
}

export function setDevelopmentBuildEnabled(enabled: boolean) {
export async function setDevelopmentBuildEnabled(enabled: boolean) {
if (enabled) {
loaderConfig.__previousCustomLoadUrlConfig = loaderConfig.customLoadUrl;
loaderConfig.customLoadUrl = {
Expand All @@ -164,5 +166,14 @@ export function setDevelopmentBuildEnabled(enabled: boolean) {

settings.developmentBuildEnabled = enabled;

return removeCachedScript();
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
});
}
10 changes: 6 additions & 4 deletions src/ui/settings/pages/Developer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BundleUpdaterManager } from '@lib/native'
import { showConfirmationAlert } from '@ui/alerts'
import { connectToDebugger, setDevelopmentBuildEnabled } from "@lib/debug";
import { BundleUpdaterManager } from "@lib/native";
import settings, { loaderConfig } from "@lib/settings";
import { useProxy } from "@lib/storage";
import { NavigationNative, ReactNative as RN } from "@metro/common";
import { ButtonColors } from '@types'
import { findByProps } from "@metro/filters";
import { ButtonColors } from "@types";
import { showConfirmationAlert } from "@ui/alerts";
import { getAssetIDByName } from "@ui/assets";
import { ErrorBoundary, Forms } from "@ui/components";
import AssetBrowser from "@ui/settings/pages/AssetBrowser";
Expand Down Expand Up @@ -92,7 +92,9 @@ export default function Developer() {
<>
<FormInput
value={loaderConfig.customLoadUrl.url}
onChange={(v: string) => (loaderConfig.customLoadUrl.url = v)}
onChange={(v: string) =>
(loaderConfig.customLoadUrl.url = v)
}
placeholder="http://localhost:4040/revenge.js"
title="REVENGE URL"
/>
Expand Down
37 changes: 26 additions & 11 deletions src/ui/settings/pages/General.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
import { getDebugInfo, setDevelopmentBuildEnabled, toggleSafeMode } from "@lib/debug";
import {
getDebugInfo,
setDevelopmentBuildEnabled,
toggleSafeMode
} from "@lib/debug";
import { BundleUpdaterManager } from "@lib/native";
import settings, { loaderConfig } from "@lib/settings";
import { removeMMKVBackend, useProxy } from "@lib/storage";
Expand Down Expand Up @@ -175,21 +179,32 @@ export default function General() {
label="Use Development Builds"
leading={
<FormRow.Icon
source={getAssetIDByName("ic_progress_wrench_24px")}
source={getAssetIDByName("ic_progress_wrench_24px")}
/>
}
value={settings.developmentBuildEnabled}
onValueChange={(v: boolean) => {
if (v) showConfirmationAlert({
title: "Use development builds?",
if (v)
showConfirmationAlert({
title: "Use development builds?",
content:
"Development builds can be unstable and may contain bugs. Changes will apply next time the app launches or reloads.",
confirmText: "Continue",
cancelText: "Nevermind",
confirmColor: ButtonColors.RED,
onConfirm: () => setDevelopmentBuildEnabled(v)
});
else setDevelopmentBuildEnabled(v);

showConfirmationAlert({
title: "Reload required",
content:
"Development builds can be unstable and may contain bugs. Changes will apply next time the app launches or reloads.",
confirmText: "Continue",
cancelText: "Nevermind",
confirmColor: ButtonColors.RED,
onConfirm: () => setDevelopmentBuildEnabled(v)
})
else setDevelopmentBuildEnabled(v)
"Changes will only apply next time the app launches or reloads.",
confirmText: "Reload now",
cancelText: "Later",
confirmColor: ButtonColors.PRIMARY,
onConfirm: BundleUpdaterManager.reload
});
}}
/>
<FormDivider />
Expand Down

0 comments on commit 38bc47c

Please sign in to comment.