Emit {will,did}SavePath events synchronously

This commit is contained in:
Antonio Scandurra
2016-05-25 00:11:30 +02:00
parent e57b35f8de
commit b84feeb853
2 changed files with 13 additions and 6 deletions

View File

@@ -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)

View File

@@ -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) {