1- import { updatePreferences } from '@renderer/store/preferences/slice' ;
2- import store from '@renderer/store/store' ;
1+ import { useAppDispatch } from '@renderer/hooks/useAppSelector' ;
2+ import { setMainState } from '@renderer/store/main/slice' ;
3+ import { setPreferences , updatePreferences } from '@renderer/store/preferences/slice' ;
4+ import store , { AppDispatch } from '@renderer/store/store' ;
35import { logFactory } from '@renderer/util/logging' ;
46import { SocketClient } from '@shared/back/SocketClient' ;
57import { BackIn , BackOut } from '@shared/back/types' ;
68import { InitRendererData } from '@shared/IPC' ;
79import { LogLevel } from '@shared/Log/interface' ;
8- import { setTheme } from '@shared/Theme' ;
910import { createErrorProxy } from '@shared/Util' ;
1011import EventEmitter from 'node:events' ;
1112import * as path from 'node:path' ;
1213import { ReactNode , useState } from 'react' ;
1314import { Spinner } from './Spinner' ;
15+ import { ThemeProvider } from './ThemeProvider' ;
1416
1517type AppLoaderProps = {
1618 children : ReactNode ,
@@ -30,7 +32,7 @@ async function waitForConnection(host: string): Promise<WebSocket> {
3032 }
3133}
3234
33- const onInit = async ( data : InitRendererData ) => {
35+ const onInit = async ( data : InitRendererData , dispatch : AppDispatch ) => {
3436 // Store value(s)
3537 window . Shared . isBackRemote = data . isBackRemote ;
3638 window . Shared . backUrl = new URL ( data . host ) ;
@@ -60,6 +62,10 @@ const onInit = async (data: InitRendererData) => {
6062 const initData = await window . Shared . back . request ( BackIn . GET_RENDERER_INIT_DATA ) ;
6163 if ( initData ) {
6264 window . Shared . initialPreferences = initData . preferences ;
65+ window . Shared . initialThemes = initData . themes ;
66+ // Set some things early so Theme provider works
67+ dispatch ( setMainState ( { themeList : initData . themes } ) ) ;
68+ dispatch ( setPreferences ( initData . preferences ) ) ;
6369 window . Shared . config = {
6470 data : initData . config ,
6571 // @FIXTHIS This should take if this is installed into account
@@ -71,12 +77,7 @@ const onInit = async (data: InitRendererData) => {
7177 window . Shared . customVersion = initData . customVersion ;
7278 window . Shared . initialLang = initData . language ;
7379 window . Shared . initialLangList = initData . languages ;
74- window . Shared . initialThemes = initData . themes ;
7580 window . Shared . initialLocaleCode = initData . localeCode ;
76- if ( window . Shared . initialPreferences . currentTheme ) {
77- const theme = window . Shared . initialThemes . find ( t => t . id === window . Shared . initialPreferences . currentTheme ) ;
78- if ( theme ) { setTheme ( theme ) ; }
79- }
8081 } else {
8182 throw 'No data given by host?' ;
8283 }
@@ -177,6 +178,7 @@ export function AppLoader(props: AppLoaderProps) {
177178 const [ isInitDone , setIsInitDone ] = useState ( false ) ;
178179 const [ initError , setInitError ] = useState < string > ( ) ;
179180 const [ showSpinner , setShowSpinner ] = useState ( false ) ;
181+ const dispatch = useAppDispatch ( ) ;
180182
181183 if ( ! loaderInit ) {
182184 setLoaderInit ( true ) ;
@@ -185,7 +187,7 @@ export function AppLoader(props: AppLoaderProps) {
185187 setShowSpinner ( true ) ;
186188 } , 800 ) ;
187189 // Run initialization script
188- onInit ( props . data )
190+ onInit ( props . data , dispatch )
189191 . then ( ( ) => {
190192 setIsInitDone ( true ) ;
191193 } )
@@ -200,26 +202,32 @@ export function AppLoader(props: AppLoaderProps) {
200202 </ div > ;
201203 }
202204
203- if ( ! isInitDone ) {
204- return < div style = { { width : '100%' , height : '100%' , display : 'flex' , flexDirection : 'column' } } >
205- { showSpinner && (
206- < div className = 'splash-screen' >
207- < div className = 'splash-screen__logo' >
208- < Spinner />
209- </ div >
210- < div className = 'splash-screen__status-block' >
211- < div className = 'splash-screen__status-header' >
212- Connecting...
205+ if ( loaderInit && ! isInitDone ) {
206+ return (
207+ < ThemeProvider >
208+ < div style = { { width : '100%' , height : '100%' , display : 'flex' , flexDirection : 'column' } } >
209+ { showSpinner && (
210+ < div className = 'splash-screen' >
211+ < div className = 'splash-screen__logo' >
212+ < Spinner />
213+ </ div >
214+ < div className = 'splash-screen__status-block' >
215+ < div className = 'splash-screen__status-header' >
216+ Connecting...
217+ </ div >
218+ </ div >
213219 </ div >
214- </ div >
220+ ) }
215221 </ div >
216- ) }
217- </ div > ;
222+ </ ThemeProvider >
223+ ) ;
218224 }
219225
220226 return (
221- < div style = { { width : '100%' , height : '100%' , display : 'flex' , flexDirection : 'column' } } >
222- { props . children }
223- </ div >
227+ < ThemeProvider >
228+ < div style = { { width : '100%' , height : '100%' , display : 'flex' , flexDirection : 'column' } } >
229+ { props . children }
230+ </ div >
231+ </ ThemeProvider >
224232 ) ;
225233}
0 commit comments