2013-04-15 07:39:54 +00:00
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
|
|
|
|
2013-04-25 11:41:23 +00:00
|
|
|
# Enable idle gc.
|
2013-04-27 11:13:24 +00:00
|
|
|
process.atomBinding('idle_gc').start()
|
2013-04-25 11:41:23 +00:00
|
|
|
|
2013-04-15 07:39:54 +00:00
|
|
|
# Provide default Content API implementations.
|
|
|
|
atom = {}
|
|
|
|
|
|
|
|
atom.browserMainParts =
|
|
|
|
preMainMessageLoopRun: ->
|
|
|
|
# This is the start of the whole application, usually we should initialize
|
|
|
|
# the main window here.
|
|
|
|
|
|
|
|
# Store atom object in global scope, apps can just override methods of it to
|
|
|
|
# implement various logics.
|
|
|
|
global.__atom = atom
|
|
|
|
|
|
|
|
# Add Atom.app/Contents/Resources/browser/api/lib to require's search paths,
|
2013-04-24 08:43:01 +00:00
|
|
|
# which contains javascript part of Atom's built-in libraries.
|
|
|
|
globalPaths = require('module').globalPaths
|
|
|
|
globalPaths.push path.join(__dirname, '..', 'api', 'lib')
|
|
|
|
|
|
|
|
# And Atom.app/Contents/Resources/common/api/lib
|
|
|
|
globalPaths.push path.join(__dirname, '..', '..', 'common', 'api', 'lib')
|
2013-04-15 07:39:54 +00:00
|
|
|
|
2013-04-14 14:48:35 +00:00
|
|
|
# Don't quit on fatal error.
|
2013-04-15 07:39:54 +00:00
|
|
|
process.on 'uncaughtException', (error) ->
|
|
|
|
# TODO Show error in GUI.
|
|
|
|
message = error.stack ? "#{error.name}: #{error.message}"
|
|
|
|
console.error 'uncaughtException:'
|
|
|
|
console.error message
|
|
|
|
|
2013-04-24 08:43:01 +00:00
|
|
|
# Load the RPC server.
|
|
|
|
require './rpc_server.js'
|
|
|
|
|
2013-04-15 07:39:54 +00:00
|
|
|
# Now we try to load app's package.json.
|
|
|
|
packageJson = null
|
|
|
|
|
|
|
|
packagePath = path.join __dirname, '..', '..', 'app'
|
|
|
|
try
|
|
|
|
# First we try to load Atom.app/Contents/Resources/app
|
|
|
|
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
|
|
|
|
catch error
|
|
|
|
# If not found then we load Atom.app/Contents/Resources/browser/default_app
|
|
|
|
packagePath = path.join __dirname, '..', 'default_app'
|
|
|
|
packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json')))
|
|
|
|
|
|
|
|
# Finally load app's main.js and transfer control to C++.
|
|
|
|
require path.join(packagePath, packageJson.main)
|