2013-05-02 16:05:09 +00:00
|
|
|
EventEmitter = require('events').EventEmitter
|
|
|
|
|
2013-12-26 10:41:21 +00:00
|
|
|
bindings = process.atomBinding 'app'
|
2015-09-01 10:02:14 +00:00
|
|
|
sessionBindings = process.atomBinding 'session'
|
2015-09-20 10:56:10 +00:00
|
|
|
downloadItemBindings = process.atomBinding 'download_item'
|
2013-12-26 10:41:21 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
app = bindings.app
|
|
|
|
app.__proto__ = EventEmitter.prototype
|
2013-05-17 07:39:44 +00:00
|
|
|
|
2015-09-01 10:02:14 +00:00
|
|
|
wrapSession = (session) ->
|
|
|
|
# session is an Event Emitter.
|
|
|
|
session.__proto__ = EventEmitter.prototype
|
|
|
|
|
2015-09-20 10:56:10 +00:00
|
|
|
wrapDownloadItem = (download_item) ->
|
|
|
|
# download_item is an Event Emitter.
|
|
|
|
download_item.__proto__ = EventEmitter.prototype
|
2015-09-21 01:38:06 +00:00
|
|
|
# Be compatible with old APIs.
|
2015-09-24 07:55:45 +00:00
|
|
|
download_item.url = download_item.getUrl()
|
2015-09-24 08:31:41 +00:00
|
|
|
download_item.filename = download_item.getFilename()
|
2015-09-21 01:38:06 +00:00
|
|
|
download_item.mimeType = download_item.getMimeType()
|
|
|
|
download_item.hasUserGesture = download_item.hasUserGesture()
|
2015-09-20 10:56:10 +00:00
|
|
|
|
2013-10-05 05:46:48 +00:00
|
|
|
app.setApplicationMenu = (menu) ->
|
|
|
|
require('menu').setApplicationMenu menu
|
|
|
|
|
2013-10-05 13:05:59 +00:00
|
|
|
app.getApplicationMenu = ->
|
|
|
|
require('menu').getApplicationMenu()
|
|
|
|
|
2013-05-17 07:39:44 +00:00
|
|
|
app.commandLine =
|
|
|
|
appendSwitch: bindings.appendSwitch,
|
|
|
|
appendArgument: bindings.appendArgument
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2013-08-06 08:19:56 +00:00
|
|
|
if process.platform is 'darwin'
|
|
|
|
app.dock =
|
2013-12-26 10:41:21 +00:00
|
|
|
bounce: (type='informational') -> bindings.dockBounce type
|
2013-08-06 08:19:56 +00:00
|
|
|
cancelBounce: bindings.dockCancelBounce
|
|
|
|
setBadge: bindings.dockSetBadgeText
|
2013-08-06 08:39:31 +00:00
|
|
|
getBadge: bindings.dockGetBadgeText
|
2014-07-29 14:31:51 +00:00
|
|
|
hide: bindings.dockHide
|
|
|
|
show: bindings.dockShow
|
2014-11-16 15:04:31 +00:00
|
|
|
setMenu: bindings.dockSetMenu
|
2013-08-06 08:19:56 +00:00
|
|
|
|
2015-07-06 09:35:35 +00:00
|
|
|
appPath = null
|
|
|
|
app.setAppPath = (path) ->
|
|
|
|
appPath = path
|
|
|
|
|
|
|
|
app.getAppPath = ->
|
|
|
|
appPath
|
|
|
|
|
2015-09-01 10:02:14 +00:00
|
|
|
# Be compatible with old API.
|
|
|
|
app.once 'ready', -> @emit 'finish-launching'
|
2014-04-10 09:07:39 +00:00
|
|
|
app.terminate = app.quit
|
|
|
|
app.exit = process.exit
|
2015-06-24 04:01:19 +00:00
|
|
|
app.getHomeDir = -> @getPath 'home'
|
|
|
|
app.getDataPath = -> @getPath 'userData'
|
|
|
|
app.setDataPath = (path) -> @setPath 'userData', path
|
|
|
|
app.resolveProxy = -> @defaultSession.resolveProxy.apply @defaultSession, arguments
|
2015-09-16 00:36:01 +00:00
|
|
|
app.on 'activate', (event, hasVisibleWindows) -> @emit 'activate-with-no-open-windows' if not hasVisibleWindows
|
2013-12-27 03:08:26 +00:00
|
|
|
|
2015-09-01 10:02:14 +00:00
|
|
|
# Session wrapper.
|
|
|
|
sessionBindings._setWrapSession wrapSession
|
|
|
|
process.once 'exit', sessionBindings._clearWrapSession
|
|
|
|
|
2015-09-20 10:56:10 +00:00
|
|
|
downloadItemBindings._setWrapDownloadItem wrapDownloadItem
|
|
|
|
process.once 'exit', downloadItemBindings._clearWrapDownloadItem
|
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
# Only one App object pemitted.
|
2013-05-17 07:39:44 +00:00
|
|
|
module.exports = app
|