2015-06-23 16:41:25 +01:00
|
|
|
/*
|
2016-01-07 04:17:56 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-24 11:45:28 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-05-22 22:57:39 -06:00
|
|
|
Copyright 2018, 2019 New Vector Ltd
|
2019-06-26 21:08:04 +01:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2020-01-20 19:52:11 -07:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2015-06-23 16:41:25 +01:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-01-18 16:06:02 +00:00
|
|
|
// Require common CSS here; this will make webpack process it into bundle.css.
|
|
|
|
// Our own CSS (which is themed) is imported via separate webpack entry points
|
|
|
|
// in webpack.config.js
|
2020-04-08 16:09:47 +01:00
|
|
|
import {preparePlatform} from "./init";
|
|
|
|
|
2018-04-25 17:33:18 +01:00
|
|
|
require('gfm.css/gfm.css');
|
|
|
|
require('highlight.js/styles/github.css');
|
2015-12-01 18:05:43 +00:00
|
|
|
|
2020-01-20 19:52:11 -07:00
|
|
|
// These are things that can run before the skin loads - be careful not to reference the react-sdk though.
|
2020-04-05 00:55:36 +01:00
|
|
|
import {parseQsFromFragment} from "./url_utils";
|
2018-11-22 18:27:53 +00:00
|
|
|
import './modernizr';
|
2016-08-11 12:44:49 +01:00
|
|
|
|
2020-02-05 16:35:23 +00:00
|
|
|
// load service worker if available on this platform
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
navigator.serviceWorker.register('sw.js');
|
|
|
|
}
|
|
|
|
|
2020-04-05 00:27:59 +01:00
|
|
|
async function settled(prom: Promise<any>) {
|
2020-04-04 17:34:33 +01:00
|
|
|
try {
|
|
|
|
await prom;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 00:55:36 +01:00
|
|
|
function checkBrowserFeatures() {
|
|
|
|
if (!window.Modernizr) {
|
|
|
|
console.error("Cannot check features - Modernizr global is missing.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// custom checks atop Modernizr because it doesn't have ES2018/ES2019 checks in it for some features we depend on,
|
|
|
|
// Modernizr requires rules to be lowercase with no punctuation:
|
|
|
|
// ES2018: http://www.ecma-international.org/ecma-262/9.0/#sec-promise.prototype.finally
|
|
|
|
window.Modernizr.addTest("promiseprototypefinally", () =>
|
|
|
|
window.Promise && window.Promise.prototype && typeof window.Promise.prototype.finally === "function");
|
|
|
|
// ES2019: http://www.ecma-international.org/ecma-262/10.0/#sec-object.fromentries
|
|
|
|
window.Modernizr.addTest("objectfromentries", () =>
|
|
|
|
window.Object && typeof window.Object.fromEntries === "function");
|
|
|
|
|
|
|
|
const featureList = Object.keys(window.Modernizr);
|
|
|
|
|
|
|
|
let featureComplete = true;
|
|
|
|
for (let i = 0; i < featureList.length; i++) {
|
|
|
|
if (window.Modernizr[featureList[i]] === undefined) {
|
|
|
|
console.error(
|
|
|
|
"Looked for feature '%s' but Modernizr has no results for this. " +
|
|
|
|
"Has it been configured correctly?", featureList[i],
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (window.Modernizr[featureList[i]] === false) {
|
|
|
|
console.error("Browser missing feature: '%s'", featureList[i]);
|
|
|
|
// toggle flag rather than return early so we log all missing features rather than just the first.
|
|
|
|
featureComplete = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return featureComplete;
|
|
|
|
}
|
|
|
|
|
2020-04-04 17:21:59 +01:00
|
|
|
// React depends on Map & Set which we check for using modernizr's es6collections
|
|
|
|
// if modernizr fails we may not have a functional react to show the error message.
|
|
|
|
// try in react but fallback to an `alert`
|
|
|
|
async function start() {
|
|
|
|
// load init.ts async so that its code is not executed immediately and we can catch any exceptions
|
2020-04-08 16:09:47 +01:00
|
|
|
const {rageshakePromise, preparePlatform, loadOlm, loadSkin, loadApp} = await import(
|
2020-04-04 17:21:59 +01:00
|
|
|
/* webpackChunkName: "init" */
|
|
|
|
/* webpackPreload: true */
|
|
|
|
"./init");
|
|
|
|
|
2020-04-04 17:34:33 +01:00
|
|
|
await settled(rageshakePromise); // give rageshake a chance to load/fail
|
|
|
|
|
2020-04-08 16:08:39 +01:00
|
|
|
|
2020-04-05 00:55:36 +01:00
|
|
|
const fragparts = parseQsFromFragment(window.location);
|
|
|
|
|
|
|
|
// don't try to redirect to the native apps if we're
|
|
|
|
// verifying a 3pid (but after we've loaded the config)
|
|
|
|
// or if the user is following a deep link
|
|
|
|
// (https://github.com/vector-im/riot-web/issues/7378)
|
|
|
|
const preventRedirect = fragparts.params.client_secret || fragparts.location.length > 0;
|
|
|
|
|
|
|
|
if (!preventRedirect) {
|
|
|
|
const isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
|
|
const isAndroid = /Android/.test(navigator.userAgent);
|
|
|
|
if (isIos || isAndroid) {
|
|
|
|
if (document.cookie.indexOf("riot_mobile_redirect_to_guide=false") === -1) {
|
|
|
|
window.location.href = "mobile_guide/";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:09:47 +01:00
|
|
|
// set the platform for react sdk
|
|
|
|
preparePlatform();
|
|
|
|
|
2020-04-08 16:10:44 +01:00
|
|
|
const loadOlmPromise = loadOlm();
|
|
|
|
|
2020-04-04 17:21:59 +01:00
|
|
|
await loadSkin();
|
2020-04-04 23:42:19 +01:00
|
|
|
|
2020-04-05 00:55:36 +01:00
|
|
|
let acceptBrowser = checkBrowserFeatures();
|
|
|
|
if (!acceptBrowser && window.localStorage) {
|
|
|
|
acceptBrowser = Boolean(window.localStorage.getItem("mx_accepts_unsupported_browser"));
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:08:39 +01:00
|
|
|
// await things starting successfully
|
|
|
|
await loadOlmPromise;
|
|
|
|
|
2020-04-04 23:42:19 +01:00
|
|
|
// Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to
|
2020-04-08 16:08:39 +01:00
|
|
|
// run on the components.
|
2020-04-05 00:55:36 +01:00
|
|
|
await loadApp(fragparts.params, acceptBrowser);
|
2020-04-04 17:21:59 +01:00
|
|
|
}
|
2020-04-05 00:12:37 +01:00
|
|
|
start();
|