diff --git a/app/(auth)/(tabs)/(home)/index.tsx b/app/(auth)/(tabs)/(home)/index.tsx index 0675f12f..0b018087 100644 --- a/app/(auth)/(tabs)/(home)/index.tsx +++ b/app/(auth)/(tabs)/(home)/index.tsx @@ -59,7 +59,13 @@ export default function index() { const user = useAtomValue(userAtom); const [loading, setLoading] = useState(false); - const [settings, _] = useSettings(); + const [ + settings, + updateSettings, + pluginSettings, + setPluginSettings, + refreshStreamyfinPluginSettings, + ] = useSettings(); const [isConnected, setIsConnected] = useState(null); const [loadingRetry, setLoadingRetry] = useState(false); @@ -69,6 +75,14 @@ export default function index() { const insets = useSafeAreaInsets(); + useEffect(() => { + const interval = setInterval(async () => { + await refreshStreamyfinPluginSettings(); + }, 60 * 10 * 1000); // 10 min + + return () => clearInterval(interval); + }, []); + useEffect(() => { const hasDownloads = downloadedFiles && downloadedFiles.length > 0; navigation.setOptions({ @@ -110,6 +124,7 @@ export default function index() { cleanCacheDirectory().catch((e) => console.error("Something went wrong cleaning cache directory") ); + return () => { unsubscribe(); }; @@ -154,6 +169,7 @@ export default function index() { const refetch = useCallback(async () => { setLoading(true); + await refreshStreamyfinPluginSettings(); await invalidateCache(); setLoading(false); }, []); diff --git a/components/settings/OtherSettings.tsx b/components/settings/OtherSettings.tsx index dcea3f26..7c49a100 100644 --- a/components/settings/OtherSettings.tsx +++ b/components/settings/OtherSettings.tsx @@ -9,7 +9,7 @@ import * as BackgroundFetch from "expo-background-fetch"; import { useRouter } from "expo-router"; import * as ScreenOrientation from "expo-screen-orientation"; import * as TaskManager from "expo-task-manager"; -import React, {useEffect, useMemo} from "react"; +import React, { useEffect, useMemo } from "react"; import { Linking, Switch, TouchableOpacity } from "react-native"; import { toast } from "sonner-native"; import { Text } from "../common/Text"; @@ -52,28 +52,28 @@ export const OtherSettings: React.FC = () => { /********************** *********************/ - const disabled = useMemo(() => ( - pluginSettings?.autoRotate?.locked === true && - pluginSettings?.defaultVideoOrientation?.locked === true && - pluginSettings?.safeAreaInControlsEnabled?.locked === true && - pluginSettings?.showCustomMenuLinks?.locked === true && - pluginSettings?.hiddenLibraries?.locked === true && - pluginSettings?.disableHapticFeedback?.locked === true - ), [pluginSettings]); + const disabled = useMemo( + () => + pluginSettings?.autoRotate?.locked === true && + pluginSettings?.defaultVideoOrientation?.locked === true && + pluginSettings?.safeAreaInControlsEnabled?.locked === true && + pluginSettings?.showCustomMenuLinks?.locked === true && + pluginSettings?.hiddenLibraries?.locked === true && + pluginSettings?.disableHapticFeedback?.locked === true, + [pluginSettings] + ); const orientations = [ ScreenOrientation.OrientationLock.DEFAULT, ScreenOrientation.OrientationLock.PORTRAIT_UP, ScreenOrientation.OrientationLock.LANDSCAPE_LEFT, - ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT - ] + ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT, + ]; if (!settings) return null; return ( - + { updateSettings({autoRotate: value})} + onValueChange={(value) => updateSettings({ autoRotate: value })} /> - ScreenOrientationEnum[item] + disabled={ + pluginSettings?.defaultVideoOrientation?.locked || + settings.autoRotate } + keyExtractor={String} + titleExtractor={(item) => ScreenOrientationEnum[item]} title={ {ScreenOrientationEnum[settings.defaultVideoOrientation]} - + } label="Orientation" onSelected={(defaultVideoOrientation) => - updateSettings({defaultVideoOrientation}) + updateSettings({ defaultVideoOrientation }) } /> @@ -120,7 +128,7 @@ export const OtherSettings: React.FC = () => { value={settings.safeAreaInControlsEnabled} disabled={pluginSettings?.safeAreaInControlsEnabled?.locked} onValueChange={(value) => - updateSettings({safeAreaInControlsEnabled: value}) + updateSettings({ safeAreaInControlsEnabled: value }) } /> @@ -138,7 +146,7 @@ export const OtherSettings: React.FC = () => { value={settings.showCustomMenuLinks} disabled={pluginSettings?.showCustomMenuLinks?.locked} onValueChange={(value) => - updateSettings({showCustomMenuLinks: value}) + updateSettings({ showCustomMenuLinks: value }) } /> @@ -155,7 +163,7 @@ export const OtherSettings: React.FC = () => { value={settings.disableHapticFeedback} disabled={pluginSettings?.disableHapticFeedback?.locked} onValueChange={(disableHapticFeedback) => - updateSettings({disableHapticFeedback}) + updateSettings({ disableHapticFeedback }) } /> diff --git a/utils/atoms/settings.ts b/utils/atoms/settings.ts index a16c51a6..a4d1a135 100644 --- a/utils/atoms/settings.ts +++ b/utils/atoms/settings.ts @@ -221,11 +221,13 @@ export const useSettings = () => { const refreshStreamyfinPluginSettings = useCallback(async () => { if (!api) return; - const settings = await api - .getStreamyfinPluginConfig() - .then(({ data }) => data?.settings); - - writeInfoLog(`Got remote settings: ${JSON.stringify(settings)}`); + const settings = await api.getStreamyfinPluginConfig().then( + ({ data }) => { + writeInfoLog(`Got remote settings`); + return data?.settings; + }, + (err) => undefined + ); setPluginSettings(settings); return settings;