1+ // eslint-disable-next-line import/no-unresolved, import/extensions
12import { remote } from 'electron' ;
23import first from 'lodash/first' ;
34import find from 'lodash/find' ;
45
56import store from '../store' ;
67import * as types from '../types' ;
7- import { read , stat } from '../../helpers/fsHelpers' ;
88
99export const openApp = async ( appPath , cb ) => {
1010 try {
@@ -13,7 +13,7 @@ export const openApp = async (appPath, cb) => {
1313 path = appPath ;
1414 } else {
1515 const directories = await remote . dialog . showOpenDialog ( {
16- properties : [ 'openDirectory' ]
16+ properties : [ 'openDirectory' ] ,
1717 } ) ;
1818 if ( directories ) {
1919 path = first ( directories ) ;
@@ -29,24 +29,22 @@ export const openApp = async (appPath, cb) => {
2929 }
3030 } ) ;
3131 }
32- store . dispatch ( { type : types . OPEN_APP , payload : { path} } ) ;
33- store . dispatch ( { type : types . SELECT_APP , payload : { path} } ) ;
3432 try {
35- const stats = await stat ( `${ path } /package.json` ) ;
36- store . dispatch ( { type : types . APP_HAS_PACKAGE , payload : { path, hasPackage : true } } ) ;
33+ const info = await import ( `${ path } /package.json` ) ;
34+ store . dispatch ( { type : types . OPEN_APP , payload : { path, info } } ) ;
3735 } catch ( error ) {
38- if ( error . code === 'ENOENT' ) {
39- store . dispatch ( { type : types . APP_HAS_PACKAGE , payload : { path, hasPackage : false } } ) ;
40- } else {
41- throw error ;
42- }
36+ store . dispatch ( {
37+ type : types . ERROR ,
38+ payload : {
39+ error : new Error ( `${ path } is not a React Native app` ) ,
40+ } ,
41+ } ) ;
4342 }
4443 }
4544 } catch ( error ) {
46- console . log ( error . stack ) ;
4745 store . dispatch ( { type : types . ERROR , payload : { error} } ) ;
4846 }
49- }
47+ } ;
5048
5149export const closeApp = async ( app ) => {
5250 try {
@@ -55,20 +53,3 @@ export const closeApp = async (app) => {
5553 store . dispatch ( { type : types . ERROR , payload : { error} } ) ;
5654 }
5755} ;
58-
59- export const openBase = async ( ) => {
60- try {
61- let path ;
62- const directories = await remote . dialog . showOpenDialog ( {
63- properties : [ 'openDirectory' ]
64- } ) ;
65- if ( directories ) {
66- path = first ( directories ) ;
67- }
68- if ( path ) {
69- }
70- } catch ( error ) {
71- console . log ( error . stack ) ;
72- store . dispatch ( { type : types . ERROR , payload : { error} } ) ;
73- }
74- } ;
0 commit comments