Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c8c4dc2

Browse files
authored
Merge pull request #3503 from matrix-org/bwindels/custom-themes-mvp
Custom theming MVP
2 parents 4b6c916 + 27ca73b commit c8c4dc2

File tree

13 files changed

+299
-110
lines changed

13 files changed

+299
-110
lines changed

docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ order of prioirty, are:
1515
* `room-account` - The current user's account, but only when in a specific room
1616
* `account` - The current user's account
1717
* `room` - A specific room (setting for all members of the room)
18-
* `config` - Values are defined by `config.json`
18+
* `config` - Values are defined by the `settingDefaults` key (usually) in `config.json`
1919
* `default` - The hardcoded default for the settings
2020

2121
Individual settings may control which levels are appropriate for them as part of the defaults. This is often to ensure

res/css/structures/_RoomSubList.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ limitations under the License.
7070
.mx_RoomSubList_badge {
7171
flex: 0 0 auto;
7272
border-radius: 8px;
73-
color: $accent-fg-color;
7473
font-weight: 600;
7574
font-size: 12px;
7675
padding: 0 5px;
76+
color: $roomtile-badge-fg-color;
7777
background-color: $roomtile-name-color;
7878
cursor: pointer;
7979
}
@@ -104,6 +104,7 @@ limitations under the License.
104104
}
105105

106106
.mx_RoomSubList_badgeHighlight {
107+
color: $accent-fg-color;
107108
background-color: $warning-color;
108109
}
109110

res/css/views/rooms/_RoomTile.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ limitations under the License.
110110
flex: 0 1 content;
111111
border-radius: 0.8em;
112112
padding: 0 0.4em;
113-
color: $accent-fg-color;
113+
color: $roomtile-badge-fg-color;
114114
font-weight: 600;
115115
font-size: 12px;
116116
}
@@ -156,6 +156,7 @@ limitations under the License.
156156

