mirror of https://github.com/vector-im/riot-web
Remove getBaseTheme
This was only used by vector/index.js, in the code removed by https://github.com/vector-im/riot-web/pull/11445 React SDK does a very similar thing in setTheme but also gets the rest of the custom theme name. Requires https://github.com/vector-im/riot-web/pull/11445pull/21833/head
parent
518130c912
commit
b69cee0c67
23
src/theme.js
23
src/theme.js
|
@ -127,28 +127,14 @@ function getCustomTheme(themeName) {
|
||||||
return customTheme;
|
return customTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the underlying theme name for the given theme. This is usually the theme or
|
|
||||||
* CSS resource that the theme relies upon to load.
|
|
||||||
* @param {string} theme The theme name to get the base of.
|
|
||||||
* @returns {string} The base theme (typically "light" or "dark").
|
|
||||||
*/
|
|
||||||
export function getBaseTheme(theme) {
|
|
||||||
if (!theme) return "light";
|
|
||||||
if (theme.startsWith("custom-")) {
|
|
||||||
const customTheme = getCustomTheme(theme.substr(7));
|
|
||||||
return customTheme.is_dark ? "dark-custom" : "light-custom";
|
|
||||||
}
|
|
||||||
|
|
||||||
return theme; // it's probably a base theme
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever someone changes the theme
|
* Called whenever someone changes the theme
|
||||||
|
* Async function that returns once the theme has been set
|
||||||
|
* (ie. the CSS has been loaded)
|
||||||
*
|
*
|
||||||
* @param {string} theme new theme
|
* @param {string} theme new theme
|
||||||
*/
|
*/
|
||||||
export function setTheme(theme) {
|
export async function setTheme(theme) {
|
||||||
if (!theme) {
|
if (!theme) {
|
||||||
const themeWatcher = new ThemeWatcher();
|
const themeWatcher = new ThemeWatcher();
|
||||||
theme = themeWatcher.getEffectiveTheme();
|
theme = themeWatcher.getEffectiveTheme();
|
||||||
|
@ -190,6 +176,7 @@ export function setTheme(theme) {
|
||||||
|
|
||||||
styleElements[stylesheetName].disabled = false;
|
styleElements[stylesheetName].disabled = false;
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
const switchTheme = function() {
|
const switchTheme = function() {
|
||||||
// we re-enable our theme here just in case we raced with another
|
// we re-enable our theme here just in case we raced with another
|
||||||
// theme set request as per https://github.com/vector-im/riot-web/issues/5601.
|
// theme set request as per https://github.com/vector-im/riot-web/issues/5601.
|
||||||
|
@ -201,6 +188,7 @@ export function setTheme(theme) {
|
||||||
a.disabled = true;
|
a.disabled = true;
|
||||||
});
|
});
|
||||||
Tinter.setTheme(theme);
|
Tinter.setTheme(theme);
|
||||||
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
// turns out that Firefox preloads the CSS for link elements with
|
// turns out that Firefox preloads the CSS for link elements with
|
||||||
|
@ -224,4 +212,5 @@ export function setTheme(theme) {
|
||||||
styleElements[stylesheetName].onload = undefined;
|
styleElements[stylesheetName].onload = undefined;
|
||||||
switchTheme();
|
switchTheme();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue