Make the safe as and open file dialogs blocking (#2712)

This commit is contained in:
absidue 2022-10-14 08:00:23 +02:00 committed by GitHub
parent 3aa080d707
commit ad01d2b37d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 19 deletions

View File

@ -433,22 +433,28 @@ function runApp() {
return app.getPath('pictures') 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) return await dialog.showOpenDialog(options)
}) })
ipcMain.handle(IpcChannels.SHOW_SAVE_DIALOG, async (event, { options, useModal }) => { ipcMain.handle(IpcChannels.SHOW_SAVE_DIALOG, async ({ sender }, options) => {
if (useModal) { const senderWindow = findSenderWindow(sender)
const senderWindow = BrowserWindow.getAllWindows().find((window) => {
return window.webContents.id === event.sender.id
})
if (senderWindow) { if (senderWindow) {
return await dialog.showSaveDialog(senderWindow, options) return await dialog.showSaveDialog(senderWindow, options)
} }
}
return await dialog.showSaveDialog(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) => { ipcMain.on(IpcChannels.STOP_POWER_SAVE_BLOCKER, (_, id) => {
powerSaveBlocker.stop(id) powerSaveBlocker.stop(id)
}) })

View File

@ -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 === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return return
@ -580,7 +580,7 @@ export default Vue.extend({
return object return object
}) })
const response = await this.showSaveDialog({ options }) const response = await this.showSaveDialog(options)
if (response.canceled || response.filePath === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return 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 === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return return
@ -670,7 +670,7 @@ export default Vue.extend({
exportText += `${channel.id},${channelUrl},${channelName}\n` exportText += `${channel.id},${channelUrl},${channelName}\n`
}) })
exportText += '\n' exportText += '\n'
const response = await this.showSaveDialog({ options }) const response = await this.showSaveDialog(options)
if (response.canceled || response.filePath === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return return
@ -719,7 +719,7 @@ export default Vue.extend({
newPipeObject.subscriptions.push(subscription) newPipeObject.subscriptions.push(subscription)
}) })
const response = await this.showSaveDialog({ options }) const response = await this.showSaveDialog(options)
if (response.canceled || response.filePath === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return 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 === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return 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 === '') { if (response.canceled || response.filePath === '') {
// User canceled the save dialog // User canceled the save dialog
return return

View File

@ -1379,7 +1379,7 @@ export default Vue.extend({
] ]
} }
const response = await this.showSaveDialog({ options, useModal: true }) const response = await this.showSaveDialog(options)
if (wasPlaying) { if (wasPlaying) {
this.player.play() this.player.play()
} }

View File

@ -344,10 +344,10 @@ const actions = {
return await invokeIRC(context, IpcChannels.SHOW_OPEN_DIALOG, webCbk, options) 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 // TODO: implement showSaveDialog web compatible callback
const webCbk = () => null 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) { async getUserDataPath (context) {