157157
.mx_RoomTile_highlight .mx_RoomTile_badge,
158158
.mx_RoomTile_badge.mx_RoomTile_badgeRed {
159+
color: $accent-fg-color;
159160
background-color: $warning-color;
160161
}
161162

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import "../../light/css/_paths.scss";
2+
@import "../../light/css/_fonts.scss";
3+
@import "../../light/css/_light.scss";
4+
@import "../../dark/css/_dark.scss";
5+
@import "../../light-custom/css/_custom.scss";
6+
@import "../../../../res/css/_components.scss";
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Copyright 2019 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//
18+
// --accent-color
19+
$accent-color: var(--accent-color);
20+
$button-bg-color: var(--accent-color);
21+
$button-link-fg-color: var(--accent-color);
22+
$button-primary-bg-color: var(--accent-color);
23+
$input-valid-border-color: var(--accent-color);
24+
$reaction-row-button-selected-border-color: var(--accent-color);
25+
$roomsublist-chevron-color: var(--accent-color);
26+
$tab-label-active-bg-color: var(--accent-color);
27+
$togglesw-on-color: var(--accent-color);
28+
$username-variant3-color: var(--accent-color);
29+
$accent-color-50pct: var(--accent-color-50pct); //still needs alpha at .5
30+
//
31+
// --timeline-background-color
32+
$authpage-body-bg-color: var(--timeline-background-color);
33+
$button-secondary-bg-color: var(--timeline-background-color);
34+
$field-focused-label-bg-color: var(--timeline-background-color);
35+
$lightbox-border-color: var(--timeline-background-color);
36+
$menu-bg-color: var(--timeline-background-color);
37+
$avatar-bg-color: var(--timeline-background-color);
38+
$message-action-bar-bg-color: var(--timeline-background-color);
39+
$primary-bg-color: var(--timeline-background-color);
40+
$roomtile-focused-bg-color: var(--timeline-background-color);
41+
$togglesw-ball-color: var(--timeline-background-color);
42+
$droptarget-bg-color: var(--timeline-background-color-50pct); //still needs alpha at .5
43+
$authpage-modal-bg-color: var(--timeline-background-color-50pct); //still needs alpha at .59
44+
//
45+
// --roomlist-highlights-color
46+
$roomtile-selected-bg-color: var(--roomlist-highlights-color);
47+
//
48+
// --sidebar-color
49+
$interactive-tooltip-bg-color: var(--sidebar-color);
50+
$tagpanel-bg-color: var(--sidebar-color);
51+
$tooltip-timeline-bg-color: var(--sidebar-color);
52+
$dialog-backdrop-color: var(--sidebar-color-50pct);
53+
//
54+
// --roomlist-background-color
55+
$event-selected-color: var(--roomlist-background-color);
56+
$header-panel-bg-color: var(--roomlist-background-color);
57+
$reaction-row-button-bg-color: var(--roomlist-background-color);
58+
$panel-gradient: var(--roomlist-background-color-0pct), var(--roomlist-background-color);
59+
// these were #f2f5f8 instead of #f3f8fd, but close enough
60+
$dark-panel-bg-color: var(--roomlist-background-color);
61+
$input-lighter-bg-color: var(--roomlist-background-color);
62+
$plinth-bg-color: var(--roomlist-background-color);
63+
$roomsublist-background: var(--roomlist-background-color);
64+
$secondary-accent-color: var(--roomlist-background-color);
65+
$selected-color: var(--roomlist-background-color);
66+
$widget-menu-bar-bg-color: var(--roomlist-background-color);
67+
$roomtile-badge-fg-color: var(--roomlist-background-color);
68+
//
69+
// --timeline-text-color
70+
$message-action-bar-fg-color: var(--timeline-text-color);
71+
$primary-fg-color: var(--timeline-text-color);
72+
$settings-profile-overlay-placeholder-fg-color: var(--timeline-text-color);
73+
$roomtopic-color: var(--timeline-text-color-50pct);
74+
$tab-label-fg-color: var(--timeline-text-color);
75+
$tab-label-icon-bg-color: var(--timeline-text-color); //was #454545
76+
// was #212121
77+
$topleftmenu-color: var(--timeline-text-color);
78+
// was #45474a
79+
$dialog-title-fg-color: var(--timeline-text-color);
80+
$tab-label-fg-color: var(--timeline-text-color);
81+
// was #4e5054
82+
$authpage-lang-color: var(--timeline-text-color);
83+
$roomheader-color: var(--timeline-text-color);
84+
//
85+
// --roomlist-text-color
86+
$roomtile-notified-color: var(--roomlist-text-color);
87+
$roomtile-selected-color: var(--roomlist-text-color);
88+
//
89+
// --roomlist-text-secondary-color
90+
$roomsublist-label-fg-color: var(--roomlist-text-secondary-color);
91+
$roomtile-name-color: var(--roomlist-text-secondary-color);
92+
//
93+
// --roomlist-separator-color
94+
$input-darker-bg-color: var(--roomlist-separator-color);
95+
$panel-divider-color: var(--roomlist-separator-color);// originally #dee1f3, but close enough
96+
$primary-hairline-color: var(--roomlist-separator-color);// originally #e5e5e5, but close enough
97+
//
98+
// --timeline-text-secondary-color
99+
$authpage-secondary-color: var(--timeline-text-secondary-color);
100+
$memberstatus-placeholder-color: var(--timeline-text-secondary-color);
101+
$notice-secondary-color: var(--timeline-text-secondary-color);
102+
$pinned-color: var(--timeline-text-secondary-color);
103+
$settings-subsection-fg-color: var(--timeline-text-secondary-color);
104+
$roomheader-addroom-bg-color: var(--timeline-text-secondary-color);
105+
// was #747474
106+
$light-fg-color: var(--timeline-text-secondary-color);
107+
// was #777777
108+
$blockquote-fg-color: var(--timeline-text-secondary-color);
109+
// was #888888
110+
$greyed-fg-color: var(--timeline-text-secondary-color);
111+
$info-plinth-fg-color: var(--timeline-text-secondary-color);
112+
$preview-widget-fg-color: var(--timeline-text-secondary-color);
113+
//
114+
// --primary-color
115+
$accent-color-alt: var(--primary-color);
116+
$input-focused-border-color: var(--primary-color);
117+
//
118+
// --warning-color
119+
$button-danger-bg-color: var(--warning-color);
120+
$event-highlight-fg-color: var(--warning-color);
121+
$input-invalid-border-color: var(--warning-color);
122+
$mention-user-pill-bg-color: var(--warning-color);
123+
$notice-primary-color: var(--warning-color);
124+
$pinned-unread-color: var(--warning-color);
125+
$warning-color: var(--warning-color);
126+
$button-danger-disabled-bg-color: var(--warning-color-50pct); // still needs alpha at 0.5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "../../light/css/_paths.scss";
2+
@import "../../light/css/_fonts.scss";
3+
@import "../../light/css/_light.scss";
4+
@import "_custom.scss";
5+
@import "../../../../res/css/_components.scss";

