mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
feat: Allow plugin override defaults (#508)
This commit is contained in:
@@ -157,7 +157,6 @@ export type StreamyfinPluginConfig = {
|
||||
settings: PluginLockableSettings;
|
||||
};
|
||||
|
||||
const loadSettings = (): Settings => {
|
||||
const defaultValues: Settings = {
|
||||
home: null,
|
||||
autoRotate: true,
|
||||
@@ -198,12 +197,13 @@ const loadSettings = (): Settings => {
|
||||
hiddenLibraries: [],
|
||||
};
|
||||
|
||||
const loadSettings = (): Partial<Settings> => {
|
||||
try {
|
||||
const jsonValue = storage.getString("settings");
|
||||
const loadedValues: Partial<Settings> =
|
||||
jsonValue != null ? JSON.parse(jsonValue) : {};
|
||||
|
||||
return { ...defaultValues, ...loadedValues };
|
||||
return loadedValues;
|
||||
} catch (error) {
|
||||
console.error("Failed to load settings:", error);
|
||||
return defaultValues;
|
||||
@@ -222,7 +222,7 @@ const saveSettings = (settings: Settings) => {
|
||||
storage.set("settings", jsonValue);
|
||||
};
|
||||
|
||||
export const settingsAtom = atom<Settings | null>(null);
|
||||
export const settingsAtom = atom<Partial<Settings> | null>(null);
|
||||
export const pluginSettingsAtom = atom(
|
||||
storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS)
|
||||
);
|
||||
@@ -262,7 +262,7 @@ export const useSettings = () => {
|
||||
|
||||
const updateSettings = (update: Partial<Settings>) => {
|
||||
if (settings) {
|
||||
const newSettings = { ...settings, ...update };
|
||||
const newSettings = { ..._settings, ...update };
|
||||
|
||||
setSettings(newSettings);
|
||||
saveSettings(newSettings);
|
||||
@@ -300,12 +300,8 @@ export const useSettings = () => {
|
||||
{} as Settings
|
||||
);
|
||||
|
||||
// Update settings with plugin defined defaults
|
||||
if (Object.keys(unlockedPluginDefaults).length > 0) {
|
||||
updateSettings(unlockedPluginDefaults);
|
||||
}
|
||||
|
||||
return {
|
||||
...defaultValues,
|
||||
..._settings,
|
||||
...overrideSettings,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user