Skip to content

Commit b35a7c7

Browse files
committed
Refuse to open non React Native apps
1 parent fa42ed8 commit b35a7c7

File tree

7 files changed

+35
-33
lines changed

7 files changed

+35
-33
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["env", "react", "stage-0"]
2+
"presets": ["env", "react", "stage-0"],
3+
"plugins": ["dynamic-import-node"]
34
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is a GUI for running React Native commands. It is built with electron so it
55

66
# Downloads
77

8-
[v0.1.1](http://v1.1.1) is out! Choose your weapon.
8+
v0.1.2 is out! Choose your weapon.
99

1010

1111
[<img alt="Mac" src="http://clinsite.com/wp-content/uploads/2017/01/Apple-logo-120x120.png" />](https://drive.google.com/open?id=12GdTnRph5DMrAj5b8Kmntykm0lXbOcT-)

app/components/Layout/AppCard.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// @flow
22
import React, {PureComponent} from 'react';
3-
import {Card, CardHeader} from 'material-ui/Card';
3+
import {Card, CardHeader, CardActions} from 'material-ui/Card';
44
import path from 'path';
5+
import Chip from 'material-ui/Chip';
56

67
import Animated from '../Base/Animated';
78

@@ -28,6 +29,17 @@ class AppCard extends PureComponent<$AppCardProps> {
2829
actAsExpander
2930
showExpandableButton={false}
3031
/>
32+
<CardActions>
33+
{(
34+
this.props.app.info &&
35+
this.props.app.info.dependencies &&
36+
this.props.app.info.dependencies['react-native'] && (
37+
<Chip>
38+
React Native v{this.props.app.info.dependencies['react-native']}
39+
</Chip>
40+
)
41+
)}
42+
</CardActions>
3143
</Card>
3244
</Animated>
3345
);

app/redux/actions/appsActions.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
// eslint-disable-next-line import/no-unresolved, import/extensions
12
import {remote} from 'electron';
23
import first from 'lodash/first';
34
import find from 'lodash/find';
45

56
import store from '../store';
67
import * as types from '../types';
7-
import {read, stat} from '../../helpers/fsHelpers';
88

99
export 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

5149
export 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-
};

assets/icons/icon.ico

66.1 KB
Binary file not shown.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"babel-core": "^6.26.0",
2929
"babel-eslint": "^8.2.3",
3030
"babel-loader": "^7.1.2",
31+
"babel-plugin-dynamic-import-node": "^1.2.0",
32+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
3133
"babel-plugin-syntax-flow": "^6.18.0",
3234
"babel-preset-electron": "^1.4.15",
3335
"babel-preset-env": "^1.6.1",

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ babel-plugin-check-es2015-constants@^6.22.0:
496496
dependencies:
497497
babel-runtime "^6.22.0"
498498

499+
babel-plugin-dynamic-import-node@^1.2.0:
500+
version "1.2.0"
501+
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-1.2.0.tgz#f91631e703e0595e47d4beafbb088576c87fbeee"
502+
dependencies:
503+
babel-plugin-syntax-dynamic-import "^6.18.0"
504+
499505
babel-plugin-syntax-async-functions@^6.8.0:
500506
version "6.13.0"
501507
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"

0 commit comments

Comments
 (0)