@@ -231,10 +231,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
231231 private prevWindowWidth : number ;
232232 private voiceBroadcastResumer ?: VoiceBroadcastResumer ;
233233
234- private readonly loggedInView : React . RefObject < LoggedInViewType > ;
235- private readonly dispatcherRef : string ;
236- private readonly themeWatcher : ThemeWatcher ;
237- private readonly fontWatcher : FontWatcher ;
234+ private readonly loggedInView = createRef < LoggedInViewType > ( ) ;
235+ private dispatcherRef ? : string ;
236+ private themeWatcher ? : ThemeWatcher ;
237+ private fontWatcher ? : FontWatcher ;
238238 private readonly stores : SdkContextClass ;
239239
240240 public constructor ( props : IProps ) {
@@ -256,8 +256,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
256256 ready : false ,
257257 } ;
258258
259- this . loggedInView = createRef ( ) ;
260-
261259 SdkConfig . put ( this . props . config ) ;
262260
263261 // Used by _viewRoom before getting state from sync
@@ -282,32 +280,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
282280 }
283281
284282 this . prevWindowWidth = UIStore . instance . windowWidth || 1000 ;
285- UIStore . instance . on ( UI_EVENTS . Resize , this . handleResize ) ;
286-
287- // For PersistentElement
288- this . state . resizeNotifier . on ( "middlePanelResized" , this . dispatchTimelineResize ) ;
289-
290- RoomNotificationStateStore . instance . on ( UPDATE_STATUS_INDICATOR , this . onUpdateStatusIndicator ) ;
291-
292- this . dispatcherRef = dis . register ( this . onAction ) ;
293-
294- this . themeWatcher = new ThemeWatcher ( ) ;
295- this . fontWatcher = new FontWatcher ( ) ;
296- this . themeWatcher . start ( ) ;
297- this . fontWatcher . start ( ) ;
298283
299284 // object field used for tracking the status info appended to the title tag.
300285 // we don't do it as react state as i'm scared about triggering needless react refreshes.
301286 this . subTitleStatus = "" ;
302-
303- initSentry ( SdkConfig . get ( "sentry" ) ) ;
304-
305- if ( ! checkSessionLockFree ( ) ) {
306- // another instance holds the lock; confirm its theft before proceeding
307- setTimeout ( ( ) => this . setState ( { view : Views . CONFIRM_LOCK_THEFT } ) , 0 ) ;
308- } else {
309- this . startInitSession ( ) ;
310- }
311287 }
312288
313289 /**
@@ -476,6 +452,29 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
476452 }
477453
478454 public componentDidMount ( ) : void {
455+ UIStore . instance . on ( UI_EVENTS . Resize , this . handleResize ) ;
456+
457+ // For PersistentElement
458+ this . state . resizeNotifier . on ( "middlePanelResized" , this . dispatchTimelineResize ) ;
459+
460+ RoomNotificationStateStore . instance . on ( UPDATE_STATUS_INDICATOR , this . onUpdateStatusIndicator ) ;
461+
462+ this . dispatcherRef = dis . register ( this . onAction ) ;
463+
464+ this . themeWatcher = new ThemeWatcher ( ) ;
465+ this . fontWatcher = new FontWatcher ( ) ;
466+ this . themeWatcher . start ( ) ;
467+ this . fontWatcher . start ( ) ;
468+
469+ initSentry ( SdkConfig . get ( "sentry" ) ) ;
470+
471+ if ( ! checkSessionLockFree ( ) ) {
472+ // another instance holds the lock; confirm its theft before proceeding
473+ setTimeout ( ( ) => this . setState ( { view : Views . CONFIRM_LOCK_THEFT } ) , 0 ) ;
474+ } else {
475+ this . startInitSession ( ) ;
476+ }
477+
479478 window . addEventListener ( "resize" , this . onWindowResized ) ;
480479 }
481480
@@ -497,8 +496,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
497496 public componentWillUnmount ( ) : void {
498497 Lifecycle . stopMatrixClient ( ) ;
499498 dis . unregister ( this . dispatcherRef ) ;
500- this . themeWatcher . stop ( ) ;
501- this . fontWatcher . stop ( ) ;
499+ this . themeWatcher ? .stop ( ) ;
500+ this . fontWatcher ? .stop ( ) ;
502501 UIStore . destroy ( ) ;
503502 this . state . resizeNotifier . removeListener ( "middlePanelResized" , this . dispatchTimelineResize ) ;
504503 window . removeEventListener ( "resize" , this . onWindowResized ) ;
@@ -1011,7 +1010,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
10111010
10121011 this . setStateForNewView ( newState ) ;
10131012 ThemeController . isLogin = true ;
1014- this . themeWatcher . recheck ( ) ;
1013+ this . themeWatcher ? .recheck ( ) ;
10151014 this . notifyNewScreen ( isMobileRegistration ? "mobile_register" : "register" ) ;
10161015 }
10171016
@@ -1088,7 +1087,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
10881087 } ,
10891088 ( ) => {
10901089 ThemeController . isLogin = false ;
1091- this . themeWatcher . recheck ( ) ;
1090+ this . themeWatcher ? .recheck ( ) ;
10921091 this . notifyNewScreen ( "room/" + presentedId , replaceLast ) ;
10931092 } ,
10941093 ) ;
@@ -1113,7 +1112,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11131112 } ) ;
11141113 this . notifyNewScreen ( "welcome" ) ;
11151114 ThemeController . isLogin = true ;
1116- this . themeWatcher . recheck ( ) ;
1115+ this . themeWatcher ? .recheck ( ) ;
11171116 }
11181117
11191118 private viewLogin ( otherState ?: any ) : void {
@@ -1123,7 +1122,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11231122 } ) ;
11241123 this . notifyNewScreen ( "login" ) ;
11251124 ThemeController . isLogin = true ;
1126- this . themeWatcher . recheck ( ) ;
1125+ this . themeWatcher ? .recheck ( ) ;
11271126 }
11281127
11291128 private viewHome ( justRegistered = false ) : void {
@@ -1136,7 +1135,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11361135 this . setPage ( PageType . HomePage ) ;
11371136 this . notifyNewScreen ( "home" ) ;
11381137 ThemeController . isLogin = false ;
1139- this . themeWatcher . recheck ( ) ;
1138+ this . themeWatcher ? .recheck ( ) ;
11401139 }
11411140
11421141 private viewUser ( userId : string , subAction : string ) : void {
@@ -1357,7 +1356,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13571356 */
13581357 private async onLoggedIn ( ) : Promise < void > {
13591358 ThemeController . isLogin = false ;
1360- this . themeWatcher . recheck ( ) ;
1359+ this . themeWatcher ? .recheck ( ) ;
13611360 StorageManager . tryPersistStorage ( ) ;
13621361
13631362 await this . onShowPostLoginScreen ( ) ;
0 commit comments