fix: alert issue on Windows by using native messageBox (#509)

* Fix alert issue on Windows by using native messageBox

* Update related docs for alert fix

* Remove unlocalized hint
This commit is contained in:
Ethan Wong 2021-04-04 21:00:11 +08:00 committed by GitHub
parent 025e28399e
commit 1e7274e97f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 8 deletions

32
src/utils/nativeAlert.js Normal file
View file

@ -0,0 +1,32 @@
/**
* Returns an alert-like function that fits current runtime environment
*
* This function is amid to solve a electron bug on Windows, that, when
* user dismissed a browser alert, <input> elements cannot be focused
* for further editing unless switching to another window and then back
*
* @returns { (message:string) => void }
* Built-in alert function for browser environment
* A function wrapping {@link dialog.showMessageBoxSync} for electron environment
*
* @see {@link https://github.com/electron/electron/issues/19977} for upstream electron issue
*/
const nativeAlert = (() => {
if (process.env.IS_ELECTRON === true) {
const {
remote: { dialog },
} = require("electron");
if (dialog) {
return (message) => {
var options = {
type: "warning",
detail: message,
};
dialog.showMessageBoxSync(null, options);
};
}
}
return alert;
})();
export default nativeAlert;