res/themes/light/css/_light.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ $header-divider-color: #91A1C0;
167167
// ********************
168168

169169
$roomtile-name-color: #61708b;
170+
$roomtile-badge-fg-color: $accent-fg-color;
170171
$roomtile-selected-color: #212121;
171172
$roomtile-notified-color: #212121;
172173
$roomtile-selected-bg-color: #fff;
@@ -234,7 +235,7 @@ $tab-label-active-fg-color: #ffffff;
234235
$tab-label-bg-color: transparent;
235236
$tab-label-active-bg-color: $accent-color;
236237
$tab-label-icon-bg-color: #454545;
237-
$tab-label-active-icon-bg-color: #ffffff;
238+
$tab-label-active-icon-bg-color: $tab-label-active-fg-color;
238239

239240
// Buttons
240241
$button-primary-fg-color: #ffffff;

src/components/structures/MatrixChat.js

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { ValidatedServerConfig } from "../../utils/AutoDiscoveryUtils";
5959
import AutoDiscoveryUtils from "../../utils/AutoDiscoveryUtils";
6060
import DMRoomMap from '../../utils/DMRoomMap';
6161
import { countRoomsWithNotif } from '../../RoomNotifs';
62+
import { setTheme } from "../../theme";
6263

6364
// Disable warnings for now: we use deprecated bluebird functions
6465
// and need to migrate, but they spam the console with warnings.
@@ -661,7 +662,7 @@ export default createReactClass({
661662
break;
662663
}
663664
case 'set_theme':
664-
this._onSetTheme(payload.value);
665+
setTheme(payload.value);
665666
break;
666667
case 'on_logging_in':
667668
// We are now logging in, so set the state to reflect that
@@ -1105,82 +1106,6 @@ export default createReactClass({
11051106
});
11061107
},
11071108

