From 9261c983aa17f6dd62b748b531cf07d0a5b0027a Mon Sep 17 00:00:00 2001 From: kmmiio99o <164557248+kmmiio99o@users.noreply.github.com> Date: Sat, 27 Sep 2025 21:22:17 +0200 Subject: [PATCH] Fix settings switches to handle missing storage keys safely --- plugins/all-in-one/settings.tsx | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/all-in-one/settings.tsx b/plugins/all-in-one/settings.tsx index 847d0c9..f8c3aff 100644 --- a/plugins/all-in-one/settings.tsx +++ b/plugins/all-in-one/settings.tsx @@ -1,4 +1,6 @@ import { plugin } from "@vendetta"; +import { storage } from "@vendetta/plugin"; +import { useProxy } from "@vendetta/storage"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { React } from "@vendetta/metro/common"; import { findByProps } from "@vendetta/metro"; @@ -13,7 +15,7 @@ const { TableRowGroup, TableSwitchRow, Stack, TableRow } = findByProps( "TableRow", ); -// Initialize default settings if not exist +// Initialize storage with default values if (!storage.factSettings) { storage.factSettings = { sendAsReply: true, @@ -49,7 +51,7 @@ export default function Settings() { useProxy(storage); const [rerender, forceRerender] = React.useReducer((x) => x + 1, 0); - // Check for changes when component unmounts + // Check for pending restart when unmounting React.useEffect(() => { return () => { if (storage.pendingRestart) { @@ -67,7 +69,10 @@ export default function Settings() { return ( - + {/* Facts Commands */} @@ -75,7 +80,7 @@ export default function Settings() { label="Send as Reply" subLabel="Send facts as a reply to the command message" icon={getAssetIDByName("ic_reply_24px")} - value={storage.factSettings.sendAsReply} + value={storage.factSettings?.sendAsReply ?? true} onValueChange={(v: boolean) => { storage.factSettings.sendAsReply = v; forceRerender(); @@ -85,7 +90,7 @@ export default function Settings() { label="Include Source Citation" subLabel="Include the source of facts when available" icon={getAssetIDByName("ic_info")} - value={storage.factSettings.includeCitation} + value={storage.factSettings?.includeCitation ?? false} onValueChange={(v: boolean) => { storage.factSettings.includeCitation = v; forceRerender(); @@ -95,21 +100,21 @@ export default function Settings() { label="/catfact" subLabel="Get random cat facts" icon={getAssetIDByName("ic_info")} - value={storage.enabledCommands.catfact} + value={storage.enabledCommands?.catfact ?? true} onValueChange={(v) => handleCommandToggle("catfact", v)} /> handleCommandToggle("dogfact", v)} /> handleCommandToggle("useless", v)} /> @@ -120,7 +125,7 @@ export default function Settings() { label="Always Send Detailed Plugin List" subLabel="Always use detailed mode when listing plugins" icon={getAssetIDByName("ic_message_copy")} - value={storage.listSettings.pluginListAlwaysDetailed} + value={storage.listSettings?.pluginListAlwaysDetailed ?? false} onValueChange={(v: boolean) => { storage.listSettings.pluginListAlwaysDetailed = v; forceRerender(); @@ -130,7 +135,7 @@ export default function Settings() { label="Always Send Detailed Theme List" subLabel="Always use detailed mode when listing themes" icon={getAssetIDByName("ic_theme")} - value={storage.listSettings.themeListAlwaysDetailed} + value={storage.listSettings?.themeListAlwaysDetailed ?? false} onValueChange={(v: boolean) => { storage.listSettings.themeListAlwaysDetailed = v; forceRerender(); @@ -140,14 +145,14 @@ export default function Settings() { label="/plugin-list" subLabel="List all installed plugins" icon={getAssetIDByName("ic_plugins")} - value={storage.enabledCommands.pluginList} + value={storage.enabledCommands?.pluginList ?? true} onValueChange={(v) => handleCommandToggle("pluginList", v)} /> handleCommandToggle("themeList", v)} /> @@ -158,7 +163,7 @@ export default function Settings() { label="/petpet" subLabel="Create pet-pet GIF of a user" icon={getAssetIDByName("ic_image")} - value={storage.enabledCommands.petpet} + value={storage.enabledCommands?.petpet ?? true} onValueChange={(v) => handleCommandToggle("petpet", v)} /> @@ -169,14 +174,14 @@ export default function Settings() { label="/konoself" subLabel="Get random image from KonoChan (private)" icon={getAssetIDByName("ic_image")} - value={storage.enabledCommands.konoself} + value={storage.enabledCommands?.konoself ?? true} onValueChange={(v) => handleCommandToggle("konoself", v)} /> handleCommandToggle("konosend", v)} /> @@ -209,6 +214,7 @@ export default function Settings() { BundleUpdaterManager.reload()} />