From 0b6652cde395b0c64d3268967650a75fcf1f90ef Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Thu, 16 Jan 2020 15:55:04 -0800 Subject: [PATCH] fix save & quit dialogs for Electron 6 API changes --- src/main/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index cf9e4c0..a245583 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -104,8 +104,11 @@ const createMainWindow = () => { const extNameNoDot = extName.replace(/^\./, ''); options.filters = [getFilterForExtension(extNameNoDot)]; } - const userChosenPath = dialog.showSaveDialog(window, options); + const userChosenPath = dialog.showSaveDialogSync(window, options); if (userChosenPath) { + // WARNING: `setSavePath` on this item is only valid during the `will-download` event. Calling the async + // version of `showSaveDialog` means the event will finish before we get here, so `setSavePath` will be + // ignored. For that reason we need to call `showSaveDialogSync` above. item.setSavePath(userChosenPath); if (isProjectSave) { const newProjectTitle = path.basename(userChosenPath, extName); @@ -125,7 +128,7 @@ const createMainWindow = () => { }); webContents.on('will-prevent-unload', ev => { - const choice = dialog.showMessageBox(window, { + const choice = dialog.showMessageBoxSync(window, { type: 'question', message: 'Leave Scratch?', detail: 'Any unsaved changes will be lost.',