From e5e72e25da759c8b40d52c8578ec3a7f19647038 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 1 Jun 2015 16:00:57 -0700 Subject: [PATCH] fix(app): When there is no focused window, dispatch events to the mainWindow Summary: This fixes T1766 and probably others as well, ensuring that commands not handled by the browser-side are still delivered to the main window even when it's hidden. Test Plan: Run tests Reviewers: evan Reviewed By: evan Maniphest Tasks: T1766 Differential Revision: https://phab.nylas.com/D1586 --- src/browser/application.coffee | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/browser/application.coffee b/src/browser/application.coffee index c08914674..31c8f391f 100644 --- a/src/browser/application.coffee +++ b/src/browser/application.coffee @@ -334,14 +334,21 @@ class Application # Public: Executes the given command. # # If it isn't handled globally, delegate to the currently focused window. + # If there is no focused window (all the windows of the app are hidden), + # fire the command to the main window. (This ensures that `application:` + # commands, like Cmd-N work when no windows are visible.) # # command - The string representing the command. # args - The optional arguments to pass along. sendCommand: (command, args...) -> unless @emit(command, args...) focusedWindow = @windowManager.focusedWindow() + mainWindow = @windowManager.mainWindow() + if focusedWindow? focusedWindow.sendCommand(command, args...) + else if mainWindow? + mainWindow.sendCommand(command, args...) else @sendCommandToFirstResponder(command)