]> git.lizzy.rs Git - rust.git/commitdiff
Set preferred-dark-theme to the last dark theme
authornasso <nassomails@gmail.com>
Thu, 15 Oct 2020 16:03:25 +0000 (18:03 +0200)
committernasso <nassomails@gmail.com>
Thu, 15 Oct 2020 16:03:25 +0000 (18:03 +0200)
If the user doesn't have a preferred dark theme but is already using a
dark theme, set the preferred dark theme to be that theme

src/librustdoc/html/static/storage.js

index cf8b806501f3661d0dc18e51f199177360f5a217..a027d6845ea21d8b959c75d7732a0bb4ce33fb13 100644 (file)
@@ -1,8 +1,10 @@
 // From rust:
 /* global resourcesSuffix */
 
+var darkThemes = ["dark", "ayu"];
 var currentTheme = document.getElementById("themeStyle");
 var mainTheme = document.getElementById("mainThemeStyle");
+var localStoredTheme = getCurrentValue("rustdoc-theme");
 
 var savedHref = [];
 
@@ -179,6 +181,14 @@ var updateSystemTheme = (function() {
 })();
 
 if (getCurrentValue("rustdoc-use-system-theme") !== "false" && window.matchMedia) {
+    // update the preferred dark theme if the user is already using a dark theme
+    // See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732
+    if (getCurrentValue("rustdoc-use-system-theme") === null
+        && getCurrentValue("rustdoc-preferred-dark-theme") === null
+        && darkThemes.indexOf(localStoredTheme) >= 0) {
+        updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme);
+    }
+
     // call the function to initialize the theme at least once!
     updateSystemTheme();
 } else {