1108-
/**
1109-
* Called whenever someone changes the theme
1110-
*
1111-
* @param {string} theme new theme
1112-
*/
1113-
_onSetTheme: function(theme) {
1114-
if (!theme) {
1115-
theme = SettingsStore.getValue("theme");
1116-
}
1117-
1118-
// look for the stylesheet elements.
1119-
// styleElements is a map from style name to HTMLLinkElement.
1120-
const styleElements = Object.create(null);
1121-
let a;
1122-
for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
1123-
const href = a.getAttribute("href");
1124-
// shouldn't we be using the 'title' tag rather than the href?
1125-
const match = href.match(/^bundles\/.*\/theme-(.*)\.css$/);
1126-
if (match) {
1127-
styleElements[match[1]] = a;
1128-
}
1129-
}
1130-
1131-
if (!(theme in styleElements)) {
1132-
throw new Error("Unknown theme " + theme);
1133-
}
1134-
1135-
// disable all of them first, then enable the one we want. Chrome only
1136-
// bothers to do an update on a true->false transition, so this ensures
1137-
// that we get exactly one update, at the right time.
1138-
//
1139-
// ^ This comment was true when we used to use alternative stylesheets
1140-
// for the CSS. Nowadays we just set them all as disabled in index.html
1141-
// and enable them as needed. It might be cleaner to disable them all
1142-
// at the same time to prevent loading two themes simultaneously and
1143-
// having them interact badly... but this causes a flash of unstyled app
1144-
// which is even uglier. So we don't.
1145-
1146-
styleElements[theme].disabled = false;
1147-
1148-
const switchTheme = function() {
1149-
// we re-enable our theme here just in case we raced with another
1150-
// theme set request as per https://github.com/vector-im/riot-web/issues/5601.
1151-
// We could alternatively lock or similar to stop the race, but
1152-
// this is probably good enough for now.
1153-
styleElements[theme].disabled = false;
1154-
Object.values(styleElements).forEach((a) => {
1155-
if (a == styleElements[theme]) return;
1156-
a.disabled = true;
1157-
});
1158-
Tinter.setTheme(theme);
1159-
};
1160-
1161-
// turns out that Firefox preloads the CSS for link elements with
1162-
// the disabled attribute, but Chrome doesn't.
1163-
1164-
let cssLoaded = false;
1165-
1166-
styleElements[theme].onload = () => {
1167-
switchTheme();
1168-
};
1169-
1170-
for (let i = 0; i < document.styleSheets.length; i++) {
1171-
const ss = document.styleSheets[i];
1172-
if (ss && ss.href === styleElements[theme].href) {
1173-
cssLoaded = true;
1174-
break;
1175-
}
1176-
}
1177-
1178-
if (cssLoaded) {
1179-
styleElements[theme].onload = undefined;
1180-
switchTheme();
1181-
}
1182-
},
1183-
11841109
/**
11851110
* Starts a chat with the welcome user, if the user doesn't already have one
11861111
* @returns {string} The room ID of the new room, or null if no room was created

src/components/views/settings/tabs/user/GeneralUserSettingsTab.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import LanguageDropdown from "../../../elements/LanguageDropdown";
2727
import AccessibleButton from "../../../elements/AccessibleButton";
2828
import DeactivateAccountDialog from "../../../dialogs/DeactivateAccountDialog";
2929
import PropTypes from "prop-types";
30-
import {THEMES} from "../../../../../themes";
30+
import {enumerateThemes} from "../../../../../theme";
3131
import PlatformPeg from "../../../../../PlatformPeg";
3232
import MatrixClientPeg from "../../../../../MatrixClientPeg";
3333
import sdk from "../../../../..";
@@ -275,8 +275,8 @@ export default class GeneralUserSettingsTab extends React.Component {
275275
<span className="mx_SettingsTab_subheading">{_t("Theme")}</span>
276276
<Field id="theme" label={_t("Theme")} element="select"
277277
value={this.state.theme} onChange={this._onThemeChange}>
278-
{Object.entries(THEMES).map(([theme, text]) => {
279-
return <option key={theme} value={theme}>{_t(text)}</option>;
278+
{Object.entries(enumerateThemes()).map(([theme, text]) => {
279+
return <option key={theme} value={theme}>{text}</option>;
280280
})}
281281
</Field>
282282
<SettingsFlag name="useCompactLayout" level={SettingLevel.ACCOUNT} />

src/settings/Settings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ export const SETTINGS = {
245245
default: "light",
246246
controller: new ThemeController(),
247247
},
248+
"custom_themes": {
249+
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
250+
default: [],
251+
},
248252
"webRtcAllowPeerToPeer": {
249253
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
250254
displayName: _td('Allow Peer-to-Peer for 1:1 calls'),

0 commit comments

Comments
 (0)