mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
catch manual edits of settings without a reload when opening settings
Co-authored-by: sadan4 <117494111+sadan4@users.noreply.github.com>
This commit is contained in:
parent
3766cc829e
commit
36c81714ff
1 changed files with 18 additions and 1 deletions
|
@ -68,9 +68,26 @@ export function SettingArrayComponent({
|
||||||
id
|
id
|
||||||
}: ISettingElementProps<PluginOptionArray>) {
|
}: ISettingElementProps<PluginOptionArray>) {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [items, setItems] = useState<string[]>(pluginSettings[id] || []);
|
const [items, setItems] = useState<string[]>(ensureSettingsMigrated() || []);
|
||||||
const [text, setText] = useState<string>("");
|
const [text, setText] = useState<string>("");
|
||||||
|
|
||||||
|
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(() => {
|
useEffect(() => {
|
||||||
if (text === "") {
|
if (text === "") {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
Loading…
Add table
Reference in a new issue