From 6fa2d356300767c17d2bd26968b8cad4c6089455 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 20 Oct 2017 18:41:39 +0100 Subject: [PATCH] support concept of default theme --- config.sample.json | 1 + src/vector/index.html | 3 +-- src/vector/index.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config.sample.json b/config.sample.json index a4477ea1..a6378334 100644 --- a/config.sample.json +++ b/config.sample.json @@ -7,6 +7,7 @@ "bug_report_endpoint_url": "https://riot.im/bugreports/submit", "enableLabs": true, "default_federate": true, + "default_theme": "light", "roomDirectory": { "servers": [ "matrix.org" diff --git a/src/vector/index.html b/src/vector/index.html index 49c2979e..864377ee 100644 --- a/src/vector/index.html +++ b/src/vector/index.html @@ -25,9 +25,8 @@ var match = file.match(/^bundles\/.*?\/theme-(.*)\.css$/); if (match) { var title = match[1].charAt(0).toUpperCase() + match[1].slice(1); - var light = match[1] == 'light'; %> - <% } else { %> diff --git a/src/vector/index.js b/src/vector/index.js index a08397ce..f775d1b3 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -281,6 +281,23 @@ async function loadApp() { configError = e; } + // as quickly as we possibly can, set a default theme... + const styleElements = Object.create(null); + let a; + 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')) { + // remove the alternative flag off the stylesheet + a.setAttribute("rel", "stylesheet"); + } + } + } + // 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'); validBrowser = true;