From a76c4ae9438e79e22babd2ebbc5b12f9b4dd0099 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 16 Mar 2021 14:21:59 -0600 Subject: [PATCH] Disable rageshake persistence if no logs would be submitted This also delays the persistence until later in the app startup - this is fine for the reasons listed on the partner PR: https://github.com/matrix-org/matrix-react-sdk/pull/5767 Fixes https://github.com/vector-im/element-web/issues/16694 --- src/vector/index.ts | 9 +++++++++ src/vector/init.tsx | 10 +++++++++- src/vector/rageshakesetup.ts | 7 ++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/vector/index.ts b/src/vector/index.ts index 21aacaf69e..948bc6a9ea 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -92,6 +92,7 @@ async function start() { // load init.ts async so that its code is not executed immediately and we can catch any exceptions const { rageshakePromise, + setupLogStorage, preparePlatform, loadOlm, loadConfig, @@ -138,6 +139,9 @@ async function start() { await settled(loadConfigPromise); // wait for it to settle // keep initialising so that we can show any possible error with as many features (theme, i18n) as possible + // now that the config is ready, try to persist logs + const persistLogsPromise = setupLogStorage(); + // Load language after loading config.json so that settingsDefaults.language can be applied const loadLanguagePromise = loadLanguage(); // as quickly as we possibly can, set a default theme... @@ -197,6 +201,11 @@ async function start() { await loadThemePromise; await loadLanguagePromise; + // We don't care if the log persistence made it through successfully, but we do want to + // make sure it had a chance to load before we move on. It's prepared much higher up in + // the process, making this the first time we check that it did something. + await settled(persistLogsPromise); + // Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to // run on the components. await loadApp(fragparts.params); diff --git a/src/vector/init.tsx b/src/vector/init.tsx index de022622db..019cb352f8 100644 --- a/src/vector/init.tsx +++ b/src/vector/init.tsx @@ -33,7 +33,7 @@ import PlatformPeg from "matrix-react-sdk/src/PlatformPeg"; import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import {setTheme} from "matrix-react-sdk/src/theme"; -import { initRageshake } from "./rageshakesetup"; +import {initRageshake, initRageshakeStore} from "./rageshakesetup"; export const rageshakePromise = initRageshake(); @@ -51,6 +51,14 @@ export function preparePlatform() { } } +export function setupLogStorage() { + if (SdkConfig.get().bug_report_endpoint_url) { + return initRageshakeStore(); + } + console.warn("No bug report endpoint set - logs will not be persisted"); + return Promise.resolve(); +} + export async function loadConfig() { // XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure // granular settings are loaded correctly and to avoid duplicating the override logic for the theme. diff --git a/src/vector/rageshakesetup.ts b/src/vector/rageshakesetup.ts index 425246268f..e2c293d346 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"; export function initRageshake() { - const prom = rageshake.init(); + // we manually check persistence for rageshakes ourselves + const prom = rageshake.init(/*setUpPersistence=*/false); prom.then(() => { console.log("Initialised rageshake."); console.log("To fix line numbers in Chrome: " + @@ -50,6 +51,10 @@ export function initRageshake() { return prom; } +export function initRageshakeStore() { + return rageshake.tryInitStorage(); +} + window.mxSendRageshake = function(text: string, withLogs?: boolean) { const url = SdkConfig.get().bug_report_endpoint_url; if (!url) {