From 38bc47c6b10d125366d714974dce3f6895c697a4 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Mon, 18 Mar 2024 20:53:58 +0700 Subject: [PATCH] feat: add reload CTA prompt --- src/lib/debug.ts | 17 ++++++++++--- src/ui/settings/pages/Developer.tsx | 10 ++++---- src/ui/settings/pages/General.tsx | 37 ++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/lib/debug.ts b/src/lib/debug.ts index 7facfcc3..660a3df5 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -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() { @@ -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 = { @@ -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 + }); } diff --git a/src/ui/settings/pages/Developer.tsx b/src/ui/settings/pages/Developer.tsx index ae34426e..af2ee3aa 100644 --- a/src/ui/settings/pages/Developer.tsx +++ b/src/ui/settings/pages/Developer.tsx @@ -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"; @@ -92,7 +92,9 @@ export default function Developer() { <> (loaderConfig.customLoadUrl.url = v)} + onChange={(v: string) => + (loaderConfig.customLoadUrl.url = v) + } placeholder="http://localhost:4040/revenge.js" title="REVENGE URL" /> diff --git a/src/ui/settings/pages/General.tsx b/src/ui/settings/pages/General.tsx index 76b3bcbd..c3f5e41a 100644 --- a/src/ui/settings/pages/General.tsx +++ b/src/ui/settings/pages/General.tsx @@ -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"; @@ -175,21 +179,32 @@ export default function General() { label="Use Development Builds" leading={ } 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 + }); }} />