From ad01d2b37d6f9960b0874c0c8b352e8dd54970c1 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Fri, 14 Oct 2022 08:00:23 +0200 Subject: [PATCH] Make the safe as and open file dialogs blocking (#2712) --- src/main/index.js | 24 ++++++++++++------- .../components/data-settings/data-settings.js | 14 +++++------ .../ft-video-player/ft-video-player.js | 2 +- src/renderer/store/modules/utils.js | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 5a4f55da..330fb238 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -433,22 +433,28 @@ function runApp() { return app.getPath('pictures') }) - ipcMain.handle(IpcChannels.SHOW_OPEN_DIALOG, async (_, options) => { + ipcMain.handle(IpcChannels.SHOW_OPEN_DIALOG, async ({ sender }, options) => { + const senderWindow = findSenderWindow(sender) + if (senderWindow) { + return await dialog.showOpenDialog(senderWindow, options) + } return await dialog.showOpenDialog(options) }) - ipcMain.handle(IpcChannels.SHOW_SAVE_DIALOG, async (event, { options, useModal }) => { - if (useModal) { - const senderWindow = BrowserWindow.getAllWindows().find((window) => { - return window.webContents.id === event.sender.id - }) - if (senderWindow) { - return await dialog.showSaveDialog(senderWindow, options) - } + ipcMain.handle(IpcChannels.SHOW_SAVE_DIALOG, async ({ sender }, options) => { + const senderWindow = findSenderWindow(sender) + if (senderWindow) { + return await dialog.showSaveDialog(senderWindow, options) } return await dialog.showSaveDialog(options) }) + function findSenderWindow(sender) { + return BrowserWindow.getAllWindows().find((window) => { + return window.webContents.id === sender.id + }) + } + ipcMain.on(IpcChannels.STOP_POWER_SAVE_BLOCKER, (_, id) => { powerSaveBlocker.stop(id) }) diff --git a/src/renderer/components/data-settings/data-settings.js b/src/renderer/components/data-settings/data-settings.js index 11640fac..1a5bdd4b 100644 --- a/src/renderer/components/data-settings/data-settings.js +++ b/src/renderer/components/data-settings/data-settings.js @@ -503,7 +503,7 @@ export default Vue.extend({ ] } - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return @@ -580,7 +580,7 @@ export default Vue.extend({ return object }) - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return @@ -628,7 +628,7 @@ export default Vue.extend({ } }) - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return @@ -670,7 +670,7 @@ export default Vue.extend({ exportText += `${channel.id},${channelUrl},${channelName}\n` }) exportText += '\n' - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return @@ -719,7 +719,7 @@ export default Vue.extend({ newPipeObject.subscriptions.push(subscription) }) - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return @@ -823,7 +823,7 @@ export default Vue.extend({ ] } - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return @@ -978,7 +978,7 @@ export default Vue.extend({ ] } - const response = await this.showSaveDialog({ options }) + const response = await this.showSaveDialog(options) if (response.canceled || response.filePath === '') { // User canceled the save dialog return diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index 71bf6451..7b7a80e2 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -1379,7 +1379,7 @@ export default Vue.extend({ ] } - const response = await this.showSaveDialog({ options, useModal: true }) + const response = await this.showSaveDialog(options) if (wasPlaying) { this.player.play() } diff --git a/src/renderer/store/modules/utils.js b/src/renderer/store/modules/utils.js index d01fb66e..07aa81ff 100644 --- a/src/renderer/store/modules/utils.js +++ b/src/renderer/store/modules/utils.js @@ -344,10 +344,10 @@ const actions = { return await invokeIRC(context, IpcChannels.SHOW_OPEN_DIALOG, webCbk, options) }, - async showSaveDialog (context, { options, useModal = false }) { + async showSaveDialog (context, options) { // TODO: implement showSaveDialog web compatible callback const webCbk = () => null - return await invokeIRC(context, IpcChannels.SHOW_SAVE_DIALOG, webCbk, { options, useModal }) + return await invokeIRC(context, IpcChannels.SHOW_SAVE_DIALOG, webCbk, options) }, async getUserDataPath (context) {