diff --git a/js/modules/logs.js b/js/modules/logs.js index 90056d86e390..940fa8b367c1 100644 --- a/js/modules/logs.js +++ b/js/modules/logs.js @@ -3,6 +3,8 @@ const { ipcRenderer } = require('electron'); +const { beforeRestart } = require('../../ts/logging/set_up_renderer_logging'); + /* eslint-env node */ module.exports = { @@ -11,6 +13,9 @@ module.exports = { function deleteAll() { return new Promise((resolve, reject) => { + // Restart logging again when the file stream close + beforeRestart(); + ipcRenderer.once('delete-all-logs-complete', resolve); setTimeout(() => { diff --git a/js/views/clear_data_view.js b/js/views/clear_data_view.js index b09acaac861f..486aa450d6a4 100644 --- a/js/views/clear_data_view.js +++ b/js/views/clear_data_view.js @@ -36,11 +36,23 @@ try { await Logs.deleteAll(); + window.log.info('clearAllData: deleted all logs'); + await window.Signal.Data.removeAll(); + + window.log.info('clearAllData: emptied database'); + await window.Signal.Data.close(); + + window.log.info('clearAllData: closed database'); + await window.Signal.Data.removeDB(); + window.log.info('clearAllData: removed database'); + await window.Signal.Data.removeOtherData(); + + window.log.info('clearAllData: removed all other data'); } catch (error) { window.log.error( 'Something went wrong deleting all data:', diff --git a/main.js b/main.js index 3d739a26e110..84987752584f 100644 --- a/main.js +++ b/main.js @@ -1477,6 +1477,7 @@ ipc.on('draw-attention', () => { }); ipc.on('restart', () => { + console.log('Relaunching application'); app.relaunch(); app.quit(); }); diff --git a/preload.js b/preload.js index 52aaf6c85d5e..120836956837 100644 --- a/preload.js +++ b/preload.js @@ -371,10 +371,16 @@ try { installGetter('sync-time', 'getLastSyncTime'); installSetter('sync-time', 'setLastSyncTime'); - ipc.on('delete-all-data', () => { + ipc.on('delete-all-data', async () => { const { deleteAllData } = window.Events; - if (deleteAllData) { - deleteAllData(); + if (!deleteAllData) { + return; + } + + try { + await deleteAllData(); + } catch (error) { + window.log.error('delete-all-data: error', error && error.stack); } }); diff --git a/ts/background.ts b/ts/background.ts index 49e7fe665f14..7ca380f91a9f 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -459,7 +459,9 @@ export async function startApp(): Promise { removeDarkOverlay: () => $('.dark-overlay').remove(), showKeyboardShortcuts: () => window.showKeyboardShortcuts(), - deleteAllData: () => { + deleteAllData: async () => { + await window.sqlInitializer.goBackToMainProcess(); + const clearDataView = new window.Whisper.ClearDataView().render(); $('body').append(clearDataView.el); }, diff --git a/ts/logging/main_process_logging.ts b/ts/logging/main_process_logging.ts index e8eca378f6ce..df067ce71485 100644 --- a/ts/logging/main_process_logging.ts +++ b/ts/logging/main_process_logging.ts @@ -38,6 +38,7 @@ declare global { } let globalLogger: undefined | pinoms.Logger; +let shouldRestart = false; const isRunningFromConsole = Boolean(process.stdout.isTTY) || @@ -74,13 +75,16 @@ export async function initialize(): Promise { rotate: 3, }); - stream.on('close', () => { + const onClose = () => { globalLogger = undefined; - }); - stream.on('error', () => { - globalLogger = undefined; - }); + if (shouldRestart) { + initialize(); + } + }; + + stream.on('close', onClose); + stream.on('error', onClose); const streams: pinoms.Streams = []; streams.push({ stream }); @@ -109,6 +113,9 @@ export async function initialize(): Promise { }); ipc.on('delete-all-logs', async event => { + // Restart logging when the streams will close + shouldRestart = true; + try { await deleteAllLogs(logPath); } catch (error) { diff --git a/ts/logging/set_up_renderer_logging.ts b/ts/logging/set_up_renderer_logging.ts index 2273bf9a7025..41771751b800 100644 --- a/ts/logging/set_up_renderer_logging.ts +++ b/ts/logging/set_up_renderer_logging.ts @@ -101,6 +101,11 @@ function fetch(): Promise { } let globalLogger: undefined | pino.Logger; +let shouldRestart = false; + +export function beforeRestart(): void { + shouldRestart = true; +} export function initialize(): void { if (globalLogger) { @@ -114,13 +119,16 @@ export function initialize(): void { rotate: 3, }); - stream.on('close', () => { + const onClose = () => { globalLogger = undefined; - }); - stream.on('error', () => { - globalLogger = undefined; - }); + if (shouldRestart) { + initialize(); + } + }; + + stream.on('close', onClose); + stream.on('error', onClose); globalLogger = pino( { diff --git a/ts/sql/Client.ts b/ts/sql/Client.ts index 82c039d0a3b9..ec8d235a332b 100644 --- a/ts/sql/Client.ts +++ b/ts/sql/Client.ts @@ -269,6 +269,9 @@ async function goBackToMainProcess(): Promise { // We don't need to wait for pending queries since they are synchronous. window.log.info('data.goBackToMainProcess: switching to main process'); + // Close the database in the renderer process. + await close(); + shouldUseRendererProcess = false; // Print query statistics for whole startup