feat: Allow plugin override defaults (#508)

This commit is contained in:
lostb1t
2025-02-10 17:38:01 +01:00
committed by GitHub
parent 34d1dbb20e
commit e0f03ccb93

View File

@@ -157,8 +157,7 @@ export type StreamyfinPluginConfig = {
settings: PluginLockableSettings;
};
const loadSettings = (): Settings => {
const defaultValues: Settings = {
const defaultValues: Settings = {
home: null,
autoRotate: true,
forceLandscapeInVideoPlayer: false,
@@ -196,14 +195,15 @@ const loadSettings = (): Settings => {
safeAreaInControlsEnabled: true,
jellyseerrServerUrl: undefined,
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,
};