@@ -23,7 +23,6 @@ import React from 'react';
2323// access via the console
2424global . React = React ;
2525
26- import ReactDOM from 'react-dom' ;
2726import * as sdk from 'matrix-react-sdk' ;
2827import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg' ;
2928import * as VectorConferenceHandler from 'matrix-react-sdk/src/VectorConferenceHandler' ;
@@ -45,41 +44,6 @@ import {loadConfig, preparePlatform, loadLanguage, loadOlm} from "./init";
4544
4645let lastLocationHashSet = null ;
4746
48- function checkBrowserFeatures ( ) {
49- if ( ! window . Modernizr ) {
50- console . error ( "Cannot check features - Modernizr global is missing." ) ;
51- return false ;
52- }
53-
54- // custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on,
55- // Modernizr requires rules to be lowercase with no punctuation:
56- // ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally
57- window . Modernizr . addTest ( "promiseprototypefinally" , ( ) =>
58- window . Promise && window . Promise . prototype && typeof window . Promise . prototype . finally === "function" ) ;
59- // ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries
60- window . Modernizr . addTest ( "objectfromentries" , ( ) =>
61- window . Object && typeof window . Object . fromEntries === "function" ) ;
62-
63- const featureList = Object . keys ( window . Modernizr ) ;
64-
65- let featureComplete = true ;
66- for ( let i = 0 ; i < featureList . length ; i ++ ) {
67- if ( window . Modernizr [ featureList [ i ] ] === undefined ) {
68- console . error (
69- "Looked for feature '%s' but Modernizr has no results for this. " +
70- "Has it been configured correctly?" , featureList [ i ] ,
71- ) ;
72- return false ;
73- }
74- if ( window . Modernizr [ featureList [ i ] ] === false ) {
75- console . error ( "Browser missing feature: '%s'" , featureList [ i ] ) ;
76- // toggle flag rather than return early so we log all missing features rather than just the first.
77- featureComplete = false ;
78- }
79- }
80- return featureComplete ;
81- }
82-
8347// Parse the given window.location and return parameters that can be used when calling
8448// MatrixChat.showScreen(screen, params)
8549function getScreenFromLocation ( location ) {
@@ -164,7 +128,7 @@ function onTokenLoginCompleted() {
164128 window . location . href = formatted ;
165129}
166130
167- export async function loadApp ( ) {
131+ export async function loadApp ( fragParams : { } , acceptBrowser : boolean ) {
168132 // XXX: the way we pass the path to the worker script from webpack via html in body's dataset is a hack
169133 // but alternatives seem to require changing the interface to passing Workers to js-sdk
170134 const vectorIndexeddbWorkerScript = document . body . dataset . vectorIndexeddbWorkerScript ;
@@ -192,26 +156,8 @@ export async function loadApp() {
192156 // Load language after loading config.json so that settingsDefaults.language can be applied
193157 await loadLanguage ( ) ;
194158
195- const fragparts = parseQsFromFragment ( window . location ) ;
196159 const params = parseQs ( window . location ) ;
197160
198- // don't try to redirect to the native apps if we're
199- // verifying a 3pid (but after we've loaded the config)
200- // or if the user is following a deep link
201- // (https://github.com/vector-im/riot-web/issues/7378)
202- const preventRedirect = fragparts . params . client_secret || fragparts . location . length > 0 ;
203-
204- if ( ! preventRedirect ) {
205- const isIos = / i P a d | i P h o n e | i P o d / . test ( navigator . userAgent ) && ! window . MSStream ;
206- const isAndroid = / A n d r o i d / . test ( navigator . userAgent ) ;
207- if ( isIos || isAndroid ) {
208- if ( document . cookie . indexOf ( "riot_mobile_redirect_to_guide=false" ) === - 1 ) {
209- window . location = "mobile_guide/" ;
210- return ;
211- }
212- }
213- }
214-
215161 // as quickly as we possibly can, set a default theme...
216162 await setTheme ( ) ;
217163
@@ -235,45 +181,35 @@ export async function loadApp() {
235181 ) ;
236182
237183 const GenericErrorPage = sdk . getComponent ( "structures.GenericErrorPage" ) ;
238- window . matrixChat = ReactDOM . render (
239- < GenericErrorPage message = { errorMessage } title = { _t ( "Your Riot is misconfigured" ) } /> ,
240- document . getElementById ( 'matrixchat' ) ,
241- ) ;
242- return ;
184+ return < GenericErrorPage message = { errorMessage } title = { _t ( "Your Riot is misconfigured" ) } /> ;
243185 }
244186
245- const validBrowser = checkBrowserFeatures ( ) ;
246-
247- const acceptInvalidBrowser = window . localStorage && window . localStorage . getItem ( 'mx_accepts_unsupported_browser' ) ;
248-
249187 const urlWithoutQuery = window . location . protocol + '//' + window . location . host + window . location . pathname ;
250188 console . log ( "Vector starting at " + urlWithoutQuery ) ;
251189 if ( configError ) {
252- window . matrixChat = ReactDOM . render ( < div className = "error" >
190+ return < div className = "error" >
253191 Unable to load config file: please refresh the page to try again.
254- </ div > , document . getElementById ( 'matrixchat' ) ) ;
255- } else if ( validBrowser || acceptInvalidBrowser ) {
192+ </ div > ;
193+ } else if ( acceptBrowser ) {
256194 platform . startUpdater ( ) ;
257195
258- // Don't bother loading the app until the config is verified
259- verifyServerConfig ( ) . then ( ( newConfig ) => {
196+ try {
197+ // Don't bother loading the app until the config is verified
198+ const config = await verifyServerConfig ( ) ;
260199 const MatrixChat = sdk . getComponent ( 'structures.MatrixChat' ) ;
261- window . matrixChat = ReactDOM . render (
262- < MatrixChat
263- onNewScreen = { onNewScreen }
264- makeRegistrationUrl = { makeRegistrationUrl }
265- ConferenceHandler = { VectorConferenceHandler }
266- config = { newConfig }
267- realQueryParams = { params }
268- startingFragmentQueryParams = { fragparts . params }
269- enableGuest = { ! SdkConfig . get ( ) . disable_guests }
270- onTokenLoginCompleted = { onTokenLoginCompleted }
271- initialScreenAfterLogin = { getScreenFromLocation ( window . location ) }
272- defaultDeviceDisplayName = { platform . getDefaultDeviceDisplayName ( ) }
273- /> ,
274- document . getElementById ( 'matrixchat' ) ,
275- ) ;
276- } ) . catch ( err => {
200+ return < MatrixChat
201+ onNewScreen = { onNewScreen }
202+ makeRegistrationUrl = { makeRegistrationUrl }
203+ ConferenceHandler = { VectorConferenceHandler }
204+ config = { config }
205+ realQueryParams = { params }
206+ startingFragmentQueryParams = { fragParams }
207+ enableGuest = { ! config . disable_guests }
208+ onTokenLoginCompleted = { onTokenLoginCompleted }
209+ initialScreenAfterLogin = { getScreenFromLocation ( window . location ) }
210+ defaultDeviceDisplayName = { platform . getDefaultDeviceDisplayName ( ) }
211+ /> ;
212+ } catch ( err ) {
277213 console . error ( err ) ;
278214
279215 let errorMessage = err . translatedMessage
@@ -282,23 +218,17 @@ export async function loadApp() {
282218
283219 // Like the compatibility page, AWOOOOOGA at the user
284220 const GenericErrorPage = sdk . getComponent ( "structures.GenericErrorPage" ) ;
285- window . matrixChat = ReactDOM . render (
286- < GenericErrorPage message = { errorMessage } title = { _t ( "Your Riot is misconfigured" ) } /> ,
287- document . getElementById ( 'matrixchat' ) ,
288- ) ;
289- } ) ;
221+ return < GenericErrorPage message = { errorMessage } title = { _t ( "Your Riot is misconfigured" ) } /> ;
222+ }
290223 } else {
291224 console . error ( "Browser is missing required features." ) ;
292225 // take to a different landing page to AWOOOOOGA at the user
293226 const CompatibilityPage = sdk . getComponent ( "structures.CompatibilityPage" ) ;
294- window . matrixChat = ReactDOM . render (
295- < CompatibilityPage onAccept = { function ( ) {
296- if ( window . localStorage ) window . localStorage . setItem ( 'mx_accepts_unsupported_browser' , true ) ;
297- console . log ( "User accepts the compatibility risks." ) ;
298- loadApp ( ) ;
299- } } /> ,
300- document . getElementById ( 'matrixchat' ) ,
301- ) ;
227+ return < CompatibilityPage onAccept = { function ( ) {
228+ if ( window . localStorage ) window . localStorage . setItem ( 'mx_accepts_unsupported_browser' , true ) ;
229+ console . log ( "User accepts the compatibility risks." ) ;
230+ loadApp ( ) ;
231+ } } /> ;
302232 }
303233}
304234
@@ -384,7 +314,6 @@ async function verifyServerConfig() {
384314 }
385315 }
386316
387-
388317 validatedConfig . isDefault = true ;
389318
390319 // Just in case we ever have to debug this
0 commit comments