Skip to content

Commit 8b2ca56

Browse files
authored
Merge pull request element-hq#11445 from vector-im/dbkr/dedup_theming_code
De-dup theming code
2 parents 234e789 + e34c46c commit 8b2ca56

1 file changed

Lines changed: 2 additions & 49 deletions

File tree

‎src/vector/index.js‎

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import WebPlatform from './platform/WebPlatform';
5757
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
5858
import SettingsStore from "matrix-react-sdk/lib/settings/SettingsStore";
5959
import SdkConfig from "matrix-react-sdk/lib/SdkConfig";
60-
import {getBaseTheme, setTheme, ThemeWatcher} from "matrix-react-sdk/lib/theme";
60+
import {setTheme} from "matrix-react-sdk/lib/theme";
6161

6262
import Olm from 'olm';
6363

@@ -255,54 +255,7 @@ async function loadApp() {
255255
}
256256

257257
// as quickly as we possibly can, set a default theme...
258-
// we do this by checking to see if the theme's "base" has loaded first so we can
259-
// safely rely on the assets.
260-
let a;
261-
const themeWatcher = new ThemeWatcher();
262-
const theme = themeWatcher.getEffectiveTheme();
263-
const baseTheme = getBaseTheme(theme);
264-
for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
265-
const href = a.getAttribute("href");
266-
if (!href) continue;
267-
// shouldn't we be using the 'title' tag rather than the href?
268-
const match = href.match(/^bundles\/.*\/theme-(.*)\.css$/);
269-
if (match) {
270-
if (match[1] === baseTheme) {
271-
// remove the disabled flag off the stylesheet
272-
273-
// Firefox requires setting the attribute to false, so do
274-
// that instead of removing it. Related:
275-
// https://bugzilla.mozilla.org/show_bug.cgi?id=1281135
276-
a.disabled = false;
277-
278-
// in case the Tinter.tint() in MatrixChat fires before the
279-
// CSS has actually loaded (which in practice happens)...
280-
281-
// This if fixes setTheme to not fire on Firefox
282-
// in case it is the first time loading Riot.
283-
// `InstallTrigger` is a Object which only exists on Firefox
284-
// (it is used for their Plugins) and can be used as a
285-
// feature check.
286-
// Firefox loads css always before js. This is why we dont use
287-
// onload or it's EventListener as those will never trigger.
288-
if (typeof InstallTrigger !== 'undefined') {
289-
setTheme(theme);
290-
} else {
291-
// FIXME: we should probably block loading the app or even
292-
// showing a spinner until the theme is loaded, to avoid
293-
// flashes of unstyled content.
294-
a.onload = () => {
295-
setTheme(theme);
296-
};
297-
}
298-
} else {
299-
// Firefox requires this to not be done via `setAttribute`
300-
// or via HTML.
301-
// https://bugzilla.mozilla.org/show_bug.cgi?id=1281135
302-
a.disabled = true;
303-
}
304-
}
305-
}
258+
await setTheme();
306259

307260
// Now that we've loaded the theme (CSS), display the config syntax error if needed.
308261
if (configSyntaxError) {

0 commit comments

Comments
 (0)