Skip to content

Commit 74c09b4

Browse files
Make theme setting work with previous versions
1 parent ad61dc9 commit 74c09b4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/librustdoc/html/static/js/storage.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ function getSettingValue(settingName) {
4343
}
4444

4545
function isUsingSystemTheme() {
46-
const current = getSettingValue("theme");
46+
const current = getTheme();
4747
return current === null || current === "system-preference";
4848
}
4949

50-
const localStoredTheme = getSettingValue("theme");
50+
function getTheme() {
51+
const current = getSettingValue("theme2");
52+
if (current === null) {
53+
// We try to get what's being used in the previous version.
54+
return getSettingValue("theme");
55+
}
56+
return current;
57+
}
5158

5259
const savedHref = [];
5360

@@ -200,7 +207,7 @@ const updateSystemTheme = (function() {
200207
// the user disables "use-system-theme" and reloads the page or
201208
// navigates to another page
202209
} else {
203-
use(getSettingValue("theme"), true);
210+
use(getTheme(), true);
204211
}
205212
}
206213

@@ -215,18 +222,18 @@ function switchToSavedTheme() {
215222
switchTheme(
216223
window.currentTheme,
217224
window.mainTheme,
218-
getSettingValue("theme") || "light",
225+
getTheme() || "light",
219226
false
220227
);
221228
}
222229

223230
if (isUsingSystemTheme() && window.matchMedia) {
224231
// update the preferred dark theme if the user is already using a dark theme
225232
// See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732
226-
if (getSettingValue("theme") === null
233+
if (getTheme() === null
227234
&& getSettingValue("preferred-dark-theme") === null
228-
&& darkThemes.indexOf(localStoredTheme) >= 0) {
229-
updateLocalStorage("preferred-dark-theme", localStoredTheme);
235+
&& darkThemes.indexOf(getTheme()) >= 0) {
236+
updateLocalStorage("preferred-dark-theme", getTheme());
230237
}
231238

232239
// call the function to initialize the theme at least once!

0 commit comments

Comments
 (0)