Merge pull request #21587 from Benjamin-Dobell/fix/atom-confirm

Fixed atom.confirm and internal use of dialog.showMessageBox
This commit is contained in:
Musa Ibrahim
2020-10-29 18:44:04 +01:00
committed by GitHub
5 changed files with 67 additions and 79 deletions

View File

@@ -228,11 +228,11 @@ module.exports = class ApplicationDelegate {
{ type: 'info', normalizeAccessKeys: true },
options
);
remote.dialog.showMessageBox(
remote.getCurrentWindow(),
options,
callback
);
remote.dialog
.showMessageBox(remote.getCurrentWindow(), options)
.then(result => {
callback(result.response);
});
} else {
// Legacy sync version: options can only have `message`,
// `detailedMessage` (optional), and buttons array or object (optional)
@@ -246,13 +246,16 @@ module.exports = class ApplicationDelegate {
buttonLabels = Object.keys(buttons);
}
const chosen = remote.dialog.showMessageBox(remote.getCurrentWindow(), {
type: 'info',
message,
detail: detailedMessage,
buttons: buttonLabels,
normalizeAccessKeys: true
});
const chosen = remote.dialog.showMessageBoxSync(
remote.getCurrentWindow(),
{
type: 'info',
message,
detail: detailedMessage,
buttons: buttonLabels,
normalizeAccessKeys: true
}
);
if (Array.isArray(buttons)) {
return chosen;

View File

@@ -2025,8 +2025,8 @@ module.exports = class AtomApplication extends EventEmitter {
dialog.showOpenDialog(parentWindow, openOptions, callback);
}
promptForRestart() {
dialog.showMessageBox(
async promptForRestart() {
const result = await dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'warning',
@@ -2034,11 +2034,9 @@ module.exports = class AtomApplication extends EventEmitter {
message:
'You will need to restart Atom for this change to take effect.',
buttons: ['Restart Atom', 'Cancel']
},
response => {
if (response === 0) this.restart();
}
);
if (result.response === 0) this.restart();
}
restart() {

View File

@@ -211,22 +211,17 @@ module.exports = class AtomWindow extends EventEmitter {
this.resolveClosedPromise();
});
this.browserWindow.on('unresponsive', () => {
this.browserWindow.on('unresponsive', async () => {
if (this.isSpec) return;
dialog.showMessageBox(
this.browserWindow,
{
type: 'warning',
buttons: ['Force Close', 'Keep Waiting'],
cancelId: 1, // Canceling should be the least destructive action
message: 'Editor is not responding',
detail:
'The editor is not responding. Would you like to force close it or just keep waiting?'
},
response => {
if (response === 0) this.browserWindow.destroy();
}
);
const result = await dialog.showMessageBox(this.browserWindow, {
type: 'warning',
buttons: ['Force Close', 'Keep Waiting'],
cancelId: 1, // Canceling should be the least destructive action
message: 'Editor is not responding',
detail:
'The editor is not responding. Would you like to force close it or just keep waiting?'
});
if (result.response === 0) this.browserWindow.destroy();
});
this.browserWindow.webContents.on('crashed', async () => {
@@ -237,24 +232,23 @@ module.exports = class AtomWindow extends EventEmitter {
}
await this.fileRecoveryService.didCrashWindow(this);
dialog.showMessageBox(
this.browserWindow,
{
type: 'warning',
buttons: ['Close Window', 'Reload', 'Keep It Open'],
cancelId: 2, // Canceling should be the least destructive action
message: 'The editor has crashed',
detail: 'Please report this issue to https://github.com/atom/atom'
},
response => {
switch (response) {
case 0:
return this.browserWindow.destroy();
case 1:
return this.browserWindow.reload();
}
}
);
const result = await dialog.showMessageBox(this.browserWindow, {
type: 'warning',
buttons: ['Close Window', 'Reload', 'Keep It Open'],
cancelId: 2, // Canceling should be the least destructive action
message: 'The editor has crashed',
detail: 'Please report this issue to https://github.com/atom/atom'
});
switch (result.response) {
case 0:
this.browserWindow.destroy();
break;
case 1:
this.browserWindow.reload();
break;
}
});
this.browserWindow.webContents.on('will-navigate', (event, url) => {

View File

@@ -168,17 +168,14 @@ module.exports = class AutoUpdateManager extends EventEmitter {
onUpdateNotAvailable() {
autoUpdater.removeListener('error', this.onUpdateError);
const { dialog } = require('electron');
dialog.showMessageBox(
{
type: 'info',
buttons: ['OK'],
icon: this.iconPath,
message: 'No update available.',
title: 'No Update Available',
detail: `Version ${this.version} is the latest version.`
},
() => {}
); // noop callback to get async behavior
dialog.showMessageBox({
type: 'info',
buttons: ['OK'],
icon: this.iconPath,
message: 'No update available.',
title: 'No Update Available',
detail: `Version ${this.version} is the latest version.`
});
}
onUpdateError(event, message) {
@@ -187,17 +184,14 @@ module.exports = class AutoUpdateManager extends EventEmitter {
this.onUpdateNotAvailable
);
const { dialog } = require('electron');
dialog.showMessageBox(
{
type: 'warning',
buttons: ['OK'],
icon: this.iconPath,
message: 'There was an error checking for updates.',
title: 'Update Error',
detail: message
},
() => {}
); // noop callback to get async behavior
dialog.showMessageBox({
type: 'warning',
buttons: ['OK'],
icon: this.iconPath,
message: 'There was an error checking for updates.',
title: 'Update Error',
detail: message
});
}
getWindows() {

View File

@@ -83,13 +83,12 @@ module.exports = class FileRecoveryService {
recoveryFile.recoveryPath
}".`;
console.log(detail);
dialog.showMessageBox(
window,
{ type: 'info', buttons: ['OK'], message, detail },
() => {
/* noop callback to get async behavior */
}
);
dialog.showMessageBox(window, {
type: 'info',
buttons: ['OK'],
message,
detail
});
})
.then(() => {
for (let window of this.windowsByRecoveryFile.get(recoveryFile)) {