From ec9316c803ededcd3c9d575261cb416bb010dbbb Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 29 Mar 2020 22:59:15 +0100 Subject: [PATCH] Field: make id optional, generate one if not provided Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/@types/global.d.ts | 3 +++ src/vector/index.js | 30 ++++++++++++++++++++++-------- src/vector/init.ts | 6 ++++++ src/vector/rageshakesetup.ts | 6 ++++-- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 646fe6ea..7e91b766 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -14,9 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ +import {ReactElement} from "react"; + interface Window { Olm: { init: () => Promise; }; mxSendRageshake: (text: string, withLogs?: boolean) => void; + matrixChat: ReactElement; } diff --git a/src/vector/index.js b/src/vector/index.js index b99785df..449d69a1 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -24,8 +24,7 @@ limitations under the License. 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,13 +32,28 @@ if ('serviceWorker' in navigator) { navigator.serviceWorker.register('sw.js'); } -// Ensure the skin is the very first thing to load for the react-sdk. We don't even want to reference -// the SDK until we have to in imports. -import {loadSkin} from "./init"; -loadSkin().then(() => { +async function start() { + const { initRageshake, loadSkin } = await import( + /* webpackChunkName: "init" */ + /* webpackPreload: true */ + "./init"); + + // These are things that can run before the skin loads - be careful not to reference the react-sdk though. + await initRageshake(); + + // Ensure the skin is the very first thing to load for the react-sdk. We don't even want to reference + // the SDK until we have to in imports. + await loadSkin(); + // Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to // run on the components. We use `require` here to make sure webpack doesn't optimize this into an async // import and thus running before the skin can load. - require("./app").loadApp(); -}); + const { loadApp } = await import( + /* webpackChunkName: "app" */ + /* webpackPreload: true */ + "./app"); + loadApp(); +} + +start(); diff --git a/src/vector/init.ts b/src/vector/init.ts index 78a29cd6..3a96629b 100644 --- a/src/vector/init.ts +++ b/src/vector/init.ts @@ -121,3 +121,9 @@ export async function loadTheme() { // as quickly as we possibly can, set a default theme... await setTheme(); } + +import rageshakeProm from "./rageshakesetup"; + +export async function initRageshake() { + return rageshakeProm; +} diff --git a/src/vector/rageshakesetup.ts b/src/vector/rageshakesetup.ts index 6445f4e9..967a2cf5 100644 --- a/src/vector/rageshakesetup.ts +++ b/src/vector/rageshakesetup.ts @@ -31,7 +31,8 @@ import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import sendBugReport from "matrix-react-sdk/src/rageshake/submit-rageshake"; function initRageshake() { - rageshake.init().then(() => { + const prom = rageshake.init(); + prom.then(() => { console.log("Initialised rageshake."); console.log("To fix line numbers in Chrome: " + "Meatball menu → Settings → Blackboxing → Add /rageshake\\.js$"); @@ -46,9 +47,10 @@ function initRageshake() { }, (err) => { console.error("Failed to initialise rageshake: " + err); }); + return prom; } -initRageshake(); +export default initRageshake(); window.mxSendRageshake = function(text: string, withLogs?: boolean) { if (withLogs === undefined) withLogs = true;