From b84feeb853426b175ca8b4cdceddb6dc2cc72ebf Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 25 May 2016 00:11:30 +0200 Subject: [PATCH] Emit {will,did}SavePath events synchronously --- src/application-delegate.coffee | 4 ++-- src/browser/file-recovery-service.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index efe2af28e..74c498e78 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -268,7 +268,7 @@ class ApplicationDelegate ipcRenderer.sendSync('get-auto-update-manager-error') emitWillSavePath: (path) -> - ipcRenderer.send('will-save-path', path) + ipcRenderer.sendSync('will-save-path', path) emitDidSavePath: (path) -> - ipcRenderer.send('did-save-path', path) + ipcRenderer.sendSync('did-save-path', path) diff --git a/src/browser/file-recovery-service.js b/src/browser/file-recovery-service.js index b7537937b..56ebd8067 100644 --- a/src/browser/file-recovery-service.js +++ b/src/browser/file-recovery-service.js @@ -20,6 +20,7 @@ export default class FileRecoveryService { willSavePath (event, path) { if (!fs.existsSync(path)) { // Unexisting files won't be truncated/overwritten, and so there's no data to be lost. + event.returnValue = false return } @@ -37,16 +38,22 @@ export default class FileRecoveryService { window.on('crashed', () => this.recoverFilesForWindow(window)) this.crashListeners.add(window) } + + event.returnValue = true } didSavePath (event, path) { const window = event.sender const recoveryPathsByFilePath = this.recoveryPathsByWindowAndFilePath.get(window) - if (recoveryPathsByFilePath != null && recoveryPathsByFilePath.has(path)) { - const recoveryPath = recoveryPathsByFilePath.get(path) - fs.unlinkSync(recoveryPath) - recoveryPathsByFilePath.delete(path) + if (recoveryPathsByFilePath == null || !recoveryPathsByFilePath.has(path)) { + event.returnValue = false + return } + + const recoveryPath = recoveryPathsByFilePath.get(path) + fs.unlinkSync(recoveryPath) + recoveryPathsByFilePath.delete(path) + event.returnValue = true } recoverFilesForWindow (window) {