Separate IPC messages that don’t belong in the command palette

Path opening and update signaling were both using the command-sending
IPC mechanism, but neither is actually a command. This commit adds a
second “message” channel with custom handling on the render process
side for these messages, rather than attempting to route them through
commands.
This commit is contained in:
Nathan Sobo
2014-11-27 10:30:50 -07:00
parent 5fed6199ec
commit 0b44cee8db
7 changed files with 49 additions and 26 deletions

View File

@@ -783,6 +783,12 @@ class Atom extends Model
else
window[key] = value
onUpdateAvailable: (callback) ->
@emitter.on 'update-available', callback
updateAvailable: (details) ->
@emitter.emit 'update-available', details
# Deprecated: Callers should be converted to use atom.deserializers
registerRepresentationClass: ->
deprecate("Callers should be converted to use atom.deserializers")

View File

@@ -143,10 +143,13 @@ class AtomWindow
openPath: (pathToOpen, initialLine, initialColumn) ->
if @loaded
@focus()
@sendCommand('window:open-path', {pathToOpen, initialLine, initialColumn})
@sendMessage 'open-path', {pathToOpen, initialLine, initialColumn}
else
@browserWindow.once 'window:loaded', => @openPath(pathToOpen, initialLine, initialColumn)
sendMessage: (message, detail) ->
@browserWindow.webContents.send 'message', message, detail
sendCommand: (command, args...) ->
if @isSpecWindow()
unless global.atomApplication.sendCommandToFirstResponder(command)
@@ -154,7 +157,6 @@ class AtomWindow
when 'window:reload' then @reload()
when 'window:toggle-dev-tools' then @toggleDevTools()
when 'window:close' then @close()
when 'window:update-available' then @sendCommandToBrowserWindow(command, args...) # For spec testing
else if @isWebViewFocused()
@sendCommandToBrowserWindow(command, args...)
else

View File

@@ -56,7 +56,7 @@ class AutoUpdateManager
emitUpdateAvailableEvent: (windows...) ->
return unless @releaseVersion? and @releaseNotes
for atomWindow in windows
atomWindow.sendCommand('window:update-available', [@releaseVersion, @releaseNotes])
atomWindow.sendMessage('update-available', {@releaseVersion, @releaseNotes})
setState: (state) ->
return if @state is state

View File

@@ -14,8 +14,27 @@ class WindowEventHandler
constructor: ->
@reloadRequested = false
@subscribe ipc, 'command', (command, args...) ->
@subscribe ipc, 'message', (message, detail) ->
switch message
when 'open-path'
{pathToOpen, initialLine, initialColumn} = detail
unless atom.project?.getPaths().length
if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen))
atom.project?.setPaths([pathToOpen])
unless fs.isDirectorySync(pathToOpen)
atom.workspace?.open(pathToOpen, {initialLine, initialColumn})
when 'update-available'
atom.updateAvailable(detail)
# FIXME: Remove this when deprecations are removed
{releaseVersion, releaseNotes} = detail
detail = [releaseVersion, releaseNotes]
atom.commands.dispatch atom.views.getView(atom.workspace), "window:update-available", detail
@subscribe ipc, 'command', (command, args...) ->
activeElement = document.activeElement
# Use the workspace element view if body has focus
if activeElement is document.body and workspaceElement = atom.views.getView(atom.workspace)
@@ -30,14 +49,6 @@ class WindowEventHandler
@subscribe $(window), 'blur', -> document.body.classList.add('is-blurred')
@subscribeToCommand $(window), 'window:open-path', (event, {pathToOpen, initialLine, initialColumn}) ->
unless atom.project?.getPaths().length
if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen))
atom.project?.setPaths([pathToOpen])
unless fs.isDirectorySync(pathToOpen)
atom.workspace?.open(pathToOpen, {initialLine, initialColumn})
@subscribe $(window), 'beforeunload', =>
confirmed = atom.workspace?.confirmClose()
atom.hide() if confirmed and not @reloadRequested and atom.getCurrentWindow().isWebViewFocused()