mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-04 03:36:29 +08:00
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { DarkTheme, DefaultTheme, ThemeProvider } from "@react-navigation/native";
|
|
import { useFonts } from "expo-font";
|
|
import { Stack } from "expo-router";
|
|
import * as SplashScreen from "expo-splash-screen";
|
|
import { useEffect } from "react";
|
|
import { Platform } from "react-native";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
import { useSettingsStore } from "@/stores/settingsStore";
|
|
import { useRemoteControlStore } from "@/stores/remoteControlStore";
|
|
import LoginModal from "@/components/LoginModal";
|
|
import useAuthStore from "@/stores/authStore";
|
|
|
|
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
|
SplashScreen.preventAutoHideAsync();
|
|
|
|
export default function RootLayout() {
|
|
const colorScheme = "dark";
|
|
const [loaded, error] = useFonts({
|
|
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
|
|
});
|
|
const { loadSettings, remoteInputEnabled, apiBaseUrl } = useSettingsStore();
|
|
const { startServer, stopServer } = useRemoteControlStore();
|
|
const { checkLoginStatus } = useAuthStore();
|
|
|
|
useEffect(() => {
|
|
loadSettings();
|
|
}, [loadSettings]);
|
|
|
|
useEffect(() => {
|
|
if (apiBaseUrl) {
|
|
checkLoginStatus(apiBaseUrl);
|
|
}
|
|
}, [apiBaseUrl, checkLoginStatus]);
|
|
|
|
useEffect(() => {
|
|
if (loaded || error) {
|
|
SplashScreen.hideAsync();
|
|
if (error) {
|
|
console.warn(`Error in loading fonts: ${error}`);
|
|
}
|
|
}
|
|
}, [loaded, error]);
|
|
|
|
useEffect(() => {
|
|
if (remoteInputEnabled) {
|
|
startServer();
|
|
} else {
|
|
stopServer();
|
|
}
|
|
}, [remoteInputEnabled, startServer, stopServer]);
|
|
|
|
if (!loaded && !error) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
|
|
<Stack>
|
|
<Stack.Screen name="index" options={{ headerShown: false }} />
|
|
<Stack.Screen name="detail" options={{ headerShown: false }} />
|
|
{Platform.OS !== "web" && <Stack.Screen name="play" options={{ headerShown: false }} />}
|
|
<Stack.Screen name="search" options={{ headerShown: false }} />
|
|
<Stack.Screen name="live" options={{ headerShown: false }} />
|
|
<Stack.Screen name="settings" options={{ headerShown: false }} />
|
|
<Stack.Screen name="favorites" options={{ headerShown: false }} />
|
|
<Stack.Screen name="+not-found" />
|
|
</Stack>
|
|
<Toast />
|
|
<LoginModal />
|
|
</ThemeProvider>
|
|
);
|
|
}
|