From b47c70784580a110dba1e95363ef5c94cb993a19 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Tue, 15 Mar 2016 12:12:30 -0700 Subject: [PATCH] fix(focus): Show drafts in unfocused state when window is blurred - See #1695 - Update key commands region to clear focus when window blurs - Dispatch broswer-window-focus/blur as a window event into the renderer window - Update tray icon to listen to window instead of ipc event --- .../system-tray/lib/system-tray-icon-store.es6 | 9 +++++---- src/components/key-commands-region.cjsx | 5 +++++ src/window-event-handler.coffee | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/internal_packages/system-tray/lib/system-tray-icon-store.es6 b/internal_packages/system-tray/lib/system-tray-icon-store.es6 index 5f23da9a9..b830165f7 100644 --- a/internal_packages/system-tray/lib/system-tray-icon-store.es6 +++ b/internal_packages/system-tray/lib/system-tray-icon-store.es6 @@ -26,10 +26,11 @@ class SystemTrayIconStore { this._updateIcon() this._unsubscribers.push(UnreadBadgeStore.listen(this._updateIcon)); - ipcRenderer.on('browser-window-blur', this._onWindowBlur) - ipcRenderer.on('browser-window-focus', this._onWindowFocus) - this._unsubscribers.push(() => ipcRenderer.removeListener('browser-window-blur', this._onWindowBlur)) - this._unsubscribers.push(() => ipcRenderer.removeListener('browser-window-focus', this._onWindowFocus)) + + window.addEventListener('browser-window-blur', this._onWindowBlur); + window.addEventListener('browser-window-focus', this._onWindowFocus); + this._unsubscribers.push(() => window.removeEventListener('browser-window-blur', this._onWindowBlur)) + this._unsubscribers.push(() => window.removeEventListener('browser-window-focus', this._onWindowFocus)) } _getIconImageData(unreadCount, isWindowBlurred) { diff --git a/src/components/key-commands-region.cjsx b/src/components/key-commands-region.cjsx index 4f40cb897..784fb5c51 100644 --- a/src/components/key-commands-region.cjsx +++ b/src/components/key-commands-region.cjsx @@ -162,6 +162,7 @@ class KeyCommandsRegion extends React.Component @_localDisposable = NylasEnv.commands.add($el, props.localHandlers) $el.addEventListener('focusin', @_in) $el.addEventListener('focusout', @_out) + window.addEventListener('browser-window-blur', @_onWindowBlur) _unmountListeners: -> @_globalDisposable?.dispose() @@ -171,8 +172,12 @@ class KeyCommandsRegion extends React.Component $el = React.findDOMNode(@) $el.removeEventListener('focusin', @_in) $el.removeEventListener('focusout', @_out) + window.removeEventListener('browser-window-blur', @_onWindowBlur) @_goingout = false + _onWindowBlur: => + @setState(focused: false) + render: -> classname = classNames 'key-commands-region': true diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index d6ce9596e..d0a300e12 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -32,9 +32,11 @@ class WindowEventHandler @subscribe ipcRenderer, 'browser-window-focus', -> document.body.classList.remove('is-blurred') + window.dispatchEvent(new Event('browser-window-focus')) @subscribe ipcRenderer, 'browser-window-blur', -> document.body.classList.add('is-blurred') + window.dispatchEvent(new Event('browser-window-blur')) @subscribe ipcRenderer, 'command', (event, command, args...) -> activeElement = document.activeElement