Skip to content

Commit 5ed8572

Browse files
authored
Merge pull request atom#21587 from Benjamin-Dobell/fix/atom-confirm
Fixed atom.confirm and internal use of dialog.showMessageBox
2 parents dd2e6ca + fd4dfef commit 5ed8572

File tree

5 files changed

+67
-79
lines changed

5 files changed

+67
-79
lines changed

src/application-delegate.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ module.exports = class ApplicationDelegate {
228228
{ type: 'info', normalizeAccessKeys: true },
229229
options
230230
);
231-
remote.dialog.showMessageBox(
232-
remote.getCurrentWindow(),
233-
options,
234-
callback
235-
);
231+
remote.dialog
232+
.showMessageBox(remote.getCurrentWindow(), options)
233+
.then(result => {
234+
callback(result.response);
235+
});
236236
} else {
237237
// Legacy sync version: options can only have `message`,
238238
// `detailedMessage` (optional), and buttons array or object (optional)
@@ -246,13 +246,16 @@ module.exports = class ApplicationDelegate {
246246
buttonLabels = Object.keys(buttons);
247247
}
248248

249-
const chosen = remote.dialog.showMessageBox(remote.getCurrentWindow(), {
250-
type: 'info',
251-
message,
252-
detail: detailedMessage,
253-
buttons: buttonLabels,
254-
normalizeAccessKeys: true
255-
});
249+
const chosen = remote.dialog.showMessageBoxSync(
250+
remote.getCurrentWindow(),
251+
{
252+
type: 'info',
253+
message,
254+
detail: detailedMessage,
255+
buttons: buttonLabels,
256+
normalizeAccessKeys: true
257+
}
258+
);
256259

257260
if (Array.isArray(buttons)) {
258261
return chosen;

src/main-process/atom-application.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,20 +2025,18 @@ module.exports = class AtomApplication extends EventEmitter {
20252025
dialog.showOpenDialog(parentWindow, openOptions, callback);
20262026
}
20272027

2028-
promptForRestart() {
2029-
dialog.showMessageBox(
2028+
async promptForRestart() {
2029+
const result = await dialog.showMessageBox(
20302030
BrowserWindow.getFocusedWindow(),
20312031
{
20322032
type: 'warning',
20332033
title: 'Restart required',
20342034
message:
20352035
'You will need to restart Atom for this change to take effect.',
20362036
buttons: ['Restart Atom', 'Cancel']
2037-
},
2038-
response => {
2039-
if (response === 0) this.restart();
20402037
}
20412038
);
2039+
if (result.response === 0) this.restart();
20422040
}
20432041

20442042
restart() {

src/main-process/atom-window.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,17 @@ module.exports = class AtomWindow extends EventEmitter {
211211
this.resolveClosedPromise();
212212
});
213213

214-
this.browserWindow.on('unresponsive', () => {
214+
this.browserWindow.on('unresponsive', async () => {
215215
if (this.isSpec) return;
216-
dialog.showMessageBox(
217-
this.browserWindow,
218-
{
219-
type: 'warning',
220-
buttons: ['Force Close', 'Keep Waiting'],
221-
cancelId: 1, // Canceling should be the least destructive action
222-
message: 'Editor is not responding',
223-
detail:
224-
'The editor is not responding. Would you like to force close it or just keep waiting?'
225-
},
226-
response => {
227-
if (response === 0) this.browserWindow.destroy();
228-
}
229-
);
216+
const result = await dialog.showMessageBox(this.browserWindow, {
217+
type: 'warning',
218+
buttons: ['Force Close', 'Keep Waiting'],
219+
cancelId: 1, // Canceling should be the least destructive action
220+
message: 'Editor is not responding',
221+
detail:
222+
'The editor is not responding. Would you like to force close it or just keep waiting?'
223+
});
224+
if (result.response === 0) this.browserWindow.destroy();
230225
});
231226

232227
this.browserWindow.webContents.on('crashed', async () => {
@@ -237,24 +232,23 @@ module.exports = class AtomWindow extends EventEmitter {
237232
}
238233

239234
await this.fileRecoveryService.didCrashWindow(this);
240-
dialog.showMessageBox(
241-
this.browserWindow,
242-
{
243-
type: 'warning',
244-
buttons: ['Close Window', 'Reload', 'Keep It Open'],
245-
cancelId: 2, // Canceling should be the least destructive action
246-
message: 'The editor has crashed',
247-
detail: 'Please report this issue to https://github.com/atom/atom'
248-
},
249-
response => {
250-
switch (response) {
251-
case 0:
252-
return this.browserWindow.destroy();
253-
case 1:
254-
return this.browserWindow.reload();
255-
}
256-
}
257-
);
235+
236+
const result = await dialog.showMessageBox(this.browserWindow, {
237+
type: 'warning',
238+
buttons: ['Close Window', 'Reload', 'Keep It Open'],
239+
cancelId: 2, // Canceling should be the least destructive action
240+
message: 'The editor has crashed',
241+
detail: 'Please report this issue to https://github.com/atom/atom'
242+
});
243+
244+
switch (result.response) {
245+
case 0:
246+
this.browserWindow.destroy();
247+
break;
248+
case 1:
249+
this.browserWindow.reload();
250+
break;
251+
}
258252
});
259253

260254
this.browserWindow.webContents.on('will-navigate', (event, url) => {

src/main-process/auto-update-manager.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,14 @@ module.exports = class AutoUpdateManager extends EventEmitter {
168168
onUpdateNotAvailable() {
169169
autoUpdater.removeListener('error', this.onUpdateError);
170170
const { dialog } = require('electron');
171-
dialog.showMessageBox(
172-
{
173-
type: 'info',
174-
buttons: ['OK'],
175-
icon: this.iconPath,
176-
message: 'No update available.',
177-
title: 'No Update Available',
178-
detail: `Version ${this.version} is the latest version.`
179-
},
180-
() => {}
181-
); // noop callback to get async behavior
171+
dialog.showMessageBox({
172+
type: 'info',
173+
buttons: ['OK'],
174+
icon: this.iconPath,
175+
message: 'No update available.',
176+
title: 'No Update Available',
177+
detail: `Version ${this.version} is the latest version.`
178+
});
182179
}
183180

184181
onUpdateError(event, message) {
@@ -187,17 +184,14 @@ module.exports = class AutoUpdateManager extends EventEmitter {
187184
this.onUpdateNotAvailable
188185
);
189186
const { dialog } = require('electron');
190-
dialog.showMessageBox(
191-
{
192-
type: 'warning',
193-
buttons: ['OK'],
194-
icon: this.iconPath,
195-
message: 'There was an error checking for updates.',
196-
title: 'Update Error',
197-
detail: message
198-
},
199-
() => {}
200-
); // noop callback to get async behavior
187+
dialog.showMessageBox({
188+
type: 'warning',
189+
buttons: ['OK'],
190+
icon: this.iconPath,
191+
message: 'There was an error checking for updates.',
192+
title: 'Update Error',
193+
detail: message
194+
});
201195
}
202196

203197
getWindows() {

src/main-process/file-recovery-service.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ module.exports = class FileRecoveryService {
8383
recoveryFile.recoveryPath
8484
}".`;
8585
console.log(detail);
86-
dialog.showMessageBox(
87-
window,
88-
{ type: 'info', buttons: ['OK'], message, detail },
89-
() => {
90-
/* noop callback to get async behavior */
91-
}
92-
);
86+
dialog.showMessageBox(window, {
87+
type: 'info',
88+
buttons: ['OK'],
89+
message,
90+
detail
91+
});
9392
})
9493
.then(() => {
9594
for (let window of this.windowsByRecoveryFile.get(recoveryFile)) {

0 commit comments

Comments
 (0)