Files
streamyfin_mirror/utils/atoms/settings.ts
Fredrik Burmester ca7fd382f2 wip
2024-08-18 13:30:12 +02:00

38 lines
1.0 KiB
TypeScript

import { atom, useAtom } from "jotai";
type Settings = {
autoRotate?: boolean;
forceLandscapeInVideoPlayer?: boolean;
openFullScreenVideoPlayerByDefault?: boolean;
usePopularPlugin?: boolean;
deviceProfile?: "Expo" | "Native" | "Old";
forceDirectPlay?: boolean;
mediaListCollectionIds?: string[];
};
// Default settings
const defaultSettings: Settings = {
autoRotate: true,
forceLandscapeInVideoPlayer: false,
openFullScreenVideoPlayerByDefault: true,
usePopularPlugin: false,
deviceProfile: "Expo",
forceDirectPlay: false,
mediaListCollectionIds: [],
};
// Create an atom to store the settings in memory, initialized with default settings
const settingsAtom = atom<Settings>(defaultSettings);
// A hook to manage settings, providing a way to update them
export const useSettings = () => {
const [settings, setSettings] = useAtom(settingsAtom);
const updateSettings = (update: Partial<Settings>) => {
const newSettings = { ...settings, ...update };
setSettings(newSettings);
};
return [settings, updateSettings] as const;
};