@@ -39,9 +39,6 @@ import url from 'url';
3939
4040import { parseQs , parseQsFromFragment } from './url_utils' ;
4141
42- import ElectronPlatform from './platform/ElectronPlatform' ;
43- import WebPlatform from './platform/WebPlatform' ;
44-
4542import { MatrixClientPeg } from 'matrix-react-sdk/src/MatrixClientPeg' ;
4643import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore" ;
4744import SdkConfig from "matrix-react-sdk/src/SdkConfig" ;
@@ -50,6 +47,7 @@ import {setTheme} from "matrix-react-sdk/src/theme";
5047import Olm from 'olm' ;
5148
5249import CallHandler from 'matrix-react-sdk/src/CallHandler' ;
50+ import { loadConfig , preparePlatform } from "./initial-load" ;
5351
5452let lastLocationHashSet = null ;
5553
@@ -191,35 +189,11 @@ export async function loadApp() {
191189 await loadOlm ( ) ;
192190
193191 // set the platform for react sdk
194- if ( window . ipcRenderer ) {
195- console . log ( "Using Electron platform" ) ;
196- const plaf = new ElectronPlatform ( ) ;
197- PlatformPeg . set ( plaf ) ;
198- } else {
199- console . log ( "Using Web platform" ) ;
200- PlatformPeg . set ( new WebPlatform ( ) ) ;
201- }
202-
192+ preparePlatform ( ) ;
203193 const platform = PlatformPeg . get ( ) ;
204194
205- let configJson ;
206- let configError ;
207- let configSyntaxError = false ;
208- try {
209- configJson = await platform . getConfig ( ) ;
210- } catch ( e ) {
211- configError = e ;
212-
213- if ( e && e . err && e . err instanceof SyntaxError ) {
214- console . error ( "SyntaxError loading config:" , e ) ;
215- configSyntaxError = true ;
216- configJson = { } ; // to prevent errors between here and loading CSS for the error box
217- }
218- }
219-
220- // XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure
221- // granular settings are loaded correctly and to avoid duplicating the override logic for the theme.
222- SdkConfig . put ( configJson ) ;
195+ // Load the config from the platform
196+ const configInfo = await loadConfig ( ) ;
223197
224198 // Load language after loading config.json so that settingsDefaults.language can be applied
225199 await loadLanguage ( ) ;
@@ -248,7 +222,7 @@ export async function loadApp() {
248222 await setTheme ( ) ;
249223
250224 // Now that we've loaded the theme (CSS), display the config syntax error if needed.
251- if ( configSyntaxError ) {
225+ if ( configInfo . configSyntaxError ) {
252226 const errorMessage = (
253227 < div >
254228 < p >
@@ -260,7 +234,7 @@ export async function loadApp() {
260234 < p >
261235 { _t (
262236 "The message from the parser is: %(message)s" ,
263- { message : configError . err . message || _t ( "Invalid JSON" ) } ,
237+ { message : configInfo . configError . err . message || _t ( "Invalid JSON" ) } ,
264238 ) }
265239 </ p >
266240 </ div >
@@ -280,7 +254,7 @@ export async function loadApp() {
280254
281255 const urlWithoutQuery = window . location . protocol + '//' + window . location . host + window . location . pathname ;
282256 console . log ( "Vector starting at " + urlWithoutQuery ) ;
283- if ( configError ) {
257+ if ( configInfo . configError ) {
284258 window . matrixChat = ReactDOM . render ( < div className = "error" >
285259 Unable to load config file: please refresh the page to try again.
286260 </ div > , document . getElementById ( 'matrixchat' ) ) ;
@@ -298,7 +272,7 @@ export async function loadApp() {
298272 config = { newConfig }
299273 realQueryParams = { params }
300274 startingFragmentQueryParams = { fragparts . params }
301- enableGuest = { ! configJson . disable_guests }
275+ enableGuest = { ! SdkConfig . get ( ) . disable_guests }
302276 onTokenLoginCompleted = { onTokenLoginCompleted }
303277 initialScreenAfterLogin = { getScreenFromLocation ( window . location ) }
304278 defaultDeviceDisplayName = { platform . getDefaultDeviceDisplayName ( ) }
0 commit comments