From dee5ed0172f00ad5fddc1a9e53f164057ad4bda4 Mon Sep 17 00:00:00 2001 From: Beef Date: Sat, 14 Jan 2023 02:41:28 +0000 Subject: [PATCH] [UI] Overall cleanup and fixes --- src/ui/fixTheme.ts | 26 +++++----- src/ui/settings/components/AssetDisplay.tsx | 2 +- src/ui/settings/components/PluginCard.tsx | 12 ++++- .../settings/components/SettingsSection.tsx | 6 +-- .../{PluginSettings.tsx => Subpage.tsx} | 11 ++--- src/ui/settings/components/Version.tsx | 4 +- src/ui/settings/pages/AssetBrowser.tsx | 40 ++++++++++++++++ src/ui/settings/pages/Developer.tsx | 48 ++++++------------- src/ui/settings/pages/General.tsx | 1 - src/ui/settings/pages/Plugins.tsx | 8 ++-- 10 files changed, 91 insertions(+), 67 deletions(-) rename src/ui/settings/components/{PluginSettings.tsx => Subpage.tsx} (89%) create mode 100644 src/ui/settings/pages/AssetBrowser.tsx diff --git a/src/ui/fixTheme.ts b/src/ui/fixTheme.ts index cde4a7d..058db09 100644 --- a/src/ui/fixTheme.ts +++ b/src/ui/fixTheme.ts @@ -1,30 +1,26 @@ -// Loosely based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts +// Based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts // Literally could not figure this out, many thanks import { findByProps, findByStoreName } from "@metro/filters"; import { FluxDispatcher } from "@metro/common"; -import logger from "@/lib/logger"; +import logger from "@lib/logger"; const ThemeManager = findByProps("updateTheme", "overrideTheme"); const AMOLEDThemeManager = findByProps("setAMOLEDThemeEnabled"); const ThemeStore = findByStoreName("ThemeStore"); const UnsyncedUserSettingsStore = findByStoreName("UnsyncedUserSettingsStore"); +function override() { + const theme = ThemeStore.theme || "dark"; + ThemeManager.overrideTheme(theme); + + if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) AMOLEDThemeManager.setAMOLEDThemeEnabled(true); + FluxDispatcher.unsubscribe("I18N_LOAD_START", override); +} + export function fixTheme() { try { - if (ThemeStore) { - function override() { - const theme = ThemeStore.theme || "dark"; - ThemeManager.overrideTheme(theme); - - if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) { - AMOLEDThemeManager.setAMOLEDThemeEnabled(true); - } - FluxDispatcher.unsubscribe("I18N_LOAD_START", override); - } - - FluxDispatcher.subscribe("I18N_LOAD_START", override); - } + if (ThemeStore) FluxDispatcher.subscribe("I18N_LOAD_START", override); } catch(e) { logger.error("Failed to fix theme...", e) } diff --git a/src/ui/settings/components/AssetDisplay.tsx b/src/ui/settings/components/AssetDisplay.tsx index 2a945d4..d2c0291 100644 --- a/src/ui/settings/components/AssetDisplay.tsx +++ b/src/ui/settings/components/AssetDisplay.tsx @@ -22,7 +22,7 @@ export default function AssetDisplay({ asset }: AssetDisplayProps) { return ( } + trailing={} onPress={() => { copyText(asset.name); showToast("Copied asset name to clipboard.", getAssetIDByName("toast_copy_link")); diff --git a/src/ui/settings/components/PluginCard.tsx b/src/ui/settings/components/PluginCard.tsx index 07f0e55..ff7e706 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/ui/settings/components/PluginCard.tsx @@ -4,6 +4,7 @@ import { Plugin } from "@types"; import { getAssetIDByName } from "@ui/assets"; import { removePlugin, startPlugin, stopPlugin, showSettings, getSettings } from "@lib/plugins"; import { showToast } from "@ui/toasts"; +import copyText from "@lib/utils/copyText"; const { FormRow, FormSwitch } = Forms; const { TouchableOpacity, Image } = General; @@ -13,6 +14,7 @@ const styles = stylesheet.createThemedStyleSheet({ backgroundColor: stylesheet.ThemeColorMap.BACKGROUND_SECONDARY, borderRadius: 5, margin: 10, + marginTop: 0, }, header: { backgroundColor: stylesheet.ThemeColorMap.BACKGROUND_TERTIARY, @@ -21,7 +23,7 @@ const styles = stylesheet.createThemedStyleSheet({ }, actions: { justifyContent: "flex-end", - flexDirection: "row", + flexDirection: "row-reverse", alignItems: "center", }, icon: { @@ -73,6 +75,14 @@ export default function PluginCard({ plugin }: PluginCardProps) { > + { + copyText(plugin.id); + showToast("Copied plugin URL to clipboard.", getAssetIDByName("toast_copy_link")); + }} + > + + { plugin.update = !plugin.update; diff --git a/src/ui/settings/components/SettingsSection.tsx b/src/ui/settings/components/SettingsSection.tsx index 5494310..c26cfc0 100644 --- a/src/ui/settings/components/SettingsSection.tsx +++ b/src/ui/settings/components/SettingsSection.tsx @@ -13,14 +13,14 @@ export default function SettingsSection({ navigation }: SettingsSectionProps) { } + leading={} trailing={FormRow.Arrow} onPress={() => navigation.push("VendettaSettings")} /> } + leading={} trailing={FormRow.Arrow} onPress={() => navigation.push("VendettaPlugins")} /> @@ -29,7 +29,7 @@ export default function SettingsSection({ navigation }: SettingsSectionProps) { } + leading={} trailing={FormRow.Arrow} onPress={() => navigation.push("VendettaDeveloper")} /> diff --git a/src/ui/settings/components/PluginSettings.tsx b/src/ui/settings/components/Subpage.tsx similarity index 89% rename from src/ui/settings/components/PluginSettings.tsx rename to src/ui/settings/components/Subpage.tsx index 97e0d3c..b0f3596 100644 --- a/src/ui/settings/components/PluginSettings.tsx +++ b/src/ui/settings/components/Subpage.tsx @@ -1,10 +1,9 @@ -import { Plugin } from "@types"; import { navigation, navigationStack, NavigationNative, stylesheet, constants } from "@metro/common"; import { General } from "@ui/components"; import { getAssetIDByName } from "@ui/assets"; -interface PluginSettingsProps { - plugin: Plugin; +interface SubpageProps { + name: string; children: JSX.Element; } @@ -39,11 +38,11 @@ const styles = stylesheet.createThemedStyleSheet({ export const Settings = navigationStack.createStackNavigator(); const { TouchableOpacity, Image } = General; -export default function PluginSettings({ plugin, children }: PluginSettingsProps) { +export default function Subpage({ name, children }: SubpageProps) { return ( } - trailing={() => {version}} + leading={} + trailing={{version}} onPress={() => { copyText(`${label} - ${version}`); showToast("Copied version to clipboard.", getAssetIDByName("toast_copy_link")); diff --git a/src/ui/settings/pages/AssetBrowser.tsx b/src/ui/settings/pages/AssetBrowser.tsx new file mode 100644 index 0000000..3dc20ce --- /dev/null +++ b/src/ui/settings/pages/AssetBrowser.tsx @@ -0,0 +1,40 @@ +import { ReactNative as RN, stylesheet } from "@metro/common"; +import { Forms, Search } from "@ui/components"; +import { all } from "@ui/assets"; +import AssetDisplay from "@ui/settings/components/AssetDisplay"; + +const { FormDivider } = Forms; + +const styles = stylesheet.createThemedStyleSheet({ + search: { + margin: 0, + padding: 15, + borderBottomWidth: 0, + background: "none", + backgroundColor: "none", + } +}); + +export default function AssetBrowser() { + const [searchName, setSearchName] = React.useState(""); + + return ( + + setSearchName(v)} + placeholder="Search..." + /> + a.name.includes(searchName))} + renderItem={({ item }) => ( + <> + + + + )} + keyExtractor={item => item.name} + /> + + ) +} \ No newline at end of file diff --git a/src/ui/settings/pages/Developer.tsx b/src/ui/settings/pages/Developer.tsx index 5562698..5f823ef 100644 --- a/src/ui/settings/pages/Developer.tsx +++ b/src/ui/settings/pages/Developer.tsx @@ -1,32 +1,20 @@ -import { ReactNative as RN, stylesheet } from "@metro/common"; -import { Forms, Search } from "@ui/components"; +import { ReactNative as RN, navigation } from "@metro/common"; +import { Forms } from "@ui/components"; import { getAssetIDByName } from "@ui/assets"; import { showToast } from "@/ui/toasts"; import { connectToDebugger } from "@lib/debug"; -import { all } from "@ui/assets"; import settings from "@lib/settings"; import logger from "@lib/logger"; -import AssetDisplay from "@ui/settings/components/AssetDisplay"; +import Subpage from "@ui/settings/components/Subpage"; +import AssetBrowser from "@ui/settings/pages/AssetBrowser"; const { FormSection, FormRow, FormInput, FormDivider } = Forms; -const styles = stylesheet.createThemedStyleSheet({ - search: { - margin: 0, - padding: 0, - paddingRight: 15, - paddingLeft: 15, - borderBottomWidth: 0, - backgroundColor: "none" - } -}) - export default function Developer() { const [debuggerUrl, setDebuggerUrl] = React.useState(settings.debuggerUrl || ""); - const [searchName, setSearchName] = React.useState(""); return ( - + } - trailing={FormRow.Arrow} onPress={() => connectToDebugger(debuggerUrl)} /> {window.__vendetta_rdc && } - trailing={FormRow.Arrow} onPress={() => { try { window.__vendetta_rdc?.connectToDevTools({ @@ -61,21 +47,15 @@ export default function Developer() { }} />} - - setSearchName(v)} - placeholder="Search..." - /> - a.name.includes(searchName))} - renderItem={({ item }) => ( - <> - - - - )} - keyExtractor={item => item.name} + + } + trailing={FormRow.Arrow} + onPress={() => navigation.push(Subpage, { + name: "Asset Browser", + children: AssetBrowser, + })} /> diff --git a/src/ui/settings/pages/General.tsx b/src/ui/settings/pages/General.tsx index 234bf1b..244ccf0 100644 --- a/src/ui/settings/pages/General.tsx +++ b/src/ui/settings/pages/General.tsx @@ -110,7 +110,6 @@ export default function General() { } - trailing={FormRow.Arrow} onPress={() => RN.NativeModules.BundleUpdaterManager.reload()} /> diff --git a/src/ui/settings/pages/Plugins.tsx b/src/ui/settings/pages/Plugins.tsx index b6f81ab..1da97ca 100644 --- a/src/ui/settings/pages/Plugins.tsx +++ b/src/ui/settings/pages/Plugins.tsx @@ -1,4 +1,4 @@ -import { ReactNative as RN, stylesheet } from "@metro/common"; +import { ReactNative as RN } from "@metro/common"; import { Forms } from "@ui/components"; import { showToast } from "@ui/toasts"; import { getAssetIDByName } from "@ui/assets"; @@ -12,7 +12,7 @@ export default function Plugins() { const [pluginList, setPluginList] = React.useState(plugins); return ( - + setPluginUrl(v)} @@ -20,8 +20,7 @@ export default function Plugins() { /> } - trailing={FormRow.Arrow} + leading={} onPress={() => { fetchPlugin(pluginUrl).then(() => { setPluginUrl(""); @@ -33,6 +32,7 @@ export default function Plugins() { } /> } keyExtractor={item => item.id}