2013-09-09 02:54:08 +00:00
var app = require ( 'app' ) ;
2014-05-05 08:35:06 +00:00
var dialog = require ( 'dialog' ) ;
2014-05-24 03:18:06 +00:00
var fs = require ( 'fs' ) ;
2013-07-17 08:21:33 +00:00
var path = require ( 'path' ) ;
2013-04-17 12:05:43 +00:00
2013-09-09 02:54:08 +00:00
// Quit when all windows are closed and no other one is listening to this.
app . on ( 'window-all-closed' , function ( ) {
if ( app . listeners ( 'window-all-closed' ) . length == 1 )
app . quit ( ) ;
} ) ;
2014-08-25 11:11:26 +00:00
// Parse command line options.
var argv = process . argv . slice ( 1 ) ;
2014-09-12 14:54:00 +00:00
var option = { file : null , version : null , webdriver : null } ;
2014-08-25 11:11:26 +00:00
for ( var i in argv ) {
if ( argv [ i ] == '--version' || argv [ i ] == '-v' ) {
option . version = true ;
break ;
2014-09-12 14:54:00 +00:00
} else if ( argv [ i ] == '--test-type=webdriver' ) {
option . webdriver = true ;
2014-08-25 11:11:26 +00:00
} else if ( argv [ i ] [ 0 ] == '-' ) {
continue ;
} else {
option . file = argv [ i ] ;
break ;
}
}
2013-10-03 03:36:17 +00:00
2013-07-17 08:21:33 +00:00
// Start the specified app if there is one specified in command line, otherwise
// start the default app.
2014-09-12 14:54:00 +00:00
if ( option . file && ! option . webdriver ) {
2013-07-24 07:20:59 +00:00
try {
2014-05-24 03:18:06 +00:00
// Override app name and version.
2014-08-25 11:11:26 +00:00
var packagePath = path . resolve ( option . file ) ;
2014-05-24 03:18:06 +00:00
var packageJsonPath = path . join ( packagePath , 'package.json' ) ;
if ( fs . existsSync ( packageJsonPath ) ) {
var packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath ) ) ;
if ( packageJson . version )
app . setVersion ( packageJson . version ) ;
if ( packageJson . productName )
app . setName ( packageJson . productName ) ;
else if ( packageJson . name )
app . setName ( packageJson . name ) ;
2015-01-19 01:58:17 +00:00
app . setPath ( 'userData' , path . join ( app . getPath ( 'appData' ) , app . getName ( ) ) ) ;
2015-01-19 05:09:42 +00:00
app . setPath ( 'userCache' , path . join ( app . getPath ( 'cache' ) , app . getName ( ) ) ) ;
2014-05-24 03:18:06 +00:00
}
// Run the app.
2014-06-22 06:57:11 +00:00
require ( 'module' ) . _load ( packagePath , module , true ) ;
2013-07-24 07:20:59 +00:00
} catch ( e ) {
2014-05-14 08:27:40 +00:00
if ( e . code == 'MODULE_NOT_FOUND' ) {
app . focus ( ) ;
2014-11-05 08:05:29 +00:00
dialog . showErrorBox ( 'Error opening app' , 'The app provided is not a valid atom-shell app, please read the docs on how to write one:\nhttps://github.com/atom/atom-shell/tree/master/docs' ) ;
2014-05-14 08:27:40 +00:00
process . exit ( 1 ) ;
} else {
2015-03-02 20:08:12 +00:00
console . error ( 'App threw an error when running' , e ) ;
2014-05-14 08:27:40 +00:00
throw e ;
}
2013-07-24 07:20:59 +00:00
}
2014-08-25 11:11:26 +00:00
} else if ( option . version ) {
2013-10-03 03:48:13 +00:00
console . log ( 'v' + process . versions [ 'atom-shell' ] ) ;
2013-10-03 03:36:17 +00:00
process . exit ( 0 ) ;
2013-07-17 08:21:33 +00:00
} else {
require ( './default_app.js' ) ;
2013-04-15 07:39:54 +00:00
}