From 121888c1c33a8f01fb5ffa869f70412667ccfc46 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Sun, 30 Mar 2025 12:11:40 +1100 Subject: [PATCH] feat: hide and group settings based on plugin --- src/interface/pages/settings/general.svelte | 141 ++++++++------------ src/plugins/core/manager.ts | 3 +- 2 files changed, 59 insertions(+), 85 deletions(-) diff --git a/src/interface/pages/settings/general.svelte b/src/interface/pages/settings/general.svelte index 0375969f..29b6dd2b 100644 --- a/src/interface/pages/settings/general.svelte +++ b/src/interface/pages/settings/general.svelte @@ -34,14 +34,6 @@ const pluginSettings = getAllPluginSettings() as Plugin[]; const pluginSettingsValues = $state>>({}); - let nextPluginSettingId = 1000; - const pluginSettingMap = new Map(); - - function getPluginSettingId(pluginId: string, settingKey: string): number { - const id = nextPluginSettingId++; - pluginSettingMap.set(id, {pluginId, settingKey}); - return id; - } async function loadPluginSettings() { for (const plugin of pluginSettings) { @@ -76,81 +68,6 @@ await browser.storage.local.set({ [storageKey]: currentSettings }); } - function getPluginSettingEntries() { - const entries: any[] = []; - - pluginSettings.forEach(plugin => { - if (Object.keys(plugin.settings).length === 0) return; - - // Add enable/disable toggle if plugin has disableToggle set - if ((plugin as any).disableToggle) { - entries.push({ - title: `Enable ${plugin.name}`, - description: `${plugin.description}`, - id: getPluginSettingId(plugin.pluginId, 'enabled'), - Component: Switch, - props: { - state: pluginSettingsValues[plugin.pluginId]?.enabled ?? true, - onChange: (value: boolean) => { - updatePluginSetting(plugin.pluginId, 'enabled', value); - } - } - }); - } - - Object.entries(plugin.settings).forEach(([key, setting]) => { - const id = getPluginSettingId(plugin.pluginId, key); - - const props: Record = { - state: pluginSettingsValues[plugin.pluginId]?.[key] ?? setting.default, - onChange: (value: any) => { - if (setting.type === 'number' && typeof value === 'string') { - value = parseFloat(value); - } - updatePluginSetting(plugin.pluginId, key, value); - } - }; - - if (setting.type === 'number') { - if (typeof setting.min === 'number') props.min = setting.min; - if (typeof setting.max === 'number') props.max = setting.max; - if (typeof setting.step === 'number') props.step = setting.step; - } - - if (setting.type === 'select') { - props.options = setting.options; - } - - let Component; - switch (setting.type) { - case 'boolean': - Component = Switch; - break; - case 'number': - Component = Slider; - break; - case 'select': - Component = Select; - break; - default: - Component = null; - } - - if (!Component) return; - - entries.push({ - title: setting.title || key, - description: setting.description || '', - id, - Component, - props - }); - }); - }); - - return entries; - } - $effect(() => { loadPluginSettings(); }) @@ -171,6 +88,63 @@ {/snippet}
+ {#each pluginSettings as plugin} +
+ + {#if (plugin as any).disableToggle} +
+
+

Enable {plugin.name}

+

{plugin.description}

+
+
+ updatePluginSetting(plugin.pluginId, 'enabled', value)} + /> +
+
+ {/if} + + + {#if !((plugin as any).disableToggle) || (pluginSettingsValues[plugin.pluginId]?.enabled ?? true)} + {#each Object.entries(plugin.settings) as [key, setting]} + + {#if key !== 'enabled'} +
+
+

{setting.title || key}

+

{setting.description || ''}

+
+
+ {#if setting.type === 'boolean'} + updatePluginSetting(plugin.pluginId, key, value)} + /> + {:else if setting.type === 'number'} + updatePluginSetting(plugin.pluginId, key, value)} + min={setting.min} + max={setting.max} + step={setting.step} + /> + {:else if setting.type === 'select'} +