Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable rageshake persistence if no logs would be submitted #16697

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/vector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion src/vector/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/vector/rageshakesetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: " +
Expand All @@ -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) {
Expand Down