@@ -86,7 +86,7 @@ function getCurrentValue(name) {
86
86
return null ;
87
87
}
88
88
89
- function switchTheme ( styleElem , mainStyleElem , newTheme ) {
89
+ function switchTheme ( styleElem , mainStyleElem , newTheme , skipStorage ) {
90
90
var fullBasicCss = "rustdoc" + resourcesSuffix + ".css" ;
91
91
var fullNewTheme = newTheme + resourcesSuffix + ".css" ;
92
92
var newHref = mainStyleElem . href . replace ( fullBasicCss , fullNewTheme ) ;
@@ -109,8 +109,18 @@ function switchTheme(styleElem, mainStyleElem, newTheme) {
109
109
} ) ;
110
110
if ( found === true ) {
111
111
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
+ }
113
117
}
114
118
}
115
119
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