support concept of default theme

pull/5578/head
Matthew Hodgson 5 years ago
parent c6f75fbf37
commit 6fa2d35630
  1. 1
      config.sample.json
  2. 3
      src/vector/index.html
  3. 17
      src/vector/index.js

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

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

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

Loading…
Cancel
Save