@@ -6,7 +6,7 @@ import Region from "./region.jsx";
66import "./screen.scss" ;
77import logger from "../logger/logger" ;
88import TouchRegion from "./touch-region.jsx" ;
9- import ConfigLoader from "../../shared/ config-loader" ;
9+ import ClientConfigLoader from "../client- config-loader.js " ;
1010
1111/**
1212 * Screen component.
@@ -32,41 +32,41 @@ function Screen({ screen }) {
3232 } ;
3333
3434 const refreshColorScheme = ( ) => {
35- const config = ConfigLoader . getConfig ( ) ;
36-
3735 logger . info ( "Refreshing color scheme." ) ;
3836
39- const now = new Date ( ) ;
40- let colorScheme = "" ;
37+ ClientConfigLoader . loadConfig ( ) . then ( ( config ) => {
38+ const now = new Date ( ) ;
39+ let colorScheme ;
4140
42- if ( config . colorScheme ?. type === "library" ) {
43- // Default to somewhere in Denmark.
44- const times = SunCalc . getTimes (
45- now ,
46- config . colorScheme ?. lat ?? 56.0 ,
47- config . colorScheme ?. lng ?? 10.0
48- ) ;
41+ if ( config . colorScheme ?. type === "library" ) {
42+ // Default to somewhere in Denmark.
43+ const times = SunCalc . getTimes (
44+ now ,
45+ config . colorScheme ?. lat ?? 56.0 ,
46+ config . colorScheme ?. lng ?? 10.0
47+ ) ;
4948
50- if ( now > times . sunrise && now < times . sunset ) {
51- logger . info ( "Light color scheme activated." ) ;
52- colorScheme = "color-scheme-light" ;
49+ if ( now > times . sunrise && now < times . sunset ) {
50+ logger . info ( "Light color scheme activated." ) ;
51+ colorScheme = "color-scheme-light" ;
52+ } else {
53+ logger . info ( "Dark color scheme activated." ) ;
54+ colorScheme = "color-scheme-dark" ;
55+ }
5356 } else {
54- logger . info ( "Dark color scheme activated." ) ;
55- colorScheme = "color-scheme-dark" ;
57+ // Browser based.
58+ colorScheme = window ?. matchMedia ( "(prefers-color-scheme: dark)" ) . matches
59+ ? "color-scheme-dark"
60+ : "color-scheme-light" ;
5661 }
57- } else {
58- // Browser based.
59- colorScheme = window ?. matchMedia ( "(prefers-color-scheme: dark)" ) . matches
60- ? "color-scheme-dark"
61- : "color-scheme-light" ;
62- }
6362
64- // Set class name on html root.
65- document . documentElement . classList . remove (
66- "color-scheme-light" ,
67- "color-scheme-dark"
68- ) ;
69- document . documentElement . classList . add ( colorScheme ) ;
63+ // Set class name on html root.
64+ document . documentElement . classList . remove (
65+ "color-scheme-light" ,
66+ "color-scheme-dark"
67+ ) ;
68+ document . documentElement . classList . add ( colorScheme ) ;
69+ } ) ;
7070 } ;
7171
7272 useEffect ( ( ) => {
0 commit comments