From 37ed89c25fa6a89600e1f033e55f47245ea30901 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 4 Apr 2020 17:34:33 +0100 Subject: [PATCH] move rageshake init into init.ts to allow for code-splitting Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/index.js | 13 +++++++++++-- src/vector/init.ts | 8 ++++++-- src/vector/rageshakesetup.ts | 4 +--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 6d4411cd..44c82772 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -25,7 +25,6 @@ require('gfm.css/gfm.css'); require('highlight.js/styles/github.css'); // These are things that can run before the skin loads - be careful not to reference the react-sdk though. -import './rageshakesetup'; import './modernizr'; // load service worker if available on this platform @@ -33,16 +32,26 @@ if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw.js'); } +async function settled(prom) { + try { + await prom; + } catch (e) { + console.error(e); + } +} + // 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 - const {loadSkin, loadApp} = await import( + const {rageshakePromise, loadSkin, loadApp} = await import( /* webpackChunkName: "init" */ /* webpackPreload: true */ "./init"); + await settled(rageshakePromise); // give rageshake a chance to load/fail + await loadSkin(); await loadApp(); } diff --git a/src/vector/init.ts b/src/vector/init.ts index 9b720c7a..f53b9231 100644 --- a/src/vector/init.ts +++ b/src/vector/init.ts @@ -21,13 +21,17 @@ limitations under the License. import olmWasmPath from "olm/olm.wasm"; import Olm from 'olm'; -import * as languageHandler from 'matrix-react-sdk/src/languageHandler'; +import * as languageHandler from "matrix-react-sdk/src/languageHandler"; import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore"; import ElectronPlatform from "./platform/ElectronPlatform"; import WebPlatform from "./platform/WebPlatform"; -import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; +import PlatformPeg from "matrix-react-sdk/src/PlatformPeg"; import SdkConfig from "matrix-react-sdk/src/SdkConfig"; +import { initRageshake } from "./rageshakesetup"; + + +export const rageshakePromise = initRageshake(); export function preparePlatform() { if ((window).ipcRenderer) { diff --git a/src/vector/rageshakesetup.ts b/src/vector/rageshakesetup.ts index 6445f4e9..cef9d538 100644 --- a/src/vector/rageshakesetup.ts +++ b/src/vector/rageshakesetup.ts @@ -30,7 +30,7 @@ import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake"; import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import sendBugReport from "matrix-react-sdk/src/rageshake/submit-rageshake"; -function initRageshake() { +export function initRageshake() { rageshake.init().then(() => { console.log("Initialised rageshake."); console.log("To fix line numbers in Chrome: " + @@ -48,8 +48,6 @@ function initRageshake() { }); } -initRageshake(); - window.mxSendRageshake = function(text: string, withLogs?: boolean) { if (withLogs === undefined) withLogs = true; if (!text || !text.trim()) {