File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,17 +30,24 @@ const appContainer = ref(null)
3030// Set user theme
3131// --------------------------------------------------------------------
3232
33- const desiredTheme = window .localStorage ? .getItem (' theme' )
34- if (desiredTheme === ' dark' ) {
35- siteStore .theme = ' dark'
36- } else if (desiredTheme === ' light' ) {
37- siteStore .theme = ' light'
38- } else if (window .matchMedia (" (prefers-color-scheme: dark)" ).matches ) {
39- siteStore .theme = ' dark'
40- } else {
41- siteStore .theme = ' light'
33+ function updateTheme () {
34+ const desiredTheme = window .localStorage ? .getItem (' theme' )
35+ if (desiredTheme === ' dark' ) {
36+ siteStore .theme = ' dark'
37+ } else if (desiredTheme === ' light' ) {
38+ siteStore .theme = ' light'
39+ } else if (window .matchMedia (" (prefers-color-scheme: dark)" ).matches ) {
40+ siteStore .theme = ' dark'
41+ } else {
42+ siteStore .theme = ' light'
43+ }
4244}
4345
46+ updateTheme ()
47+
48+ // this change event fires for either light or dark changes
49+ window .matchMedia (' (prefers-color-scheme: dark)' ).addEventListener (' change' , updateTheme)
50+
4451// --------------------------------------------------------------------
4552// Handle browser resize
4653// --------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments