]> khamidou — GitHub mirrors - electron.git/commitdiff
Initial javascript startup code.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 15 Apr 2013 07:39:54 +0000 (15:39 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 15 Apr 2013 07:39:54 +0000 (15:39 +0800)
atom.gyp
browser/api/lib/atom.coffee [new file with mode: 0644]
browser/atom/atom.coffee
browser/default_app/main.js
browser/default_app/package.json [new file with mode: 0644]

index 7f85dd31aba8a021a800cba9c8164f15c80db2d3..9741955703293ea6471f49805e86ecbfcd0eae7a 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -6,6 +6,7 @@
       'app/atom_main.cc',
     ],
     'coffee_sources': [
+      'browser/api/lib/atom.coffee',
       'browser/atom/atom.coffee',
     ],
     'lib_sources': [
@@ -84,7 +85,7 @@
               ],
             },
             {
-              'destination': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources',
+              'destination': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/browser',
               'files': [
                 'browser/default_app',
               ],
diff --git a/browser/api/lib/atom.coffee b/browser/api/lib/atom.coffee
new file mode 100644 (file)
index 0000000..f38491e
--- /dev/null
@@ -0,0 +1 @@
+module.exports = global.__atom
index e6744db1325a828725b6e764f50554705b027d47..56b5367fe8caca3b885a07026b18cee4166365da 100644 (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.
-process.on "uncaughtException", (error) ->
-  console.error "uncaughtException:"
-  if error.stack?
-    console.error error.stack
-  else
-    console.error error.name + ": " + error.message
+process.on 'uncaughtException', (error) ->
+  # TODO Show error in GUI.
+  message = error.stack ? "#{error.name}: #{error.message}"
+  console.error 'uncaughtException:'
+  console.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)
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..77c0bc27e797ee22d23b3f0a7b035186fb79e1b6 100644 (file)
@@ -0,0 +1,5 @@
+var atom = require('atom');
+
+atom.browserMainParts.preMainMessageLoopRun = function() {
+  console.log('Create new window');
+}
diff --git a/browser/default_app/package.json b/browser/default_app/package.json
new file mode 100644 (file)
index 0000000..f495eee
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "name"    : "atom",
+  "version" : "0.1.0",
+  "main"    : "main.js"
+}