Add possibility to delay rageshake persistence in app startup
Even if the app takes a moment to set up persistence, this will still capture any logs before persistence happened.
This commit is contained in:
parent
bd763a09ba
commit
c285b79a8d
1 changed files with 27 additions and 5 deletions
|
@ -434,15 +434,37 @@ function selectQuery(store, keyRange, resultMapper) {
|
||||||
/**
|
/**
|
||||||
* Configure rage shaking support for sending bug reports.
|
* Configure rage shaking support for sending bug reports.
|
||||||
* Modifies globals.
|
* Modifies globals.
|
||||||
|
* @param {boolean} setUpPersistence When true (default), the persistence will
|
||||||
|
* be set up immediately for the logs.
|
||||||
* @return {Promise} Resolves when set up.
|
* @return {Promise} Resolves when set up.
|
||||||
*/
|
*/
|
||||||
export function init() {
|
export function init(setUpPersistence = true) {
|
||||||
if (global.mx_rage_initPromise) {
|
if (global.mx_rage_initPromise) {
|
||||||
return global.mx_rage_initPromise;
|
return global.mx_rage_initPromise;
|
||||||
}
|
}
|
||||||
global.mx_rage_logger = new ConsoleLogger();
|
global.mx_rage_logger = new ConsoleLogger();
|
||||||
global.mx_rage_logger.monkeyPatch(window.console);
|
global.mx_rage_logger.monkeyPatch(window.console);
|
||||||
|
|
||||||
|
if (setUpPersistence) {
|
||||||
|
return tryInitStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
global.mx_rage_initPromise = Promise.resolve();
|
||||||
|
return global.mx_rage_initPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to start up the rageshake storage for logs. If not possible (client unsupported)
|
||||||
|
* then this no-ops.
|
||||||
|
* @return {Promise} Resolves when complete.
|
||||||
|
*/
|
||||||
|
export function tryInitStorage() {
|
||||||
|
if (global.mx_rage_initStoragePromise) {
|
||||||
|
return global.mx_rage_initStoragePromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Configuring rageshake persistence...");
|
||||||
|
|
||||||
// just *accessing* indexedDB throws an exception in firefox with
|
// just *accessing* indexedDB throws an exception in firefox with
|
||||||
// indexeddb disabled.
|
// indexeddb disabled.
|
||||||
let indexedDB;
|
let indexedDB;
|
||||||
|
@ -452,11 +474,11 @@ export function init() {
|
||||||
|
|
||||||
if (indexedDB) {
|
if (indexedDB) {
|
||||||
global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger);
|
global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger);
|
||||||
global.mx_rage_initPromise = global.mx_rage_store.connect();
|
global.mx_rage_initStoragePromise = global.mx_rage_store.connect();
|
||||||
return global.mx_rage_initPromise;
|
return global.mx_rage_initStoragePromise;
|
||||||
}
|
}
|
||||||
global.mx_rage_initPromise = Promise.resolve();
|
global.mx_rage_initStoragePromise = Promise.resolve();
|
||||||
return global.mx_rage_initPromise;
|
return global.mx_rage_initStoragePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function flush() {
|
export function flush() {
|
||||||
|
|
Loading…
Reference in a new issue