@@ -86,7 +86,7 @@ function getCurrentValue(name) {
8686 return null ;
8787}
8888
89- function switchTheme ( styleElem , mainStyleElem , newTheme ) {
89+ function switchTheme ( styleElem , mainStyleElem , newTheme , skipStorage ) {
9090 var fullBasicCss = "rustdoc" + resourcesSuffix + ".css" ;
9191 var fullNewTheme = newTheme + resourcesSuffix + ".css" ;
9292 var newHref = mainStyleElem . href . replace ( fullBasicCss , fullNewTheme ) ;
@@ -109,8 +109,18 @@ function switchTheme(styleElem, mainStyleElem, newTheme) {
109109 } ) ;
110110 if ( found === true ) {
111111 styleElem . href = newHref ;
112- updateLocalStorage ( "rustdoc-theme" , newTheme ) ;
112+ // If this new value comes from a system setting or from the previously saved theme, no
113+ // need to save it.
114+ if ( skipStorage !== true ) {
115+ updateLocalStorage ( "rustdoc-theme" , newTheme ) ;
116+ }
113117 }
114118}
115119
116- switchTheme ( currentTheme , mainTheme , getCurrentValue ( "rustdoc-theme" ) || "light" ) ;
120+ function getSystemValue ( ) {
121+ return getComputedStyle ( document . documentElement ) . getPropertyValue ( 'content' ) ;
122+ }
123+
124+ switchTheme ( currentTheme , mainTheme ,
125+ getCurrentValue ( "rustdoc-theme" ) || getSystemValue ( ) || "light" ,
126+ true ) ;
0 commit comments