Turns out that even by using `process.exit(1)`, the electron main
process doesn't exit instantly, but continues executing code.
This causes electron to throw on `electron.globalShortcut` because this
functionality is not available given that we didn't create a renderer
view.
Fixes: https://github.com/resin-io/etcher/issues/215
This error was reported by TrackJS various times:
```
TypeError: Cannot read property 'length' of undefined
at EventEmitter.<anonymous> (file:///Users/jviotti/Projects/resin/etcher/lib/browser/app.js:104:15)
at emitOne (events.js:77:13)
at EventEmitter.emit (events.js:169:7)
at /Users/jviotti/Projects/resin/etcher/lib/browser/modules/drive-scanner.js:131:17
at processQueue (/Users/jviotti/Projects/resin/etcher/node_modules/angular/angular.js:15616:28)
at /Users/jviotti/Projects/resin/etcher/node_modules/angular/angular.js:15632:27
at Scope.$eval (/Users/jviotti/Projects/resin/etcher/node_modules/angular/angular.js:16884:28)
at Scope.$digest (/Users/jviotti/Projects/resin/etcher/node_modules/angular/angular.js:16700:31)
at /Users/jviotti/Projects/resin/etcher/node_modules/angular/angular.js:16923:26
at completeOutstandingRequest (/Users/jviotti/Projects/resin/etcher/node_modules/angular/angular.js:5825:10),
```
The error refers to the following line in `app.js`:
```js
if (drives.length === 1 && self.selection.hasImage()) {
```
Which indicates that the array of detected drives returned to the main
controller is `undefined` for some reason.
The problem resides in the `.scan()` method of `DriveScannerService`:
```js
this.scan = function() {
return $q.when(drives.listRemovable()).catch(dialog.showError);
};
```
When an error is thrown when scanning the drives, the `.catch()` block
is called. This means that the error is not propagated to the outer code
and the promise resolves with `undefined`.
The solution is to move `.catch()` to the place `.scan()` is called,
instead of making use of it in the low-level parts of the process.
Previously, the burn state lived in the controller, however if the user
moved to another page (the settings page for example) and then returned,
the progress state would be lost, leading to a broken progress bar.
Fixes: https://github.com/resin-io/etcher/issues/190
This service provides an easy-to-use and safe (regarding to memory
leaks) way to emit data from services to controllers.
This component will be used in `ImageWriterService` to emit the progress
state instead of accepting an `onProgress` callback.