support concept of default theme

pull/5578/head
Matthew Hodgson 2017-10-20 18:41:39 +01:00
parent c6f75fbf37
commit 6fa2d35630
3 changed files with 19 additions and 2 deletions

View File

@ -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"

View File

@ -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';
%>
<link rel="<%= light ? '' : 'alternate ' %>stylesheet" title="<%= title %>"
<link rel="alternate stylesheet" title="<%= title %>"
href="<%= file %>">
<% } else { %>
<link rel="stylesheet" href="<%= file %>">

View File

@ -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;