Fix hanging "Clear All Data" on Windows
This commit is contained in:
parent
03eaa9eb3e
commit
fe505a7f2f
8 changed files with 58 additions and 14 deletions
|
@ -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(() => {
|
||||
|
|
|
@ -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:',
|
||||
|
|
1
main.js
1
main.js
|
@ -1477,6 +1477,7 @@ ipc.on('draw-attention', () => {
|
|||
});
|
||||
|
||||
ipc.on('restart', () => {
|
||||
console.log('Relaunching application');
|
||||
app.relaunch();
|
||||
app.quit();
|
||||
});
|
||||
|
|
12
preload.js
12
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -459,7 +459,9 @@ export async function startApp(): Promise<void> {
|
|||
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);
|
||||
},
|
||||
|
|
|
@ -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<pinoms.Logger> {
|
|||
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<pinoms.Logger> {
|
|||
});
|
||||
|
||||
ipc.on('delete-all-logs', async event => {
|
||||
// Restart logging when the streams will close
|
||||
shouldRestart = true;
|
||||
|
||||
try {
|
||||
await deleteAllLogs(logPath);
|
||||
} catch (error) {
|
||||
|
|
|
@ -101,6 +101,11 @@ function fetch(): Promise<string> {
|
|||
}
|
||||
|
||||
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(
|
||||
{
|
||||
|
|
|
@ -269,6 +269,9 @@ async function goBackToMainProcess(): Promise<void> {
|
|||
// 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
|
||||
|
|
Loading…
Reference in a new issue