File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import { isValidUrl } from './utils/isValidUrl';
24
24
import CompilerWorker from '../src/workers/compiler?worker' ;
25
25
import FormatterWorker from '../src/workers/formatter?worker' ;
26
26
import useZoom from '../src/hooks/useZoom' ;
27
+ import { isDarkTheme } from './utils/isDarkTheme' ;
27
28
28
29
( window as any ) . MonacoEnvironment = {
29
30
getWorker ( _moduleId : unknown , label : string ) {
@@ -96,7 +97,7 @@ export const App = (): JSX.Element => {
96
97
'noEditableTabs' ,
97
98
] . map ( ( key ) => key in params ) ;
98
99
99
- const [ dark , setDark ] = createSignal ( localStorage . getItem ( 'dark' ) === 'true' ) ;
100
+ const [ dark , setDark ] = createSignal ( isDarkTheme ( ) ) ;
100
101
101
102
createEffect ( ( ) => {
102
103
const action = dark ( ) ? 'add' : 'remove' ;
Original file line number Diff line number Diff line change
1
+ export const isDarkTheme = ( ) => {
2
+ if ( typeof window !== 'undefined' ) {
3
+ if ( window . localStorage ) {
4
+ const isDarkTheme = window . localStorage . getItem ( 'dark' ) ;
5
+ if ( typeof isDarkTheme === 'string' ) {
6
+ return isDarkTheme === 'true' ;
7
+ }
8
+ }
9
+
10
+ const userMedia = window . matchMedia ( '(prefers-color-scheme: dark)' ) ;
11
+ if ( userMedia . matches ) {
12
+ return true ;
13
+ }
14
+ }
15
+
16
+ // Default theme is light.
17
+ return false ;
18
+ } ;
You can’t perform that action at this time.
0 commit comments