From 36c81714ffba4e61cf411e43e43581e053f3bb17 Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EepyElvyra@users.noreply.github.com> Date: Wed, 5 Feb 2025 17:12:16 +0100 Subject: [PATCH] catch manual edits of settings without a reload when opening settings Co-authored-by: sadan4 <117494111+sadan4@users.noreply.github.com> --- .../components/SettingArrayComponent.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/PluginSettings/components/SettingArrayComponent.tsx b/src/components/PluginSettings/components/SettingArrayComponent.tsx index 058d6d731..6690ed781 100644 --- a/src/components/PluginSettings/components/SettingArrayComponent.tsx +++ b/src/components/PluginSettings/components/SettingArrayComponent.tsx @@ -68,9 +68,26 @@ export function SettingArrayComponent({ id }: ISettingElementProps) { const [error, setError] = useState(null); - const [items, setItems] = useState(pluginSettings[id] || []); + const [items, setItems] = useState(ensureSettingsMigrated() || []); const [text, setText] = useState(""); + function ensureSettingsMigrated(): string[] | undefined { + // in case the settings get manually overridden without a restart of Vencord itself this will prevent crashing + if (pluginSettings[id] == null || Array.isArray(pluginSettings[id])) { + return pluginSettings[id]; + } + let migrated: string[]; + if (typeof option.oldStringSeparator === "string" || option.oldStringSeparator instanceof RegExp) { + migrated = pluginSettings[id]?.split(option.oldStringSeparator); + } else if (typeof option.oldStringSeparator === "function") { + migrated = option.oldStringSeparator(pluginSettings[id]); + } else { + throw new Error(`Invalid oldStringSeparator for in setting ${id} for plugin ${definedSettings?.pluginName || "Unknown plugin"}`); + } + onChange(migrated); + return migrated; + } + useEffect(() => { if (text === "") { setError(null);