Initial javascript startup code.

This commit is contained in:
Cheng Zhao 2013-04-15 15:39:54 +08:00
parent a7516f3da5
commit ef2056c3f5
5 changed files with 52 additions and 7 deletions

View file

@ -6,6 +6,7 @@
'app/atom_main.cc', 'app/atom_main.cc',
], ],
'coffee_sources': [ 'coffee_sources': [
'browser/api/lib/atom.coffee',
'browser/atom/atom.coffee', 'browser/atom/atom.coffee',
], ],
'lib_sources': [ 'lib_sources': [
@ -84,7 +85,7 @@
], ],
}, },
{ {
'destination': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources', 'destination': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/browser',
'files': [ 'files': [
'browser/default_app', 'browser/default_app',
], ],

View file

@ -0,0 +1 @@
module.exports = global.__atom

View file

@ -1,7 +1,40 @@
fs = require 'fs'
path = require 'path'
# 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,
# which contains javascript of Atom's built-in libraries.
require('module').globalPaths.push path.join(__dirname, '..', 'api', 'lib')
# Don't quit on fatal error. # Don't quit on fatal error.
process.on "uncaughtException", (error) -> process.on 'uncaughtException', (error) ->
console.error "uncaughtException:" # TODO Show error in GUI.
if error.stack? message = error.stack ? "#{error.name}: #{error.message}"
console.error error.stack console.error 'uncaughtException:'
else console.error message
console.error error.name + ": " + error.message
# 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)

View file

@ -0,0 +1,5 @@
var atom = require('atom');
atom.browserMainParts.preMainMessageLoopRun = function() {
console.log('Create new window');
}

View file

@ -0,0 +1,5 @@
{
"name" : "atom",
"version" : "0.1.0",
"main" : "main.js"
}