From 2fa1f16284d6307f70d668838c120c1073d80f7e Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 8 Nov 2017 06:55:30 -0800 Subject: [PATCH] use new theme-aware tinter api --- src/vector/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 5e3718ea..9e05259a 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -78,6 +78,7 @@ import {parseQs, parseQsFromFragment} from './url_utils'; import Platform from './platform'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; +import Tinter from 'matrix-react-sdk/lib/Tinter'; var lastLocationHashSet = null; @@ -288,19 +289,25 @@ async function loadApp() { // as quickly as we possibly can, set a default theme... const styleElements = Object.create(null); let a; + const theme = configJson.default_theme || 'light'; for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) { const href = a.getAttribute("href"); // shouldn't we be using the 'title' tag rather than the href? const match = href.match(/^bundles\/.*\/theme-(.*)\.css$/); if (match) { - if (match[1] === (configJson.default_theme || 'light')) { + if (match[1] === theme) { // remove the disabled flag off the stylesheet a.removeAttribute("disabled"); + + // in case the Tinter.tint() in MatrixChat fires before the + // CSS has actually loaded (which in practice happens) + a.onload = () => { + Tinter.setTheme(theme); + Tinter.tint(); + }; } } } - // XXX: do we also need to call MatrixChat.setTheme here to do any random fixups (e.g. svg tint) - if (window.localStorage && window.localStorage.getItem('mx_accepts_unsupported_browser')) { console.log('User has previously accepted risks in using an unsupported browser');