Skip to content

Commit

Permalink
fix(rn): start daemon
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Nov 6, 2018
1 parent 7bed1fb commit 64bc2d6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
Expand Up @@ -32,30 +32,28 @@ export default class List extends PureComponent {
this.setState({ restartDaemon: true }, async () => {
try {
await CoreModule.restart()
console.log(await CoreModule.getPort())
this.props.navigation.setParams({
restartDaemon: false,
})
this.setState({ restartDaemon: false })
} catch (err) {
console.error(err)
}
this.props.navigation.setParams({
restartDaemon: false,
})
this.setState({ restartDaemon: false })
})
}

panic = async () => {
this.props.navigation.setParams({ panic: true })
this.setState({ panic: true }, async () => {
try {
queries.Panic.fetch()
await CoreModule.getPort()
this.props.navigation.setParams({
panic: false,
})
this.setState({ panic: false })
await queries.Panic.fetch()
} catch (err) {
console.error(err)
}
this.props.navigation.setParams({
panic: false,
})
this.setState({ panic: false })
})
}

Expand Down
36 changes: 15 additions & 21 deletions client/react-native/common/relay/environment.js
Expand Up @@ -45,18 +45,9 @@ let getIP = () =>
if (Platform.OS === 'web') {
return resolve(window.location.hostname)
}

if (Platform.OS === 'ios') {
return resolve('127.0.0.1')
}

if (Platform.OS === 'android') {
return resolve('10.0.2.2')
}
return resolve('127.0.0.1')
})

const getPort = () => CoreModule.getPort()

const setupSubscription = async (config, variables, cacheConfig, observer) => {
try {
const query = config.text
Expand Down Expand Up @@ -121,19 +112,22 @@ const perfLogger = (msg, req, res) => {
}

const _fetchQuery = async req => {
const query = `http://${await getIP()}:${await getPort()}/query`
try {
const query = `http://${await getIP()}:${await CoreModule.getPort()}/query`

// eslint-disable-next-line
if (__DEV__) {
console.log(
'%c RELAY %c relay query: %s',
logStyle.relayOK,
logStyle.title,
query
)
// eslint-disable-next-line
if (__DEV__) {
console.log(
'%c RELAY %c relay query: %s',
logStyle.relayOK,
logStyle.title,
query
)
}
return query
} catch (err) {
console.warn(err)
}

return query
}

// @TODO: Do something better to cache this
Expand Down
6 changes: 4 additions & 2 deletions client/react-native/gomobile/core/core.go
Expand Up @@ -38,8 +38,10 @@ func GetPort() (int, error) {

defer panicHandler()

waitDaemon()
a, _ := account.Get(accountName)
a, err := account.Get(accountName)
if err != nil {
return 0, err
}
return strconv.Atoi(strings.Split(a.GQLBind, ":")[1])
}

Expand Down

0 comments on commit 64bc2d6

Please sign in to comment.