@@ -41,8 +41,9 @@ var ReactDOM = require("react-dom");
4141var sdk = require ( "matrix-react-sdk" ) ;
4242sdk . loadSkin ( require ( '../component-index' ) ) ;
4343var VectorConferenceHandler = require ( '../VectorConferenceHandler' ) ;
44- var configJson = require ( "../../config.json" ) ;
4544var UpdateChecker = require ( "./updater" ) ;
45+ var q = require ( 'q' ) ;
46+ var request = require ( 'browser-request' ) ;
4647
4748var qs = require ( "querystring" ) ;
4849
@@ -112,6 +113,8 @@ function parseQs(location) {
112113// Here, we do some crude URL analysis to allow
113114// deep-linking.
114115function routeUrl ( location ) {
116+ if ( ! window . matrixChat ) return ;
117+
115118 console . log ( "Routing URL " + window . location ) ;
116119 var params = parseQs ( location ) ;
117120 var loginToken = params . loginToken ;
@@ -182,22 +185,58 @@ window.onload = function() {
182185 }
183186}
184187
185- function loadApp ( ) {
188+ function getConfig ( ) {
189+ let deferred = q . defer ( ) ;
190+
191+ request (
192+ { method : "GET" , url : "config.json" , json : true } ,
193+ ( err , response , body ) => {
194+ if ( err || response . status < 200 || response . status >= 300 ) {
195+ deferred . reject ( { err : err , response : response } ) ;
196+ return ;
197+ }
198+
199+ deferred . resolve ( body ) ;
200+ }
201+ ) ;
202+
203+ return deferred . promise ;
204+ }
205+
206+ async function loadApp ( ) {
186207 if ( / i P a d | i P h o n e | i P o d / . test ( navigator . userAgent ) && ! window . MSStream ) {
187208 if ( confirm ( "Vector runs much better as an app on iOS. Get the app?" ) ) {
188209 window . location = "https://itunes.apple.com/us/app/vector.im/id1083446067" ;
189210 return ;
190211 }
191212 }
192213 else if ( / A n d r o i d / . test ( navigator . userAgent ) ) {
193- if ( confirm ( "Vector runs much better as an app on Vector . Get the app?" ) ) {
214+ if ( confirm ( "Vector runs much better as an app on Android . Get the app?" ) ) {
194215 window . location = "https://play.google.com/store/apps/details?id=im.vector.alpha" ;
195216 return ;
196217 }
197218 }
198219
220+ let configJson ;
221+ let configError ;
222+ try {
223+ configJson = await getConfig ( ) ;
224+ } catch ( e ) {
225+ // On 404 errors, carry on without a config,
226+ // but on other errors, fail, otherwise it will
227+ // lead to subtle errors where the app runs with
228+ // the default config if it fails to fetch config.json.
229+ if ( e . response . status != 404 ) {
230+ configError = e ;
231+ }
232+ }
233+
199234 console . log ( "Vector starting at " + window . location ) ;
200- if ( validBrowser ) {
235+ if ( configError ) {
236+ window . matrixChat = ReactDOM . render ( < div className = "error" >
237+ Unable to load config file: please refresh the page to try again.
238+ </ div > , document . getElementById ( 'matrixchat' ) ) ;
239+ } else if ( validBrowser ) {
201240 var MatrixChat = sdk . getComponent ( 'structures.MatrixChat' ) ;
202241 var fragParts = parseQsFromFragment ( window . location ) ;
203242 window . matrixChat = ReactDOM . render (
0 commit comments