Skip to content
Merged
Prev Previous commit
Next Next commit
feat(main: ipc): handle main:open-message-box to show message box
  • Loading branch information
antonreshetov committed Apr 9, 2022
commit 6cb6f01e086705f350ab36f6140b9125ce878282
23 changes: 23 additions & 0 deletions src/main/services/ipc/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { MessageBoxRequest } from '@shared/types/main'
import { dialog, ipcMain } from 'electron'

export const subscribeToDialog = () => {
Expand All @@ -14,4 +15,26 @@ export const subscribeToDialog = () => {
}
})
})

ipcMain.handle<MessageBoxRequest, boolean>(
'main:open-message-box',
(event, payload) => {
const { message, detail, buttons } = payload
return new Promise(resolve => {
const buttonId = dialog.showMessageBoxSync({
message,
detail,
buttons,
defaultId: 0,
cancelId: 1
})

if (buttonId === 0) {
resolve(true)
} else {
resolve(false)
}
})
}
)
}