etcher/lib/gui/etcher.js
Juan Cruz Viotti 77c60b91c6 upgrade: drivelist to v5.0.25 (#1574)
This version contains various improvements on the drive detection system
mainly on Windows. The improvements can be summarized as follows:

- Drivelist no longer spawns a .bat script to perform its job. This
  means that a lot of spawning related issues are now fixed

- Drivelist doesn't fetch drive sizes from WMI anymore, which was known
  to incorrectly report a very small size for certain drives, causing
  the famous "0.0 GB" Windows issues (see
  https://github.com/resin-io-modules/drivelist/issues/142)

- Cleanup temporary scripts after execution

This PR also sets the DRIVELIST_DEBUG environment variable to enable
debug information from Windows' drivelist implementation.

Change-Type: patch
Changelog-Entry: Implement Windows drive detection using C++
Changelog-Entry: Fix various Windows `.bat` spawning issues
Changelog-Entry: Fix 0.0 GB Windows drive detection issues
Changelog-Entry: Cleanup drive detection temporary scripts created for other operating systems
Fixes: https://github.com/resin-io/etcher/issues/1108
Fixes: https://github.com/resin-io/etcher/issues/1054
Fixes: https://github.com/resin-io/etcher/issues/995
Fixes: https://github.com/resin-io/etcher/issues/1483
Fixes: https://github.com/resin-io/etcher/issues/1142
Fixes: https://github.com/resin-io/etcher/issues/1571
See: https://github.com/resin-io-modules/drivelist/blob/master/CHANGELOG.md
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
2017-07-12 15:18:05 -04:00

113 lines
3.8 KiB
JavaScript

/*
* Copyright 2016 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const electron = require('electron');
const _ = require('lodash');
const path = require('path');
const EXIT_CODES = require('../shared/exit-codes');
let mainWindow = null;
// Enable drivelist debugging information
// See https://github.com/resin-io-modules/drivelist
process.env.DRIVELIST_DEBUG = 1;
electron.app.on('window-all-closed', electron.app.quit);
// Sending a `SIGINT` (e.g: Ctrl-C) to an Electron app that registers
// a `beforeunload` window event handler results in a disconnected white
// browser window in GNU/Linux and macOS.
// The `before-quit` Electron event is triggered in `SIGINT`, so we can
// make use of it to ensure the browser window is completely destroyed.
// See https://github.com/electron/electron/issues/5273
electron.app.on('before-quit', () => {
process.exit(EXIT_CODES.SUCCESS);
});
electron.app.on('ready', () => {
// No menu bar
electron.Menu.setApplicationMenu(null);
mainWindow = new electron.BrowserWindow({
width: 800,
height: 380,
useContentSize: true,
show: false,
resizable: false,
fullscreen: false,
titleBarStyle: 'hidden-inset',
icon: path.join(__dirname, '..', '..', 'assets', 'icon.png')
});
// Prevent flash of white when starting the application
mainWindow.on('ready-to-show', mainWindow.show);
mainWindow.on('closed', () => {
mainWindow = null;
});
// For some reason, Electron shortcuts are registered
// globally, which means that the app listers for shorcuts
// even if its not currently focused, potentially interferring
// with shorcuts registered by other applications.
// As a workaround, we register all shortcuts when the windows
// gains focus, and unregister them when the windows loses focus.
// See http://electron.atom.io/docs/api/global-shortcut/
mainWindow.on('focus', () => {
electron.globalShortcut.register('CmdOrCtrl+Alt+I', () => {
mainWindow.webContents.openDevTools({
mode: 'detach'
});
});
// Disable refreshing the browser window
// This is supposed to be handled by the `will-navigate`
// event, however there seems to be an issue where such
// event is not fired in macOS
// See: https://github.com/electron/electron/issues/8841
electron.globalShortcut.register('CmdOrCtrl+R', _.noop);
electron.globalShortcut.register('F5', _.noop);
});
mainWindow.on('blur', () => {
electron.globalShortcut.unregisterAll();
});
// Prevent the user from being allowed to zoom-in the application.
//
// This function should be called on the renderer process. We use
// `executeJavaScript()` rather than moving this to a file in the
// renderer process for convenience, since we have all other
// electron desktop experience fixes in this file.
//
// See https://github.com/electron/electron/issues/3609
mainWindow.webContents.executeJavaScript('require(\'electron\').webFrame.setZoomLevelLimits(1, 1);');
// Prevent external resources from being loaded (like images)
// when dropping them on the WebView.
// See https://github.com/electron/electron/issues/5919
mainWindow.webContents.on('will-navigate', (event) => {
event.preventDefault();
});
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
});