Start the specified app if there is one in command line parameters.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 17 Jul 2013 08:21:33 +0000 (16:21 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 17 Jul 2013 08:21:33 +0000 (16:21 +0800)
.gitignore
browser/default_app/default_app.js [new file with mode: 0644]
browser/default_app/main.js
browser/default_app/package.json

index 40fa8a2..607d61e 100644 (file)
@@ -6,6 +6,8 @@ dist/
 frameworks/
 node/
 node_modules/
+browser/default_app/node_modules/
+spec/node_modules/
 out/
 vendor/brightray/vendor/download/
 vendor/python_26/
diff --git a/browser/default_app/default_app.js b/browser/default_app/default_app.js
new file mode 100644 (file)
index 0000000..c24ee56
--- /dev/null
@@ -0,0 +1,165 @@
+var app = require('app');
+var dialog = require('dialog');
+var delegate = require('atom-delegate');
+var ipc = require('ipc');
+var Menu = require('menu');
+var MenuItem = require('menu-item');
+var BrowserWindow = require('browser-window');
+
+var mainWindow = null;
+var menu = null;
+
+// Quit when all windows are closed.
+app.on('window-all-closed', function() {
+  app.terminate();
+});
+
+app.on('open-url', function(event, url) {
+  dialog.showMessageBox({message: url, buttons: ['OK']});
+});
+
+app.on('finish-launching', function() {
+  app.commandLine.appendSwitch('js-flags', '--harmony_collections');
+
+  mainWindow = new BrowserWindow({ width: 800, height: 600 });
+  mainWindow.loadUrl('file://' + __dirname + '/index.html');
+
+  mainWindow.on('page-title-updated', function(event, title) {
+    event.preventDefault();
+
+    this.setTitle('Atom Shell - ' + title);
+  });
+
+  mainWindow.on('closed', function() {
+    console.log('closed');
+    mainWindow = null;
+  });
+
+  mainWindow.on('unresponsive', function() {
+    console.log('unresponsive');
+  });
+
+  var template = [
+    {
+      label: 'Atom Shell',
+      submenu: [
+        {
+          label: 'About Atom Shell',
+          selector: 'orderFrontStandardAboutPanel:'
+        },
+        {
+          type: 'separator'
+        },
+        {
+          label: 'Hide Atom Shell',
+          accelerator: 'Command+H',
+          selector: 'hide:'
+        },
+        {
+          label: 'Hide Others',
+          accelerator: 'Command+Shift+H',
+          selector: 'hideOtherApplications:'
+        },
+        {
+          label: 'Show All',
+          selector: 'unhideAllApplications:'
+        },
+        {
+          type: 'separator'
+        },
+        {
+          label: 'Quit',
+          accelerator: 'Command+Q',
+          click: function() { app.quit(); }
+        },
+      ]
+    },
+    {
+      label: 'Edit',
+      submenu: [
+        {
+          label: 'Undo',
+          accelerator: 'Command+Z',
+          selector: 'undo:'
+        },
+        {
+          label: 'Redo',
+          accelerator: 'Shift+Command+Z',
+          selector: 'redo:'
+        },
+        {
+          type: 'separator'
+        },
+        {
+          label: 'Cut',
+          accelerator: 'Command+X',
+          selector: 'cut:'
+        },
+        {
+          label: 'Copy',
+          accelerator: 'Command+C',
+          selector: 'copy:'
+        },
+        {
+          label: 'Paste',
+          accelerator: 'Command+V',
+          selector: 'paste:'
+        },
+        {
+          label: 'Select All',
+          accelerator: 'Command+A',
+          selector: 'selectAll:'
+        },
+      ]
+    },
+    {
+      label: 'View',
+      submenu: [
+        {
+          label: 'Reload',
+          accelerator: 'Command+R',
+          click: function() { BrowserWindow.getFocusedWindow().restart(); }
+        },
+        {
+          label: 'Enter Fullscreen',
+          click: function() { BrowserWindow.getFocusedWindow().setFullscreen(true); }
+        },
+        {
+          label: 'Toggle DevTools',
+          accelerator: 'Alt+Command+I',
+          click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
+        },
+      ]
+    },
+    {
+      label: 'Window',
+      submenu: [
+        {
+          label: 'Minimize',
+          accelerator: 'Command+M',
+          selector: 'performMiniaturize:'
+        },
+        {
+          label: 'Close',
+          accelerator: 'Command+W',
+          selector: 'performClose:'
+        },
+        {
+          type: 'separator'
+        },
+        {
+          label: 'Bring All to Front',
+          selector: 'arrangeInFront:'
+        },
+      ]
+    },
+  ];
+
+  menu = Menu.buildFromTemplate(template);
+  Menu.setApplicationMenu(menu);
+
+  ipc.on('message', function(processId, routingId, type) {
+    if (type == 'menu')
+      menu.popup(mainWindow);
+  });
+});
index a028f28..f5cc297 100644 (file)
-var app = require('app');
+var argv = require('optimist').argv;
 var dialog = require('dialog');
-var delegate = require('atom-delegate');
-var ipc = require('ipc');
-var Menu = require('menu');
-var MenuItem = require('menu-item');
-var BrowserWindow = require('browser-window');
+var path = require('path');
 
-var mainWindow = null;
-var menu = null;
-
-// Quit when all windows are closed.
-app.on('window-all-closed', function() {
-  app.terminate();
-});
-
-app.on('open-url', function(event, url) {
-  dialog.showMessageBox({message: url, buttons: ['OK']});
-});
-
-delegate.browserMainParts.preMainMessageLoopRun = function() {
-  app.commandLine.appendSwitch('js-flags', '--harmony_collections');
-
-  mainWindow = new BrowserWindow({ width: 800, height: 600 });
-  mainWindow.loadUrl('file://' + __dirname + '/index.html');
-
-  mainWindow.on('page-title-updated', function(event, title) {
-    event.preventDefault();
-
-    this.setTitle('Atom Shell - ' + title);
+// Start the specified app if there is one specified in command line, otherwise
+// start the default app.
+if (argv._.length > 0) {
+  process.on('uncaughtException', function() {
+    process.exit(1);
   });
 
-  mainWindow.on('closed', function() {
-    console.log('closed');
-    mainWindow = null;
-  });
-
-  mainWindow.on('unresponsive', function() {
-    console.log('unresponsive');
-  });
-
-  var template = [
-    {
-      label: 'Atom Shell',
-      submenu: [
-        {
-          label: 'About Atom Shell',
-          selector: 'orderFrontStandardAboutPanel:'
-        },
-        {
-          type: 'separator'
-        },
-        {
-          label: 'Hide Atom Shell',
-          accelerator: 'Command+H',
-          selector: 'hide:'
-        },
-        {
-          label: 'Hide Others',
-          accelerator: 'Command+Shift+H',
-          selector: 'hideOtherApplications:'
-        },
-        {
-          label: 'Show All',
-          selector: 'unhideAllApplications:'
-        },
-        {
-          type: 'separator'
-        },
-        {
-          label: 'Quit',
-          accelerator: 'Command+Q',
-          click: function() { app.quit(); }
-        },
-      ]
-    },
-    {
-      label: 'Edit',
-      submenu: [
-        {
-          label: 'Undo',
-          accelerator: 'Command+Z',
-          selector: 'undo:'
-        },
-        {
-          label: 'Redo',
-          accelerator: 'Shift+Command+Z',
-          selector: 'redo:'
-        },
-        {
-          type: 'separator'
-        },
-        {
-          label: 'Cut',
-          accelerator: 'Command+X',
-          selector: 'cut:'
-        },
-        {
-          label: 'Copy',
-          accelerator: 'Command+C',
-          selector: 'copy:'
-        },
-        {
-          label: 'Paste',
-          accelerator: 'Command+V',
-          selector: 'paste:'
-        },
-        {
-          label: 'Select All',
-          accelerator: 'Command+A',
-          selector: 'selectAll:'
-        },
-      ]
-    },
-    {
-      label: 'View',
-      submenu: [
-        {
-          label: 'Reload',
-          accelerator: 'Command+R',
-          click: function() { BrowserWindow.getFocusedWindow().restart(); }
-        },
-        {
-          label: 'Enter Fullscreen',
-          click: function() { BrowserWindow.getFocusedWindow().setFullscreen(true); }
-        },
-        {
-          label: 'Toggle DevTools',
-          accelerator: 'Alt+Command+I',
-          click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
-        },
-      ]
-    },
-    {
-      label: 'Window',
-      submenu: [
-        {
-          label: 'Minimize',
-          accelerator: 'Command+M',
-          selector: 'performMiniaturize:'
-        },
-        {
-          label: 'Close',
-          accelerator: 'Command+W',
-          selector: 'performClose:'
-        },
-        {
-          type: 'separator'
-        },
-        {
-          label: 'Bring All to Front',
-          selector: 'arrangeInFront:'
-        },
-      ]
-    },
-  ];
-
-  menu = Menu.buildFromTemplate(template);
-  Menu.setApplicationMenu(menu);
-
-  ipc.on('message', function(processId, routingId, type) {
-    if (type == 'menu')
-      menu.popup(mainWindow);
-  });
+  require(path.resolve(argv._[0]));
+} else {
+  require('./default_app.js');
 }
index f495eee..f279497 100644 (file)
@@ -1,5 +1,8 @@
 {
-  "name"    : "atom",
-  "version" : "0.1.0",
-  "main"    : "main.js"
+  "name": "atom",
+  "version": "0.1.0",
+  "main": "main.js",
+  "dependencies": {
+    "optimist": "*"
+  }
 }