66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
'use client';
|
|
|
|
import i18n from '@/i18n/i18n';
|
|
import { useEffect } from 'react';
|
|
import { IconContext } from 'react-icons';
|
|
import { AuthProvider } from '@/context/AuthContext';
|
|
import { useEnv } from '@/context/EnvContext';
|
|
import { CSPostHogProvider } from '@/context/PHContext';
|
|
import { SyncProvider } from '@/context/SyncContext';
|
|
import { initSystemThemeListener, loadDataTheme } from '@/store/themeStore';
|
|
import { useSettingsStore } from '@/store/settingsStore';
|
|
import { useDeviceControlStore } from '@/store/deviceStore';
|
|
import { useDefaultIconSize } from '@/hooks/useResponsiveSize';
|
|
import { useSafeAreaInsets } from '@/hooks/useSafeAreaInsets';
|
|
import { getLocale } from '@/utils/misc';
|
|
|
|
const Providers = ({ children }: { children: React.ReactNode }) => {
|
|
const { appService } = useEnv();
|
|
const { applyUILanguage } = useSettingsStore();
|
|
const { setScreenBrightness } = useDeviceControlStore();
|
|
const iconSize = useDefaultIconSize();
|
|
useSafeAreaInsets(); // Initialize safe area insets
|
|
|
|
useEffect(() => {
|
|
const handlerLanguageChanged = (lng: string) => {
|
|
document.documentElement.lang = lng;
|
|
};
|
|
|
|
const locale = getLocale();
|
|
handlerLanguageChanged(locale);
|
|
i18n.on('languageChanged', handlerLanguageChanged);
|
|
return () => {
|
|
i18n.off('languageChanged', handlerLanguageChanged);
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
loadDataTheme();
|
|
if (appService) {
|
|
initSystemThemeListener(appService);
|
|
appService.loadSettings().then((settings) => {
|
|
applyUILanguage(settings.globalViewSettings?.uiLanguage);
|
|
const brightness = settings.screenBrightness;
|
|
if (appService.hasScreenBrightness && brightness >= 0) {
|
|
setScreenBrightness(brightness / 100);
|
|
}
|
|
});
|
|
}
|
|
}, [appService, applyUILanguage, setScreenBrightness]);
|
|
|
|
// Make sure appService is available in all children components
|
|
if (!appService) return;
|
|
|
|
return (
|
|
<CSPostHogProvider>
|
|
<AuthProvider>
|
|
<IconContext.Provider value={{ size: `${iconSize}px` }}>
|
|
<SyncProvider>{children}</SyncProvider>
|
|
</IconContext.Provider>
|
|
</AuthProvider>
|
|
</CSPostHogProvider>
|
|
);
|
|
};
|
|
|
|
export default Providers;
|