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) ->
|
2013-06-02 06:55:47 +00:00
|
|
|
# Show error in GUI.
|
2013-04-15 07:39:54 +00:00
|
|
|
message = error.stack ? "#{error.name}: #{error.message}"
|
2013-06-02 06:55:47 +00:00
|
|
|
require('dialog').showMessageBox
|
|
|
|
type: 'warning'
|
|
|
|
title: 'An javascript error occured in the browser'
|
|
|
|
message: 'uncaughtException'
|
|
|
|
detail: message
|
|
|
|
buttons: ['OK']
|
2013-04-15 07:39:54 +00:00
|
|
|
|
2013-04-24 08:43:01 +00:00
|
|
|
# Load the RPC server.
|
2013-05-30 12:16:54 +00:00
|
|
|
require './rpc-server.js'
|
2013-04-24 08:43:01 +00:00
|
|
|
|
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)
|