Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 46 additions & 8 deletions desktop/deco_unpack_lib/Scripts/deco-tool/configure.deco.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ const checkEnvironmentOK = () => {
const tools = path.join(process.env.ANDROID_HOME, 'tools')
const platformTools = path.join(process.env.ANDROID_HOME, 'platform-tools')
process.env.PATH = `${process.env.PATH}:${tools}:${platformTools}`
} else {
try {
fs.statSync(process.env.ANDROID_HOME)
const tools = path.join(process.env.ANDROID_HOME, 'tools')
const platformTools = path.join(process.env.ANDROID_HOME, 'platform-tools')
fs.statSync(tools)
fs.statSync(platformTools)
} catch (e) {
return false
}
}

return true
}

const checkGenymotionOK = () => {
if (!process.env.GENYMOTION_APP) {
const defaultGenymotionPath = `/Applications/Genymotion.app`
try {
fs.statSync(defaultGenymotionPath)
} catch (e) {
return false
}
} else {
try {
fs.statSync(process.env.GENYMOTION_APP)
if (path.basename(process.env.GENYMOTION_APP).indexOf('Genymotion') == -1) {
return false
}
} catch (e) {
return false
}
}
return true
}
Expand Down Expand Up @@ -226,19 +258,25 @@ DECO.on('build-ios', function (args) {
*/
DECO.on('list-android-sim', function(args) {
if (!checkEnvironmentOK()) {
return Promise.resolve()
}

if (!process.env.ANDROID_HOME) {
return Promise.reject({
payload: [
'No simulators available.',
'Please install Android Studio and create an emulator.'
'The Android SDK path is missing the "tools" sub-folder.',
'Please install Android Studio if you haven\'t already. (https://facebook.github.io/react-native/docs/getting-started.html#android-studio)',
'Please check preferences (cmd + ,) to make sure your Android SDK path is set to the right location.',
]
})
}

if (process.env.USE_GENYMOTION) {
if (!checkGenymotionOK()) {
return Promise.reject({
payload: [
'Cannot find your Genymotion Application',
'Check that it is installed, then set the path to your Genymotion in preferences (cmd + ,)'
]
})
}

return Promise.resolve({
payload: [{
name: 'Launch Geny',
Expand Down Expand Up @@ -350,8 +388,8 @@ DECO.on('sim-android', function (args) {
if (ticker > 60) {
console.log(`Device did not boot up in time, please wait for Android device to boot and then re-run this command.`)
clearInterval(interval)
} else if (ticker % 5 === 0){
console.log(`Still waiting on Android Virtual Device... will wait ${(60 - ticker)} more seconds.`)
} else if (ticker % 5 === 0) {
console.log(`Still waiting on Android Device to connect... will wait ${(60 - ticker)} more seconds.`)
}
}
}, 1000)
Expand Down
10 changes: 5 additions & 5 deletions desktop/src/bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const REQUEST_TYPES = [
ModuleConstants,
]

function sendToRenderer(channel, payload, toPreferences) {
function sendToRenderer(channel, payload, windowId) {
if (!channel) {
Logger.error('Channel was found broken', channel)
return
Expand All @@ -57,7 +57,7 @@ function sendToRenderer(channel, payload, toPreferences) {
payload = {} // not sure if this will cause problems when undefined or null
}

if (toPreferences) {
if (windowId == 'preferences') {
try {
if (!global.preferencesWindow) return
global.preferencesWindow.webContents.send(channel, payload)
Expand All @@ -84,7 +84,7 @@ class Bridge extends EventEmitter {
_init() {
_.each(REQUEST_TYPES, (requestTypes) => {
_.each(requestTypes, (id, requestType) => {
requestEmitter.on(id, (body, callback, evt, fromPreferences) => {
requestEmitter.on(id, (body, callback, evt) => {
this.emit(id, body, (resp) => {
if (resp && resp.type != ERROR) {
callback(null, resp)
Expand All @@ -97,8 +97,8 @@ class Bridge extends EventEmitter {
})
}

send(payload, toPreferences) {
this._send(payload.type, payload, toPreferences)
send(payload, windowId) {
this._send(payload.type, payload, windowId)
}

}
Expand Down
31 changes: 9 additions & 22 deletions desktop/src/bridge/requestEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,23 @@ import { EventEmitter, } from 'events'

import Logger from '../log/logger'

function sendToRenderer(messageId, err, data, fromPreferences) {
if (fromPreferences) {
try {
if (!global.preferencesWindow) return
global.preferencesWindow.webContents.send('response', messageId, err, data)
} catch (e) {
//the preferences window may not be open...
Logger.error(e)
}
} else {
for (var id in global.openWindows) {
global.openWindows[id].webContents.send('response', messageId, err, data)
}
}

}

class RequestEmitter extends EventEmitter {
emit(channel, messageId, body, evt, fromPreferences) {
emit(channel, messageId, body, evt) {
const callback = (err, data) => {
sendToRenderer(messageId, err, data, fromPreferences)
try {
evt.sender.send('response', messageId, err, data)
} catch (e) {
Logger.error(e)
}
}
super.emit(channel, body, callback, evt, fromPreferences)
super.emit(channel, body, callback, evt)
}
}

const emitter = new RequestEmitter()

ipcMain.on('request', (evt, messageId, channel, body, fromPreferences) => {
emitter.emit(channel, messageId, body, evt, fromPreferences)
ipcMain.on('request', (evt, messageId, channel, body) => {
emitter.emit(channel, messageId, body, evt)
})

module.exports = emitter
1 change: 1 addition & 0 deletions desktop/src/handlers/preferenceHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PreferenceHandler {
return {
[CATEGORIES.GENERAL]: {
[PREFERENCES[CATEGORIES.GENERAL].ANDROID_HOME]: path.join(`/Users/${process.env['USER']}`, '/Library/Android/sdk'),
[PREFERENCES[CATEGORIES.GENERAL].GENYMOTION_APP]: path.join('/Applications', 'Genymotion.app'),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/handlers/windowHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class WindowHandler {
}

openPathChooserDialog(payload, respond) {
if (!payload.dialogProperty) payload.dialogProperty = 'openDirectory'
if (!payload.propertyType) payload.propertyType = 'openDirectory'
var selectedPaths = dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
title: payload.title || 'Select Path',
properties: [payload.dialogProperty],
properties: [payload.propertyType],
filter: [
{ name: 'All Files', extensions: ['*'] }
]
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/process/taskLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ process.on('exit', () => {
const injectOptionsFromPreferences = (options) => {
const preferences = preferenceHandler.getPreferences()
const androidHome = preferences[CATEGORIES.GENERAL][PREFERENCES.GENERAL.ANDROID_HOME]
const genymotionApp = preferences[CATEGORIES.GENERAL][PREFERENCES.GENERAL.GENYMOTION_APP]
if (androidHome == '') {
Logger.info('Path to Android SDK is not set, android functionality may be broken as a result')
return //just not worth it
}
options.env.ANDROID_HOME = androidHome
options.env.GENYMOTION_APP = genymotionApp
options.env.PATH = `${options.env.PATH}:${path.join(androidHome, 'tools')}:${path.join(androidHome, 'platform-tools')}`
if (preferences[CATEGORIES.GENERAL][PREFERENCES.GENERAL.USE_GENYMOTION]) {
options.env.USE_GENYMOTION = preferences[CATEGORIES.GENERAL][PREFERENCES.GENERAL.USE_GENYMOTION]
Expand Down
4 changes: 4 additions & 0 deletions shared/src/constants/PreferencesConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const CATEGORIES = _.mapKeys([
export const PREFERENCES = {
[CATEGORIES.GENERAL]: _.mapKeys([
'ANDROID_HOME',
'GENYMOTION_APP',
'USE_GENYMOTION',
]),
[CATEGORIES.SAVING]: _.mapKeys([
Expand All @@ -50,6 +51,9 @@ export const METADATA = {
[PREFERENCES[CATEGORIES.GENERAL].ANDROID_HOME]: {
defaultValue: '',
},
[PREFERENCES[CATEGORIES.GENERAL].GENYMOTION_APP]: {
defaultValue: '',
},
[PREFERENCES[CATEGORIES.GENERAL].USE_GENYMOTION]: {
defaultValue: false,
},
Expand Down
4 changes: 1 addition & 3 deletions web/src/scripts/actions/preferencesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const {

import request from '../ipc/Request'

const PREFERENCE_WINDOW_REQUEST = true

export const SET_PREFERENCE = 'SET_PREFERENCE'
export const setPreference = (categoryKey, key, value) => {
return {
Expand Down Expand Up @@ -62,7 +60,7 @@ export const mergeSystemPreferences = (preferences) => {
export const setSystemLocationPreference = (categoryKey, key, propertyType = 'openDirectory', title = 'Select Location') => {
return function (dispatch) {
return request(
{ type: OPEN_PATH_CHOOSER_DIALOG, propertyType, title, }, PREFERENCE_WINDOW_REQUEST
{ type: OPEN_PATH_CHOOSER_DIALOG, propertyType, title, }
).then((resp) => {
dispatch({
type: SET_PREFERENCE,
Expand Down
77 changes: 45 additions & 32 deletions web/src/scripts/components/menu/SimulatorMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from 'lodash'

const emptySimulatorMenuStyle = {
width: 300,
height: 280,
// height: 280,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
Expand All @@ -30,10 +30,10 @@ const mapSimulatorListToMenuOptions = (options, platform, onClick) => {

const renderError = (messageList) => {
const children = []
_.forEach(messageList, (message) => {
_.forEach(messageList, (message, i) => {
children.push(message)
children.push(<br />)
children.push(<br />)
children.push(<br key={`${i}`}/>)
children.push(<br key={`${i}b`}/>)
})

return (
Expand Down Expand Up @@ -70,39 +70,52 @@ const IOSMenu = ({ display, onClick }) => {
])
}

const AndroidMenu = ({ display, onClick, onToggleEmulationOption, activeEmulationOption }) => {
if (display.error) {
return renderError(display.message)
const AndroidMenuList = ({ errorMessage, androidLists }) => {
if (errorMessage != null) {
return renderError(errorMessage)
} else {
return (
<TwoColumnMenu
column1={androidLists[0]}
column2={androidLists[1]}
/>
)
}
}

const AndroidMenu = ({ display, onClick, onToggleEmulationOption, activeEmulationOption }) => {
let errorMessage = display.error ? display.message : null

const options = mapSimulatorListToMenuOptions(display.simList, 'android', onClick)
let androidLists = []
if (options.length > 0) {
const androidCol1 = options.splice(0, Math.ceil(options.length / 2))
const androidCol2 = options

return (
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}>
<ToggleTab
buttonWidth={90}
onClick={onToggleEmulationOption}
options={['AVD', 'Genymotion']}
active={activeEmulationOption} />
<div style={{marginTop: 10}} />
<TwoColumnMenu
column1={androidCol1}
column2={androidCol2}
/>
</div>
)
androidLists.push(options.splice(0, Math.ceil(options.length / 2)))
androidLists.push(options)
} else if (!display.error) {
errorMessage = [
'No simulators available.',
'Please install Android Studio and set your path to the Android SDK in preferences (cmd + ,)'
]
}

return renderError([
'No simulators available.',
'Please install Android Studio and set your path to the Android SDK in preferences (cmd + ,)'
])

return (
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}>
<ToggleTab
buttonWidth={90}
onClick={onToggleEmulationOption}
options={['AVD', 'Genymotion']}
active={activeEmulationOption} />
<div style={{marginTop: 10}} />
<AndroidMenuList
errorMessage={errorMessage}
androidLists={androidLists}/>
</div>
)
}

class SimulatorMenu extends Component {
Expand Down
2 changes: 1 addition & 1 deletion web/src/scripts/components/menu/TwoColumnMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const style = {
flexDirection: 'row',
alignItems: 'stretch',
display: 'flex',
width: 280,
width: 300,
}

const listStyle = {
Expand Down
1 change: 1 addition & 0 deletions web/src/scripts/components/pages/PreferencesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PreferencesPage extends Component {
onPreferenceChange={this.props.onPreferenceChange.bind(null, CATEGORIES.GENERAL)}
setSystemLocationPreference={this.props.setSystemLocationPreference.bind(null, CATEGORIES.GENERAL)}
androidHome={this.props.general[PREFERENCES.GENERAL.ANDROID_HOME]}
pathToGenymotionApp={this.props.general[PREFERENCES.GENERAL.GENYMOTION_APP]}
useGenymotion={this.props.general[PREFERENCES.GENERAL.USE_GENYMOTION]} />
)
case 1:
Expand Down
10 changes: 9 additions & 1 deletion web/src/scripts/components/preferences/GeneralPreferences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const style = {
const LABEL_WIDTH = 140
const INSET_LEVEL = 15

export default ({onPreferenceChange, setSystemLocationPreference, androidHome, useGenymotion}) => {
export default ({onPreferenceChange, setSystemLocationPreference, androidHome, pathToGenymotionApp, useGenymotion}) => {
return (
<div style={style}>
<FormRow
Expand All @@ -46,6 +46,14 @@ export default ({onPreferenceChange, setSystemLocationPreference, androidHome, u
onSelectFile={setSystemLocationPreference.bind(null, PREFERENCES.GENERAL.ANDROID_HOME, 'openDirectory', 'Choose Android SDK Location')}
placeholder={METADATA[CATEGORIES.GENERAL][PREFERENCES[CATEGORIES.GENERAL].ANDROID_HOME].defaultValue} />
</FormRow>
<FormRow
label={'Genymotion Install Location'}
labelWidth={LABEL_WIDTH}>
<FileSelectorInput
value={pathToGenymotionApp}
onSelectFile={setSystemLocationPreference.bind(null, PREFERENCES.GENERAL.GENYMOTION_APP, 'openFile', 'Choose Genymotion Install Location')}
placeholder={METADATA[CATEGORIES.GENERAL][PREFERENCES[CATEGORIES.GENERAL].GENYMOTION_APP].defaultValue} />
</FormRow>
</div>
)
}
Loading