Skip to content

Commit cc939f9

Browse files
committed
extract browser compatibility error handling out of app.js
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent f6ad5bf commit cc939f9

3 files changed

Lines changed: 54 additions & 45 deletions

File tree

‎src/vector/app.js‎

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function onTokenLoginCompleted() {
126126
window.location.href = formatted;
127127
}
128128

129-
export async function loadApp(fragParams: {}, acceptBrowser: boolean) {
129+
export async function loadApp(fragParams: {}) {
130130
// XXX: the way we pass the path to the worker script from webpack via html in body's dataset is a hack
131131
// but alternatives seem to require changing the interface to passing Workers to js-sdk
132132
const vectorIndexeddbWorkerScript = document.body.dataset.vectorIndexeddbWorkerScript;
@@ -148,45 +148,35 @@ export async function loadApp(fragParams: {}, acceptBrowser: boolean) {
148148

149149
const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname;
150150
console.log("Vector starting at " + urlWithoutQuery);
151-
if (acceptBrowser) {
152-
platform.startUpdater();
153-
154-
try {
155-
// Don't bother loading the app until the config is verified
156-
const config = await verifyServerConfig();
157-
const MatrixChat = sdk.getComponent('structures.MatrixChat');
158-
return <MatrixChat
159-
onNewScreen={onNewScreen}
160-
makeRegistrationUrl={makeRegistrationUrl}
161-
ConferenceHandler={VectorConferenceHandler}
162-
config={config}
163-
realQueryParams={params}
164-
startingFragmentQueryParams={fragParams}
165-
enableGuest={!config.disable_guests}
166-
onTokenLoginCompleted={onTokenLoginCompleted}
167-
initialScreenAfterLogin={getScreenFromLocation(window.location)}
168-
defaultDeviceDisplayName={platform.getDefaultDeviceDisplayName()}
169-
/>;
170-
} catch (err) {
171-
console.error(err);
172-
173-
let errorMessage = err.translatedMessage
174-
|| _t("Unexpected error preparing the app. See console for details.");
175-
errorMessage = <span>{errorMessage}</span>;
176-
177-
// Like the compatibility page, AWOOOOOGA at the user
178-
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
179-
return <GenericErrorPage message={errorMessage} title={_t("Your Riot is misconfigured")} />;
180-
}
181-
} else {
182-
console.error("Browser is missing required features.");
183-
// take to a different landing page to AWOOOOOGA at the user
184-
const CompatibilityPage = sdk.getComponent("structures.CompatibilityPage");
185-
return <CompatibilityPage onAccept={function() {
186-
if (window.localStorage) window.localStorage.setItem('mx_accepts_unsupported_browser', true);
187-
console.log("User accepts the compatibility risks.");
188-
loadApp();
189-
}} />;
151+
152+
platform.startUpdater();
153+
154+
try {
155+
// Don't bother loading the app until the config is verified
156+
const config = await verifyServerConfig();
157+
const MatrixChat = sdk.getComponent('structures.MatrixChat');
158+
return <MatrixChat
159+
onNewScreen={onNewScreen}
160+
makeRegistrationUrl={makeRegistrationUrl}
161+
ConferenceHandler={VectorConferenceHandler}
162+
config={config}
163+
realQueryParams={params}
164+
startingFragmentQueryParams={fragParams}
165+
enableGuest={!config.disable_guests}
166+
onTokenLoginCompleted={onTokenLoginCompleted}
167+
initialScreenAfterLogin={getScreenFromLocation(window.location)}
168+
defaultDeviceDisplayName={platform.getDefaultDeviceDisplayName()}
169+
/>;
170+
} catch (err) {
171+
console.error(err);
172+
173+
let errorMessage = err.translatedMessage
174+
|| _t("Unexpected error preparing the app. See console for details.");
175+
errorMessage = <span>{errorMessage}</span>;
176+
177+
// Like the compatibility page, AWOOOOOGA at the user
178+
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
179+
return <GenericErrorPage message={errorMessage} title={_t("Your Riot is misconfigured")} />;
190180
}
191181
}
192182

‎src/vector/index.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ async function start() {
100100
loadTheme,
101101
loadApp,
102102
showError,
103+
showIncompatibleBrowser,
103104
_t,
104105
} = await import(
105106
/* webpackChunkName: "init" */
@@ -148,9 +149,18 @@ async function start() {
148149
// ##########################
149150
// error handling begins here
150151
// ##########################
152+
console.log("DEBUG", acceptBrowser);
151153
if (!acceptBrowser) {
152154
await new Promise(resolve => {
153-
// todo
155+
console.error("Browser is missing required features.");
156+
// take to a different landing page to AWOOOOOGA at the user
157+
showIncompatibleBrowser(() => {
158+
if (window.localStorage) {
159+
window.localStorage.setItem('mx_accepts_unsupported_browser', String(true));
160+
}
161+
console.log("User accepts the compatibility risks.");
162+
resolve();
163+
});
154164
});
155165
}
156166

@@ -170,7 +180,7 @@ async function start() {
170180

171181
// ##################################
172182
// app load critical path starts here
173-
// await things starting successfully
183+
// assert things started successfully
174184
// ##################################
175185
await loadOlmPromise;
176186
await loadSkinPromise;
@@ -179,7 +189,7 @@ async function start() {
179189

180190
// Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to
181191
// run on the components.
182-
await loadApp(fragparts.params, acceptBrowser);
192+
await loadApp(fragparts.params);
183193
} catch (err) {
184194
console.trace(err);
185195
const { showError } = await import(

‎src/vector/init.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ export async function loadTheme() {
135135
setTheme();
136136
}
137137

138-
export async function loadApp(fragParams: {}, acceptBrowser: boolean) {
138+
export async function loadApp(fragParams: {}) {
139139
// load app.js async so that its code is not executed immediately and we can catch any exceptions
140140
const module = await import(
141141
/* webpackChunkName: "riot-web-app" */
142142
/* webpackPreload: true */
143143
"./app");
144-
window.matrixChat = ReactDOM.render(await module.loadApp(fragParams, acceptBrowser),
144+
window.matrixChat = ReactDOM.render(await module.loadApp(fragParams),
145145
document.getElementById('matrixchat'));
146146
}
147147

@@ -154,4 +154,13 @@ export async function showError(title: string, messages?: string[]) {
154154
document.getElementById('matrixchat'));
155155
}
156156

157+
export async function showIncompatibleBrowser(onAccept) {
158+
const CompatibilityPage = (await import(
159+
/* webpackChunkName: "compatibility-page" */
160+
/* webpackPreload: true */
161+
"matrix-react-sdk/src/components/structures/CompatibilityPage")).default;
162+
window.matrixChat = ReactDOM.render(<CompatibilityPage onAccept={onAccept} />,
163+
document.getElementById('matrixchat'));
164+
}
165+
157166
export const _t = languageHandler._t;

0 commit comments

Comments
 (0)