Fix hanging "Clear All Data" on Windows

This commit is contained in:
Fedor Indutny 2021-05-13 13:54:54 -07:00 committed by Scott Nonnenberg
parent 03eaa9eb3e
commit fe505a7f2f
8 changed files with 58 additions and 14 deletions

View file

@ -3,6 +3,8 @@
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');
const { beforeRestart } = require('../../ts/logging/set_up_renderer_logging');
/* eslint-env node */ /* eslint-env node */
module.exports = { module.exports = {
@ -11,6 +13,9 @@ module.exports = {
function deleteAll() { function deleteAll() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Restart logging again when the file stream close
beforeRestart();
ipcRenderer.once('delete-all-logs-complete', resolve); ipcRenderer.once('delete-all-logs-complete', resolve);
setTimeout(() => { setTimeout(() => {

View file

@ -36,11 +36,23 @@
try { try {
await Logs.deleteAll(); await Logs.deleteAll();
window.log.info('clearAllData: deleted all logs');
await window.Signal.Data.removeAll(); await window.Signal.Data.removeAll();
window.log.info('clearAllData: emptied database');
await window.Signal.Data.close(); await window.Signal.Data.close();
window.log.info('clearAllData: closed database');
await window.Signal.Data.removeDB(); await window.Signal.Data.removeDB();
window.log.info('clearAllData: removed database');
await window.Signal.Data.removeOtherData(); await window.Signal.Data.removeOtherData();
window.log.info('clearAllData: removed all other data');
} catch (error) { } catch (error) {
window.log.error( window.log.error(
'Something went wrong deleting all data:', 'Something went wrong deleting all data:',

View file

@ -1477,6 +1477,7 @@ ipc.on('draw-attention', () => {
}); });
ipc.on('restart', () => { ipc.on('restart', () => {
console.log('Relaunching application');
app.relaunch(); app.relaunch();
app.quit(); app.quit();
}); });

View file

@ -371,10 +371,16 @@ try {
installGetter('sync-time', 'getLastSyncTime'); installGetter('sync-time', 'getLastSyncTime');
installSetter('sync-time', 'setLastSyncTime'); installSetter('sync-time', 'setLastSyncTime');
ipc.on('delete-all-data', () => { ipc.on('delete-all-data', async () => {
const { deleteAllData } = window.Events; const { deleteAllData } = window.Events;
if (deleteAllData) { if (!deleteAllData) {
deleteAllData(); return;
}
try {
await deleteAllData();
} catch (error) {
window.log.error('delete-all-data: error', error && error.stack);
} }
}); });

View file

@ -459,7 +459,9 @@ export async function startApp(): Promise<void> {
removeDarkOverlay: () => $('.dark-overlay').remove(), removeDarkOverlay: () => $('.dark-overlay').remove(),
showKeyboardShortcuts: () => window.showKeyboardShortcuts(), showKeyboardShortcuts: () => window.showKeyboardShortcuts(),
deleteAllData: () => { deleteAllData: async () => {
await window.sqlInitializer.goBackToMainProcess();
const clearDataView = new window.Whisper.ClearDataView().render(); const clearDataView = new window.Whisper.ClearDataView().render();
$('body').append(clearDataView.el); $('body').append(clearDataView.el);
}, },

View file

@ -38,6 +38,7 @@ declare global {
} }
let globalLogger: undefined | pinoms.Logger; let globalLogger: undefined | pinoms.Logger;
let shouldRestart = false;
const isRunningFromConsole = const isRunningFromConsole =
Boolean(process.stdout.isTTY) || Boolean(process.stdout.isTTY) ||
@ -74,13 +75,16 @@ export async function initialize(): Promise<pinoms.Logger> {
rotate: 3, rotate: 3,
}); });
stream.on('close', () => { const onClose = () => {
globalLogger = undefined; globalLogger = undefined;
});
stream.on('error', () => { if (shouldRestart) {
globalLogger = undefined; initialize();
}); }
};
stream.on('close', onClose);
stream.on('error', onClose);
const streams: pinoms.Streams = []; const streams: pinoms.Streams = [];
streams.push({ stream }); streams.push({ stream });
@ -109,6 +113,9 @@ export async function initialize(): Promise<pinoms.Logger> {
}); });
ipc.on('delete-all-logs', async event => { ipc.on('delete-all-logs', async event => {
// Restart logging when the streams will close
shouldRestart = true;
try { try {
await deleteAllLogs(logPath); await deleteAllLogs(logPath);
} catch (error) { } catch (error) {

View file

@ -101,6 +101,11 @@ function fetch(): Promise<string> {
} }
let globalLogger: undefined | pino.Logger; let globalLogger: undefined | pino.Logger;
let shouldRestart = false;
export function beforeRestart(): void {
shouldRestart = true;
}
export function initialize(): void { export function initialize(): void {
if (globalLogger) { if (globalLogger) {
@ -114,13 +119,16 @@ export function initialize(): void {
rotate: 3, rotate: 3,
}); });
stream.on('close', () => { const onClose = () => {
globalLogger = undefined; globalLogger = undefined;
});
stream.on('error', () => { if (shouldRestart) {
globalLogger = undefined; initialize();
}); }
};
stream.on('close', onClose);
stream.on('error', onClose);
globalLogger = pino( globalLogger = pino(
{ {

View file

@ -269,6 +269,9 @@ async function goBackToMainProcess(): Promise<void> {
// We don't need to wait for pending queries since they are synchronous. // We don't need to wait for pending queries since they are synchronous.
window.log.info('data.goBackToMainProcess: switching to main process'); window.log.info('data.goBackToMainProcess: switching to main process');
// Close the database in the renderer process.
await close();
shouldUseRendererProcess = false; shouldUseRendererProcess = false;
// Print query statistics for whole startup // Print query statistics for whole startup