Skip to content

Commit 6fa2d35

Browse files
committed
support concept of default theme
1 parent c6f75fb commit 6fa2d35

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎config.sample.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"bug_report_endpoint_url": "https://riot.im/bugreports/submit",
88
"enableLabs": true,
99
"default_federate": true,
10+
"default_theme": "light",
1011
"roomDirectory": {
1112
"servers": [
1213
"matrix.org"

‎src/vector/index.html‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
var match = file.match(/^bundles\/.*?\/theme-(.*)\.css$/);
2626
if (match) {
2727
var title = match[1].charAt(0).toUpperCase() + match[1].slice(1);
28-
var light = match[1] == 'light';
2928
%>
30-
<link rel="<%= light ? '' : 'alternate ' %>stylesheet" title="<%= title %>"
29+
<link rel="alternate stylesheet" title="<%= title %>"
3130
href="<%= file %>">
3231
<% } else { %>
3332
<link rel="stylesheet" href="<%= file %>">

‎src/vector/index.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ async function loadApp() {
281281
configError = e;
282282
}
283283

284+
// as quickly as we possibly can, set a default theme...
285+
const styleElements = Object.create(null);
286+
let a;
287+
for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
288+
const href = a.getAttribute("href");
289+
// shouldn't we be using the 'title' tag rather than the href?
290+
const match = href.match(/^bundles\/.*\/theme-(.*)\.css$/);
291+
if (match) {
292+
if (match[1] === (configJson.default_theme || 'light')) {
293+
// remove the alternative flag off the stylesheet
294+
a.setAttribute("rel", "stylesheet");
295+
}
296+
}
297+
}
298+
// XXX: do we also need to call MatrixChat.setTheme here to do any random fixups (e.g. svg tint)
299+
300+
284301
if (window.localStorage && window.localStorage.getItem('mx_accepts_unsupported_browser')) {
285302
console.log('User has previously accepted risks in using an unsupported browser');
286303
validBrowser = true;

0 commit comments

Comments
 (0)