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,53 +157,53 @@ export type StreamyfinPluginConfig = {
|
|||||||
settings: PluginLockableSettings;
|
settings: PluginLockableSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadSettings = (): Settings => {
|
const defaultValues: Settings = {
|
||||||
const defaultValues: Settings = {
|
home: null,
|
||||||
home: null,
|
autoRotate: true,
|
||||||
autoRotate: true,
|
forceLandscapeInVideoPlayer: false,
|
||||||
forceLandscapeInVideoPlayer: false,
|
deviceProfile: "Expo",
|
||||||
deviceProfile: "Expo",
|
mediaListCollectionIds: [],
|
||||||
mediaListCollectionIds: [],
|
preferedLanguage: undefined,
|
||||||
preferedLanguage: undefined,
|
searchEngine: "Jellyfin",
|
||||||
searchEngine: "Jellyfin",
|
marlinServerUrl: "",
|
||||||
marlinServerUrl: "",
|
openInVLC: false,
|
||||||
openInVLC: false,
|
downloadQuality: DownloadOptions[0],
|
||||||
downloadQuality: DownloadOptions[0],
|
libraryOptions: {
|
||||||
libraryOptions: {
|
display: "list",
|
||||||
display: "list",
|
cardStyle: "detailed",
|
||||||
cardStyle: "detailed",
|
imageStyle: "cover",
|
||||||
imageStyle: "cover",
|
showTitles: true,
|
||||||
showTitles: true,
|
showStats: true,
|
||||||
showStats: true,
|
},
|
||||||
},
|
defaultAudioLanguage: null,
|
||||||
defaultAudioLanguage: null,
|
playDefaultAudioTrack: true,
|
||||||
playDefaultAudioTrack: true,
|
rememberAudioSelections: true,
|
||||||
rememberAudioSelections: true,
|
defaultSubtitleLanguage: null,
|
||||||
defaultSubtitleLanguage: null,
|
subtitleMode: SubtitlePlaybackMode.Default,
|
||||||
subtitleMode: SubtitlePlaybackMode.Default,
|
rememberSubtitleSelections: true,
|
||||||
rememberSubtitleSelections: true,
|
showHomeTitles: true,
|
||||||
showHomeTitles: true,
|
defaultVideoOrientation: ScreenOrientation.OrientationLock.DEFAULT,
|
||||||
defaultVideoOrientation: ScreenOrientation.OrientationLock.DEFAULT,
|
forwardSkipTime: 30,
|
||||||
forwardSkipTime: 30,
|
rewindSkipTime: 10,
|
||||||
rewindSkipTime: 10,
|
optimizedVersionsServerUrl: null,
|
||||||
optimizedVersionsServerUrl: null,
|
downloadMethod: DownloadMethod.Remux,
|
||||||
downloadMethod: DownloadMethod.Remux,
|
autoDownload: false,
|
||||||
autoDownload: false,
|
showCustomMenuLinks: false,
|
||||||
showCustomMenuLinks: false,
|
disableHapticFeedback: false,
|
||||||
disableHapticFeedback: false,
|
subtitleSize: Platform.OS === "ios" ? 60 : 100,
|
||||||
subtitleSize: Platform.OS === "ios" ? 60 : 100,
|
remuxConcurrentLimit: 1,
|
||||||
remuxConcurrentLimit: 1,
|
safeAreaInControlsEnabled: true,
|
||||||
safeAreaInControlsEnabled: true,
|
jellyseerrServerUrl: undefined,
|
||||||
jellyseerrServerUrl: undefined,
|
hiddenLibraries: [],
|
||||||
hiddenLibraries: [],
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
const loadSettings = (): Partial<Settings> => {
|
||||||
try {
|
try {
|
||||||
const jsonValue = storage.getString("settings");
|
const jsonValue = storage.getString("settings");
|
||||||
const loadedValues: Partial<Settings> =
|
const loadedValues: Partial<Settings> =
|
||||||
jsonValue != null ? JSON.parse(jsonValue) : {};
|
jsonValue != null ? JSON.parse(jsonValue) : {};
|
||||||
|
|
||||||
return { ...defaultValues, ...loadedValues };
|
return loadedValues;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to load settings:", error);
|
console.error("Failed to load settings:", error);
|
||||||
return defaultValues;
|
return defaultValues;
|
||||||
@@ -222,7 +222,7 @@ const saveSettings = (settings: Settings) => {
|
|||||||
storage.set("settings", jsonValue);
|
storage.set("settings", jsonValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const settingsAtom = atom<Settings | null>(null);
|
export const settingsAtom = atom<Partial<Settings> | null>(null);
|
||||||
export const pluginSettingsAtom = atom(
|
export const pluginSettingsAtom = atom(
|
||||||
storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS)
|
storage.get<PluginLockableSettings>(STREAMYFIN_PLUGIN_SETTINGS)
|
||||||
);
|
);
|
||||||
@@ -262,7 +262,7 @@ export const useSettings = () => {
|
|||||||
|
|
||||||
const updateSettings = (update: Partial<Settings>) => {
|
const updateSettings = (update: Partial<Settings>) => {
|
||||||
if (settings) {
|
if (settings) {
|
||||||
const newSettings = { ...settings, ...update };
|
const newSettings = { ..._settings, ...update };
|
||||||
|
|
||||||
setSettings(newSettings);
|
setSettings(newSettings);
|
||||||
saveSettings(newSettings);
|
saveSettings(newSettings);
|
||||||
@@ -271,7 +271,7 @@ export const useSettings = () => {
|
|||||||
|
|
||||||
// We do not want to save over users pre-existing settings in case admin ever removes/unlocks a setting.
|
// We do not want to save over users pre-existing settings in case admin ever removes/unlocks a setting.
|
||||||
// If admin sets locked to false but provides a value,
|
// If admin sets locked to false but provides a value,
|
||||||
// use user settings first and fallback on admin setting if required.
|
// use user settings first and fallback on admin setting if required.
|
||||||
const settings: Settings = useMemo(() => {
|
const settings: Settings = useMemo(() => {
|
||||||
let unlockedPluginDefaults = {} as Settings;
|
let unlockedPluginDefaults = {} as Settings;
|
||||||
const overrideSettings = Object.entries(pluginSettings || {}).reduce(
|
const overrideSettings = Object.entries(pluginSettings || {}).reduce(
|
||||||
@@ -300,12 +300,8 @@ export const useSettings = () => {
|
|||||||
{} as Settings
|
{} as Settings
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update settings with plugin defined defaults
|
|
||||||
if (Object.keys(unlockedPluginDefaults).length > 0) {
|
|
||||||
updateSettings(unlockedPluginDefaults);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
...defaultValues,
|
||||||
..._settings,
|
..._settings,
|
||||||
...overrideSettings,
|
...overrideSettings,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user