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 bb2c1e30a7
commit e5e72e25da

View file

@ -334,14 +334,21 @@ class Application
# Public: Executes the given command. # Public: Executes the given command.
# #
# If it isn't handled globally, delegate to the currently focused window. # 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. # command - The string representing the command.
# args - The optional arguments to pass along. # args - The optional arguments to pass along.
sendCommand: (command, args...) -> sendCommand: (command, args...) ->
unless @emit(command, args...) unless @emit(command, args...)
focusedWindow = @windowManager.focusedWindow() focusedWindow = @windowManager.focusedWindow()
mainWindow = @windowManager.mainWindow()
if focusedWindow? if focusedWindow?
focusedWindow.sendCommand(command, args...) focusedWindow.sendCommand(command, args...)
else if mainWindow?
mainWindow.sendCommand(command, args...)
else else
@sendCommandToFirstResponder(command) @sendCommandToFirstResponder(command)