1- import { createContext , useContext , useEffect , useState } from 'react' ;
1+ import { createContext , useContext , useEffect , useLayoutEffect , useState } from 'react' ;
22import {
33 DataFeedMessage ,
44 DataFeedUpdateT ,
@@ -12,8 +12,9 @@ import { useBonesDataFeedConfig, useDataFeedConfig } from './datafeed-config';
1212import { useWebsocketAPI } from './websocket-api' ;
1313import { useAtomValue , useSetAtom } from 'jotai' ;
1414import { bonesAtom , datafeedAtom , devicesAtom } from '@/store/app-store' ;
15- import { updateSentryContext } from '@/utils/sentry' ;
15+ import { getSentryOrCompute , updateSentryContext } from '@/utils/sentry' ;
1616import { fetchCurrentFirmwareRelease , FirmwareRelease } from './firmware-update' ;
17+ import { DEFAULT_LOCALE , LangContext } from '@/i18n/config' ;
1718
1819export interface AppContext {
1920 currentFirmwareRelease : FirmwareRelease | null ;
@@ -22,6 +23,7 @@ export interface AppContext {
2223export function useProvideAppContext ( ) : AppContext {
2324 const { useRPCPacket, sendDataFeedPacket, useDataFeedPacket, isConnected } =
2425 useWebsocketAPI ( ) ;
26+ const { changeLocales } = useContext ( LangContext ) ;
2527 const { config } = useConfig ( ) ;
2628 const { dataFeedConfig } = useDataFeedConfig ( ) ;
2729 const bonesDataFeedConfig = useBonesDataFeedConfig ( ) ;
@@ -58,14 +60,30 @@ export function useProvideAppContext(): AppContext {
5860 } ) ;
5961
6062 useEffect ( ( ) => {
63+ if ( ! config ) return ;
64+
6165 const interval = setInterval ( ( ) => {
62- fetchCurrentFirmwareRelease ( ) . then ( ( res ) => setCurrentFirmwareRelease ( res ) ) ;
66+ fetchCurrentFirmwareRelease ( config . uuid ) . then ( setCurrentFirmwareRelease ) ;
6367 } , 1000 ) ;
6468 return ( ) => {
6569 clearInterval ( interval ) ;
6670 } ;
71+ } , [ config ?. uuid ] ) ;
72+
73+ useLayoutEffect ( ( ) => {
74+ changeLocales ( [ config ?. lang || DEFAULT_LOCALE ] ) ;
6775 } , [ ] ) ;
6876
77+ useLayoutEffect ( ( ) => {
78+ if ( ! config ) return ;
79+ if ( config . errorTracking !== undefined ) {
80+ console . log ( 'change' ) ;
81+ // Alows for sentry to refresh if user change the setting once the gui
82+ // is initialized
83+ getSentryOrCompute ( config . errorTracking ?? false , config . uuid ) ;
84+ }
85+ } , [ config ] ) ;
86+
6987 return {
7088 currentFirmwareRelease,
7189 } ;
0 commit comments