From 2eda6601c08407b83a9ad7cbf35dc8130b2842c6 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Wed, 15 Jan 2020 17:12:27 +0100 Subject: [PATCH] Remove remaining Promise.then Change-type: patch --- lib/gui/app/app.ts | 42 +++++++++++++++++++++--------------------- lib/shared/utils.ts | 8 +++----- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/gui/app/app.ts b/lib/gui/app/app.ts index 713e59a2..9475af88 100644 --- a/lib/gui/app/app.ts +++ b/lib/gui/app/app.ts @@ -277,7 +277,7 @@ driveScanner.start(); let popupExists = false; -window.addEventListener('beforeunload', event => { +window.addEventListener('beforeunload', async event => { if (!flashState.isFlashing() || popupExists) { analytics.logEvent('Close application', { isFlashing: flashState.isFlashing(), @@ -297,33 +297,33 @@ window.addEventListener('beforeunload', event => { flashingWorkflowUuid, }); - osDialog - .showWarning({ + try { + const confirmed = await osDialog.showWarning({ confirmationLabel: 'Yes, quit', rejectionLabel: 'Cancel', title: 'Are you sure you want to close Etcher?', description: messages.warning.exitWhileFlashing(), - }) - .then(confirmed => { - if (confirmed) { - analytics.logEvent('Close confirmed while flashing', { - flashInstanceUuid: flashState.getFlashUuid(), - applicationSessionUuid, - flashingWorkflowUuid, - }); - - // This circumvents the 'beforeunload' event unlike - // electron.remote.app.quit() which does not. - electron.remote.process.exit(EXIT_CODES.SUCCESS); - } - - analytics.logEvent('Close rejected while flashing', { + }); + if (confirmed) { + analytics.logEvent('Close confirmed while flashing', { + flashInstanceUuid: flashState.getFlashUuid(), applicationSessionUuid, flashingWorkflowUuid, }); - popupExists = false; - }) - .catch(exceptionReporter.report); + + // This circumvents the 'beforeunload' event unlike + // electron.remote.app.quit() which does not. + electron.remote.process.exit(EXIT_CODES.SUCCESS); + } + + analytics.logEvent('Close rejected while flashing', { + applicationSessionUuid, + flashingWorkflowUuid, + }); + popupExists = false; + } catch (error) { + exceptionReporter.report(error); + } }); function extendLock() { diff --git a/lib/shared/utils.ts b/lib/shared/utils.ts index 899d596f..eb83f854 100755 --- a/lib/shared/utils.ts +++ b/lib/shared/utils.ts @@ -58,11 +58,9 @@ export async function getConfig(configUrl: string): Promise { * @summary returns { path: String, cleanup: Function } * * @example - * tmpFileAsync() - * .then({ path, cleanup } => { - * console.log(path) - * cleanup() - * }); + * const {path, cleanup } = await tmpFileAsync() + * console.log(path) + * cleanup() */ function tmpFileAsync( options: tmp.FileOptions,