2018-11-22 17:21:55 +01:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
2020-01-18 02:27:37 +01:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2018-11-22 17:21:55 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Separate file that sets up rageshake logging when imported.
|
|
|
|
* This is necessary so that rageshake logging is set up before
|
|
|
|
* anything else. Webpack puts all import statements at the top
|
|
|
|
* of the file before any code, so imports will always be
|
|
|
|
* evaluated first. Other imports can cause other code to be
|
|
|
|
* evaluated (eg. the loglevel library in js-sdk, which if set
|
|
|
|
* up before rageshake causes some js-sdk logging to be missing
|
|
|
|
* from the rageshake.)
|
|
|
|
*/
|
|
|
|
|
2019-12-20 02:47:40 +01:00
|
|
|
import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake";
|
|
|
|
import SdkConfig from "matrix-react-sdk/src/SdkConfig";
|
2020-01-18 02:27:37 +01:00
|
|
|
import sendBugReport from "matrix-react-sdk/src/rageshake/submit-rageshake";
|
2021-10-15 16:56:22 +02:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
|
2020-04-04 18:34:33 +02:00
|
|
|
export function initRageshake() {
|
2021-03-16 21:21:59 +01:00
|
|
|
// we manually check persistence for rageshakes ourselves
|
|
|
|
const prom = rageshake.init(/*setUpPersistence=*/false);
|
2020-04-05 01:27:59 +02:00
|
|
|
prom.then(() => {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Initialised rageshake.");
|
|
|
|
logger.log("To fix line numbers in Chrome: " +
|
2021-04-15 11:57:54 +02:00
|
|
|
"Meatball menu → Settings → Ignore list → Add /rageshake\\.js$");
|
2018-11-22 17:21:55 +01:00
|
|
|
|
|
|
|
window.addEventListener('beforeunload', (e) => {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log('element-web closing');
|
2018-11-22 17:21:55 +01:00
|
|
|
// try to flush the logs to indexeddb
|
|
|
|
rageshake.flush();
|
|
|
|
});
|
|
|
|
|
|
|
|
rageshake.cleanup();
|
|
|
|
}, (err) => {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Failed to initialise rageshake: " + err);
|
2018-11-22 17:21:55 +01:00
|
|
|
});
|
2020-04-05 01:27:59 +02:00
|
|
|
return prom;
|
2018-11-22 17:21:55 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:21:59 +01:00
|
|
|
export function initRageshakeStore() {
|
|
|
|
return rageshake.tryInitStorage();
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:07:22 +01:00
|
|
|
window.mxSendRageshake = function(text: string, withLogs?: boolean) {
|
2020-09-15 16:49:25 +02:00
|
|
|
const url = SdkConfig.get().bug_report_endpoint_url;
|
|
|
|
if (!url) {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Cannot send a rageshake - no bug_report_endpoint_url configured");
|
2020-09-15 16:49:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-29 21:13:46 +01:00
|
|
|
if (withLogs === undefined) withLogs = true;
|
2019-07-11 20:58:35 +02:00
|
|
|
if (!text || !text.trim()) {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Cannot send a rageshake without a message - please tell us what went wrong");
|
2019-07-11 20:58:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-09-15 16:49:25 +02:00
|
|
|
sendBugReport(url, {
|
2020-01-18 02:27:37 +01:00
|
|
|
userText: text,
|
|
|
|
sendLogs: withLogs,
|
2021-10-15 16:59:13 +02:00
|
|
|
progressCallback: logger.log.bind(console),
|
2020-01-18 02:27:37 +01:00
|
|
|
}).then(() => {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Bug report sent!");
|
2020-01-18 02:27:37 +01:00
|
|
|
}, (err) => {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error(err);
|
2018-11-28 00:03:37 +01:00
|
|
|
});
|
2018-11-28 00:11:58 +01:00
|
|
|
};
|