Skip to content

Commit

Permalink
Merge pull request #2287 from StoDevX/android-lazy-geo
Browse files Browse the repository at this point in the history
Android Wifi Reporting: Use Lazy Geolocation
  • Loading branch information
rye authored Jan 31, 2018
2 parents 1752125 + b97436e commit 2c59877
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 12 additions & 7 deletions source/views/help/wifi-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import deviceInfo from 'react-native-device-info'
import networkInfo from 'react-native-network-info'
import {Platform} from 'react-native'
import pkg from '../../../package.json'

export const getIpAddress = (): Promise<?string> =>
Expand All @@ -14,13 +15,17 @@ export const getIpAddress = (): Promise<?string> =>
})

export const getPosition = (args: any = {}): Promise<Object> =>
new Promise(resolve => {
navigator.geolocation.getCurrentPosition(resolve, () => resolve({}), {
...args,
enableHighAccuracy: true,
maximumAge: 1000 /*ms*/,
timeout: 5000 /*ms*/,
})
new Promise((resolve, reject) => {
if (Platform.OS === 'android') {
navigator.geolocation.getCurrentPosition(resolve, reject)
} else {
navigator.geolocation.getCurrentPosition(resolve, reject, {
...args,
enableHighAccuracy: true,
maximumAge: 1000 /* ms */,
timeout: 15000 /* ms */,
})
}
})

export const collectData = async () => ({
Expand Down
9 changes: 8 additions & 1 deletion source/views/help/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Error, ErrorMessage} from './components'
import {getPosition, collectData, reportToServer} from './wifi-tools'
import {styles} from './tool'
import type {ToolOptions} from './types'
import bugsnag from '../../bugsnag'

export const toolName = 'wifi'

Expand Down Expand Up @@ -49,7 +50,13 @@ export class ToolView extends React.Component<Props, State> {
}

this.setState(() => ({status: 'collecting', error: ''}))
const [position, device] = await Promise.all([getPosition(), collectData()])
const [position, device] = await Promise.all([
getPosition().catch(error => {
bugsnag.notify(error)
return null
}),
collectData(),
])
this.setState(() => ({status: 'reporting'}))

try {
Expand Down

0 comments on commit 2c59877

Please sign in to comment.