@@ -18,8 +18,6 @@ See the License for the specific language governing permissions and
1818limitations under the License.
1919*/
2020
21- import olmWasmPath from 'olm/olm.wasm' ;
22-
2321import React from 'react' ;
2422// add React and ReactPerf to the global namespace, to make them easier to
2523// access via the console
@@ -29,7 +27,6 @@ import ReactDOM from 'react-dom';
2927import * as sdk from 'matrix-react-sdk' ;
3028import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg' ;
3129import * as VectorConferenceHandler from 'matrix-react-sdk/src/VectorConferenceHandler' ;
32- import * as languageHandler from 'matrix-react-sdk/src/languageHandler' ;
3330import { _t , _td , newTranslatableError } from 'matrix-react-sdk/src/languageHandler' ;
3431import AutoDiscoveryUtils from 'matrix-react-sdk/src/utils/AutoDiscoveryUtils' ;
3532import { AutoDiscovery } from "matrix-js-sdk/src/autodiscovery" ;
@@ -40,14 +37,11 @@ import url from 'url';
4037import { parseQs , parseQsFromFragment } from './url_utils' ;
4138
4239import { MatrixClientPeg } from 'matrix-react-sdk/src/MatrixClientPeg' ;
43- import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore" ;
4440import SdkConfig from "matrix-react-sdk/src/SdkConfig" ;
4541import { setTheme } from "matrix-react-sdk/src/theme" ;
4642
47- import Olm from 'olm' ;
48-
4943import CallHandler from 'matrix-react-sdk/src/CallHandler' ;
50- import { loadConfig , preparePlatform } from "./initial-load " ;
44+ import { loadConfig , preparePlatform , loadLanguage , loadOlm } from "./init " ;
5145
5246let lastLocationHashSet = null ;
5347
@@ -193,7 +187,7 @@ export async function loadApp() {
193187 const platform = PlatformPeg . get ( ) ;
194188
195189 // Load the config from the platform
196- const configInfo = await loadConfig ( ) ;
190+ const configError = await loadConfig ( ) ;
197191
198192 // Load language after loading config.json so that settingsDefaults.language can be applied
199193 await loadLanguage ( ) ;
@@ -222,7 +216,7 @@ export async function loadApp() {
222216 await setTheme ( ) ;
223217
224218 // Now that we've loaded the theme (CSS), display the config syntax error if needed.
225- if ( configInfo . configSyntaxError ) {
219+ if ( configError && configError . err && configError . err instanceof SyntaxError ) {
226220 const errorMessage = (
227221 < div >
228222 < p >
@@ -234,7 +228,7 @@ export async function loadApp() {
234228 < p >
235229 { _t (
236230 "The message from the parser is: %(message)s" ,
237- { message : configInfo . configError . err . message || _t ( "Invalid JSON" ) } ,
231+ { message : configError . err . message || _t ( "Invalid JSON" ) } ,
238232 ) }
239233 </ p >
240234 </ div >
@@ -254,7 +248,7 @@ export async function loadApp() {
254248
255249 const urlWithoutQuery = window . location . protocol + '//' + window . location . host + window . location . pathname ;
256250 console . log ( "Vector starting at " + urlWithoutQuery ) ;
257- if ( configInfo . configError ) {
251+ if ( configError ) {
258252 window . matrixChat = ReactDOM . render ( < div className = "error" >
259253 Unable to load config file: please refresh the page to try again.
260254 </ div > , document . getElementById ( 'matrixchat' ) ) ;
@@ -308,62 +302,6 @@ export async function loadApp() {
308302 }
309303}
310304
311- function loadOlm ( ) {
312- /* Load Olm. We try the WebAssembly version first, and then the legacy,
313- * asm.js version if that fails. For this reason we need to wait for this
314- * to finish before continuing to load the rest of the app. In future
315- * we could somehow pass a promise down to react-sdk and have it wait on
316- * that so olm can be loading in parallel with the rest of the app.
317- *
318- * We also need to tell the Olm js to look for its wasm file at the same
319- * level as index.html. It really should be in the same place as the js,
320- * ie. in the bundle directory, but as far as I can tell this is
321- * completely impossible with webpack. We do, however, use a hashed
322- * filename to avoid caching issues.
323- */
324- return Olm . init ( {
325- locateFile : ( ) => olmWasmPath ,
326- } ) . then ( ( ) => {
327- console . log ( "Using WebAssembly Olm" ) ;
328- } ) . catch ( ( e ) => {
329- console . log ( "Failed to load Olm: trying legacy version" , e ) ;
330- return new Promise ( ( resolve , reject ) => {
331- const s = document . createElement ( 'script' ) ;
332- s . src = 'olm_legacy.js' ; // XXX: This should be cache-busted too
333- s . onload = resolve ;
334- s . onerror = reject ;
335- document . body . appendChild ( s ) ;
336- } ) . then ( ( ) => {
337- // Init window.Olm, ie. the one just loaded by the script tag,
338- // not 'Olm' which is still the failed wasm version.
339- return window . Olm . init ( ) ;
340- } ) . then ( ( ) => {
341- console . log ( "Using legacy Olm" ) ;
342- } ) . catch ( ( e ) => {
343- console . log ( "Both WebAssembly and asm.js Olm failed!" , e ) ;
344- } ) ;
345- } ) ;
346- }
347-
348- async function loadLanguage ( ) {
349- const prefLang = SettingsStore . getValue ( "language" , null , /*excludeDefault=*/ true ) ;
350- let langs = [ ] ;
351-
352- if ( ! prefLang ) {
353- languageHandler . getLanguagesFromBrowser ( ) . forEach ( ( l ) => {
354- langs . push ( ...languageHandler . getNormalizedLanguageKeys ( l ) ) ;
355- } ) ;
356- } else {
357- langs = [ prefLang ] ;
358- }
359- try {
360- await languageHandler . setLanguage ( langs ) ;
361- document . documentElement . setAttribute ( "lang" , languageHandler . getCurrentLanguage ( ) ) ;
362- } catch ( e ) {
363- console . error ( "Unable to set language" , e ) ;
364- }
365- }
366-
367305async function verifyServerConfig ( ) {
368306 let validatedConfig ;
369307 try {
0 commit comments