2018-11-22 17:21:55 +01:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
|
|
|
|
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.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
import rageshake from "matrix-react-sdk/lib/rageshake/rageshake";
|
2019-01-12 00:20:29 +01:00
|
|
|
import SdkConfig from "matrix-react-sdk/lib/SdkConfig";
|
2018-11-22 17:21:55 +01:00
|
|
|
|
|
|
|
function initRageshake() {
|
|
|
|
rageshake.init().then(() => {
|
2018-12-19 15:52:17 +01:00
|
|
|
console.log("Initialised rageshake.");
|
|
|
|
console.log("To fix line numbers in Chrome: " +
|
|
|
|
"Meatball menu → Settings → Blackboxing → Add /rageshake\\.js$");
|
2018-11-22 17:21:55 +01:00
|
|
|
|
|
|
|
window.addEventListener('beforeunload', (e) => {
|
|
|
|
console.log('riot-web closing');
|
|
|
|
// try to flush the logs to indexeddb
|
|
|
|
rageshake.flush();
|
|
|
|
});
|
|
|
|
|
|
|
|
rageshake.cleanup();
|
|
|
|
}, (err) => {
|
|
|
|
console.error("Failed to initialise rageshake: " + err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initRageshake();
|
2018-11-28 00:03:37 +01:00
|
|
|
|
|
|
|
global.mxSendRageshake = function(text, withLogs) {
|
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()) {
|
|
|
|
console.error("Cannot send a rageshake without a message - please tell us what went wrong");
|
|
|
|
return;
|
|
|
|
}
|
2018-11-28 00:03:37 +01:00
|
|
|
require(['matrix-react-sdk/lib/rageshake/submit-rageshake'], (s) => {
|
|
|
|
s(SdkConfig.get().bug_report_endpoint_url, {
|
|
|
|
userText: text,
|
|
|
|
sendLogs: withLogs,
|
2018-11-29 21:13:46 +01:00
|
|
|
progressCallback: console.log.bind(console),
|
2018-11-28 00:03:37 +01:00
|
|
|
}).then(() => {
|
|
|
|
console.log("Bug report sent!");
|
|
|
|
}, (err) => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
2018-11-28 00:11:58 +01:00
|
|
|
};
|