From 180802b985a09f8dda8519d3a5da2bedad5c03b4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Sun, 26 Mar 2017 19:29:11 -0400 Subject: [PATCH] fix(GUI): disallow reloading the app in macOS using Cmd+R (#1219) Users can currently force the browser window to reload by using Cmd+R in macOS. The `will-navigate` event handler in this same file is supposed to protect us from this case, however it's not fired at all just in macOS for some reason. As a solution, we attach dummy keyboard shortcut handlers for Cmd+R, Ctrl+R, and F5, to override the normal browser window behaviour. The reason behind disallowing reloads is that a reload during a critical operation such as writing, validation, elevating, unmounting, drive scanning, etc will cause undefined behaviour, resulting in nonsense errors that we can't solve coming to TrackJS. See: https://github.com/electron/electron/issues/8841 Fixes: https://github.com/resin-io/etcher/issues/1210 Signed-off-by: Juan Cruz Viotti --- lib/gui/etcher.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/gui/etcher.js b/lib/gui/etcher.js index 81e94b74..aad2cac0 100644 --- a/lib/gui/etcher.js +++ b/lib/gui/etcher.js @@ -17,6 +17,7 @@ 'use strict'; const electron = require('electron'); +const _ = require('lodash'); const path = require('path'); let mainWindow = null; @@ -69,6 +70,15 @@ electron.app.on('ready', () => { 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', () => {