From cc56ef3abd2a1940db19a1da68320b5bb5db0694 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 22 Jun 2017 18:25:19 +0100 Subject: [PATCH] Attempt to flush the rageshake logs on close ... so that we get to see what happened in the last 30s. --- electron_app/src/electron-main.js | 3 +++ src/vector/index.js | 6 ++++++ src/vector/platform/ElectronPlatform.js | 7 +++++++ src/vector/rageshake.js | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index c8dd6266a3..99e14b7447 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -242,6 +242,9 @@ electron.app.on('activate', () => { electron.app.on('before-quit', () => { global.appQuitting = true; + if (mainWindow) { + mainWindow.webContents.send('before-quit'); + } }); // Set the App User Model ID to match what the squirrel diff --git a/src/vector/index.js b/src/vector/index.js index 9ad86d0ec2..81d329c004 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -45,6 +45,12 @@ rageshake.init().then(() => { console.error("Failed to initialise rageshake: " + err); }); +window.addEventListener('beforeunload', (e) => { + console.log('riot-web closing'); + // try to flush the logs to indexeddb + rageshake.flush(); +}); + // add React and ReactPerf to the global namespace, to make them easier to // access via the console diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 7a1bf58292..4f0ffae733 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -22,9 +22,16 @@ import dis from 'matrix-react-sdk/lib/dispatcher'; import { _t } from 'matrix-react-sdk/lib/languageHandler'; import q from 'q'; import {remote, ipcRenderer} from 'electron'; +import rageshake from '../rageshake'; remote.autoUpdater.on('update-downloaded', onUpdateDownloaded); +// try to flush the rageshake logs to indexeddb before quit. +ipcRenderer.on('before-quit', function () { + console.log('riot-desktop closing'); + rageshake.flush(); +}); + function onUpdateDownloaded(ev: Event, releaseNotes: string, ver: string, date: Date, updateURL: string) { dis.dispatch({ action: 'new_version', diff --git a/src/vector/rageshake.js b/src/vector/rageshake.js index 249f1f2768..07726f6834 100644 --- a/src/vector/rageshake.js +++ b/src/vector/rageshake.js @@ -427,6 +427,13 @@ module.exports = { return initPromise; }, + flush: function() { + if (!store) { + return; + } + store.flush(); + }, + /** * Clean up old logs. * @return Promise Resolves if cleaned logs.