Use a settings watcher to set the theme
Rather than listening for account data updates manually
This commit is contained in:
parent
a0dbd5f62c
commit
80ee68a42f
2 changed files with 12 additions and 11 deletions
|
@ -274,6 +274,7 @@ export default createReactClass({
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
|
this._themeWatchRef = SettingsStore.watchSetting("theme", null, this._onThemeChanged);
|
||||||
|
|
||||||
this.focusComposer = false;
|
this.focusComposer = false;
|
||||||
|
|
||||||
|
@ -360,6 +361,7 @@ export default createReactClass({
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
Lifecycle.stopMatrixClient();
|
Lifecycle.stopMatrixClient();
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
|
SettingsStore.unwatchSetting(this._themeWatchRef);
|
||||||
window.removeEventListener("focus", this.onFocus);
|
window.removeEventListener("focus", this.onFocus);
|
||||||
window.removeEventListener('resize', this.handleResize);
|
window.removeEventListener('resize', this.handleResize);
|
||||||
this.state.resizeNotifier.removeListener("middlePanelResized", this._dispatchTimelineResize);
|
this.state.resizeNotifier.removeListener("middlePanelResized", this._dispatchTimelineResize);
|
||||||
|
@ -382,6 +384,13 @@ export default createReactClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onThemeChanged: function(settingName, roomId, atLevel, newValue) {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'set_theme',
|
||||||
|
value: newValue,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
startPageChangeTimer() {
|
startPageChangeTimer() {
|
||||||
// Tor doesn't support performance
|
// Tor doesn't support performance
|
||||||
if (!performance || !performance.mark) return null;
|
if (!performance || !performance.mark) return null;
|
||||||
|
@ -1376,17 +1385,6 @@ export default createReactClass({
|
||||||
}, null, true);
|
}, null, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.on("accountData", function(ev) {
|
|
||||||
if (ev.getType() === 'im.vector.web.settings') {
|
|
||||||
if (ev.getContent() && ev.getContent().theme) {
|
|
||||||
dis.dispatch({
|
|
||||||
action: 'set_theme',
|
|
||||||
value: ev.getContent().theme,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const dft = new DecryptionFailureTracker((total, errorCode) => {
|
const dft = new DecryptionFailureTracker((total, errorCode) => {
|
||||||
Analytics.trackEvent('E2E', 'Decryption failure', errorCode, total);
|
Analytics.trackEvent('E2E', 'Decryption failure', errorCode, total);
|
||||||
}, (errorCode) => {
|
}, (errorCode) => {
|
||||||
|
|
|
@ -175,6 +175,9 @@ export default class GeneralUserSettingsTab extends React.Component {
|
||||||
|
|
||||||
SettingsStore.setValue("theme", null, SettingLevel.ACCOUNT, newTheme);
|
SettingsStore.setValue("theme", null, SettingLevel.ACCOUNT, newTheme);
|
||||||
this.setState({theme: newTheme});
|
this.setState({theme: newTheme});
|
||||||
|
// The settings watcher doesn't fire until the echo comes back from the
|
||||||
|
// server, so to make the theme change immediately we need to manually
|
||||||
|
// do the dispatch now
|
||||||
dis.dispatch({action: 'set_theme', value: newTheme});
|
dis.dispatch({action: 'set_theme', value: newTheme});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue