mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-22 18:56:31 +00:00
style(GUI): use a OS dialog to show the "exit while flashing" warning (#1070)
For better OS integration purposes. This commit also fixes a bug where the dialog would be shown for some milliseconds even if the application is not flashing. Change-Type: minor Changelog-Entry: Use a OS dialog to show the "exit while flashing" warning. Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
parent
92fdba3642
commit
b55ff3eef8
@ -62,6 +62,7 @@ const app = angular.module('Etcher', [
|
|||||||
require('./os/window-progress/window-progress'),
|
require('./os/window-progress/window-progress'),
|
||||||
require('./os/open-external/open-external'),
|
require('./os/open-external/open-external'),
|
||||||
require('./os/dropzone/dropzone'),
|
require('./os/dropzone/dropzone'),
|
||||||
|
require('./os/dialog/dialog'),
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
require('./utils/manifest-bind/manifest-bind')
|
require('./utils/manifest-bind/manifest-bind')
|
||||||
@ -149,26 +150,24 @@ app.run(($timeout, DriveScannerService, DrivesModel, ErrorService, DriveSelector
|
|||||||
DriveScannerService.start();
|
DriveScannerService.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.run(($window, WarningModalService, ErrorService, FlashStateModel) => {
|
app.run(($window, WarningModalService, ErrorService, FlashStateModel, OSDialogService) => {
|
||||||
let popupExists = false;
|
let popupExists = false;
|
||||||
|
|
||||||
$window.addEventListener('beforeunload', (event) => {
|
$window.addEventListener('beforeunload', (event) => {
|
||||||
|
if (!FlashStateModel.isFlashing() || popupExists) {
|
||||||
// Don't close window while flashing
|
|
||||||
if (FlashStateModel.isFlashing()) {
|
|
||||||
event.returnValue = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (popupExists) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't close window while flashing
|
||||||
|
event.returnValue = false;
|
||||||
|
|
||||||
// Don't open any more popups
|
// Don't open any more popups
|
||||||
popupExists = true;
|
popupExists = true;
|
||||||
|
|
||||||
WarningModalService.display({
|
return OSDialogService.showWarning({
|
||||||
confirmationLabel: 'Yes, quit',
|
confirmationLabel: 'Yes, quit',
|
||||||
rejectionLabel: 'Cancel',
|
rejectionLabel: 'Cancel',
|
||||||
|
title: 'Are you sure you want to close Etcher?',
|
||||||
description: messages.warning.exitWhileFlashing()
|
description: messages.warning.exitWhileFlashing()
|
||||||
}).then((confirmed) => {
|
}).then((confirmed) => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
|
@ -22,6 +22,13 @@ const imageStream = require('../../../../image-stream');
|
|||||||
|
|
||||||
module.exports = function($q, SupportedFormatsModel) {
|
module.exports = function($q, SupportedFormatsModel) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary Current renderer BrowserWindow instance
|
||||||
|
* @type {Object}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const currentWindow = electron.remote.getCurrentWindow();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Open an image selection dialog
|
* @summary Open an image selection dialog
|
||||||
* @function
|
* @function
|
||||||
@ -40,7 +47,6 @@ module.exports = function($q, SupportedFormatsModel) {
|
|||||||
*/
|
*/
|
||||||
this.selectImage = () => {
|
this.selectImage = () => {
|
||||||
return $q((resolve, reject) => {
|
return $q((resolve, reject) => {
|
||||||
const currentWindow = electron.remote.getCurrentWindow();
|
|
||||||
electron.remote.dialog.showOpenDialog(currentWindow, {
|
electron.remote.dialog.showOpenDialog(currentWindow, {
|
||||||
|
|
||||||
// This variable is set when running in GNU/Linux from
|
// This variable is set when running in GNU/Linux from
|
||||||
@ -81,6 +87,50 @@ module.exports = function($q, SupportedFormatsModel) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary Open a warning dialog
|
||||||
|
* @function
|
||||||
|
* @public
|
||||||
|
*
|
||||||
|
* @param {Object} options - options
|
||||||
|
* @param {String} options.title - dialog title
|
||||||
|
* @param {String} options.description - dialog description
|
||||||
|
* @param {String} options.confirmationLabel - confirmation label
|
||||||
|
* @param {String} options.rejectionLabel - rejection label
|
||||||
|
* @fulfil {Boolean} - whether the dialog was confirmed or not
|
||||||
|
* @returns {Promise};
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* OSDialogService.showWarning({
|
||||||
|
* title: 'This is a warning',
|
||||||
|
* description: 'Are you sure you want to continue?',
|
||||||
|
* confirmationLabel: 'Yes, continue',
|
||||||
|
* rejectionLabel: 'Cancel'
|
||||||
|
* }).then((confirmed) => {
|
||||||
|
* if (confirmed) {
|
||||||
|
* console.log('The dialog was confirmed');
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
this.showWarning = (options) => {
|
||||||
|
return $q((resolve) => {
|
||||||
|
electron.remote.dialog.showMessageBox(currentWindow, {
|
||||||
|
type: 'warning',
|
||||||
|
buttons: [
|
||||||
|
options.confirmationLabel,
|
||||||
|
options.rejectionLabel
|
||||||
|
],
|
||||||
|
defaultId: 1,
|
||||||
|
cancelId: 1,
|
||||||
|
title: 'Attention',
|
||||||
|
message: options.title,
|
||||||
|
detail: options.description
|
||||||
|
}, (response) => {
|
||||||
|
return resolve(response === 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Show error dialog for an Error instance
|
* @summary Show error dialog for an Error instance
|
||||||
* @function
|
* @function
|
||||||
|
@ -49,9 +49,8 @@ module.exports = {
|
|||||||
].join(' ')),
|
].join(' ')),
|
||||||
|
|
||||||
exitWhileFlashing: _.template([
|
exitWhileFlashing: _.template([
|
||||||
'You are currently flashing a drive. Closing Etcher may leave',
|
'You are currently flashing a drive.',
|
||||||
'your drive in an unusable state.\n\n',
|
'Closing Etcher may leave your drive in an unusable state.'
|
||||||
'Are you sure you want to close Etcher?'
|
|
||||||
].join(' '))
|
].join(' '))
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user