feat: add signal option to dialog.showMessageBox (#26102)

* mac: add dialog.closeMessageBox API

* win: Implement dialog.closeMessageBox

* mac: Return cancelId with closeMessageBox

* gtk: Implement dialog.closeMessageBox

* win: Fix 32bit build

* win: Reduce the scope of lock

* fix: Build error after rebase

* feat: Use AbortSignal to close message box

* chore: silently handle duplicate ID

* win: Add more notes about the threads

* chore: apply reviews

* fix: base::NoDestructor should be warpped in function

* chore: fix style on windows
This commit is contained in:
Cheng Zhao 2021-07-15 07:59:27 +09:00 committed by GitHub
parent 4b780f9770
commit 05ba6359d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 276 additions and 24 deletions

View file

@ -22,6 +22,11 @@ enum OpenFileDialogProperties {
dontAddToRecent = 1 << 8 // Windows
}
let nextId = 0;
const getNextId = function () {
return ++nextId;
};
const normalizeAccessKey = (text: string) => {
if (typeof text !== 'string') return text;
@ -157,6 +162,7 @@ const messageBox = (sync: boolean, window: BrowserWindow | null, options?: Messa
let {
buttons = [],
cancelId,
signal,
checkboxLabel = '',
checkboxChecked,
defaultId = -1,
@ -196,10 +202,21 @@ const messageBox = (sync: boolean, window: BrowserWindow | null, options?: Messa
}
}
// AbortSignal processing.
let id: number | undefined;
if (signal) {
// Generate an ID used for closing the message box.
id = getNextId();
// Close the message box when signal is aborted.
if (signal.aborted) { return Promise.resolve({ cancelId, checkboxChecked }); }
signal.addEventListener('abort', () => dialogBinding._closeMessageBox(id));
}
const settings = {
window,
messageBoxType,
buttons,
id,
defaultId,
cancelId,
noLink,