Files
atom/src/app/atom.coffee
Nathan Sobo 980c5d6b11 Add support for native tracing w/ atom.begin/endTracing in console.
* Open the dev tools console
* Call `atom.beginTracing()`
* Do stuff
* Call `atom.endTracing()`
* Save the file somewhere
* Open `about:tracing` in chrome and load the file
* Inspect away!
2012-10-31 11:39:58 -06:00

70 lines
2.0 KiB
CoffeeScript

fs = require('fs')
atom.configDirPath = fs.absolute("~/.atom")
atom.configFilePath = fs.join(atom.configDirPath, "atom.coffee")
atom.exitWhenDone = window.location.params.exitWhenDone
messageIdCounter = 1
originalSendMessageToBrowserProcess = atom.sendMessageToBrowserProcess
atom.pendingBrowserProcessCallbacks = {}
atom.sendMessageToBrowserProcess = (name, data=[], callbacks) ->
messageId = messageIdCounter++
data.unshift(messageId)
callbacks = [callbacks] if typeof callbacks is 'function'
@pendingBrowserProcessCallbacks[messageId] = callbacks
originalSendMessageToBrowserProcess(name, data)
atom.receiveMessageFromBrowserProcess = (name, data) ->
if name is 'reply'
[messageId, callbackIndex] = data.shift()
@pendingBrowserProcessCallbacks[messageId]?[callbackIndex]?(data...)
atom.open = (args...) ->
@sendMessageToBrowserProcess('open', args)
atom.newWindow = (args...) ->
@sendMessageToBrowserProcess('newWindow', args)
atom.confirm = (message, detailedMessage, buttonLabelsAndCallbacks...) ->
args = [message, detailedMessage]
callbacks = []
while buttonLabelsAndCallbacks.length
args.push(buttonLabelsAndCallbacks.shift())
callbacks.push(buttonLabelsAndCallbacks.shift())
@sendMessageToBrowserProcess('confirm', args, callbacks)
atom.showSaveDialog = (callback) ->
@sendMessageToBrowserProcess('showSaveDialog', [], callback)
atom.toggleDevTools = ->
@sendMessageToBrowserProcess('toggleDevTools')
atom.showDevTools = ->
@sendMessageToBrowserProcess('showDevTools')
atom.focus = ->
@sendMessageToBrowserProcess('focus')
atom.exit = (status) ->
@sendMessageToBrowserProcess('exit', [status])
atom.beginTracing = ->
@sendMessageToBrowserProcess('beginTracing')
atom.endTracing = ->
@sendMessageToBrowserProcess('endTracing')
atom.getRootViewStateForPath = (path) ->
if json = localStorage[path]
JSON.parse(json)
atom.setRootViewStateForPath = (path, state) ->
return unless path
if state?
localStorage[path] = JSON.stringify(state)
else
delete localStorage[path]