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
This commit is contained in:
Ben Gotow 2015-06-01 16:00:57 -07:00
parent dad36aad2f
commit d35dcd32e3

View file

@ -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)