Skip to content

Commit 2c59877

Browse files
authored
Merge pull request #2287 from StoDevX/android-lazy-geo
Android Wifi Reporting: Use Lazy Geolocation
2 parents 1752125 + b97436e commit 2c59877

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

source/views/help/wifi-tools.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import deviceInfo from 'react-native-device-info'
44
import networkInfo from 'react-native-network-info'
5+
import {Platform} from 'react-native'
56
import pkg from '../../../package.json'
67

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

1617
export const getPosition = (args: any = {}): Promise<Object> =>
17-
new Promise(resolve => {
18-
navigator.geolocation.getCurrentPosition(resolve, () => resolve({}), {
19-
...args,
20-
enableHighAccuracy: true,
21-
maximumAge: 1000 /*ms*/,
22-
timeout: 5000 /*ms*/,
23-
})
18+
new Promise((resolve, reject) => {
19+
if (Platform.OS === 'android') {
20+
navigator.geolocation.getCurrentPosition(resolve, reject)
21+
} else {
22+
navigator.geolocation.getCurrentPosition(resolve, reject, {
23+
...args,
24+
enableHighAccuracy: true,
25+
maximumAge: 1000 /* ms */,
26+
timeout: 15000 /* ms */,
27+
})
28+
}
2429
})
2530

2631
export const collectData = async () => ({

source/views/help/wifi.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Error, ErrorMessage} from './components'
1111
import {getPosition, collectData, reportToServer} from './wifi-tools'
1212
import {styles} from './tool'
1313
import type {ToolOptions} from './types'
14+
import bugsnag from '../../bugsnag'
1415

1516
export const toolName = 'wifi'
1617

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

5152
this.setState(() => ({status: 'collecting', error: ''}))
52-
const [position, device] = await Promise.all([getPosition(), collectData()])
53+
const [position, device] = await Promise.all([
54+
getPosition().catch(error => {
55+
bugsnag.notify(error)
56+
return null
57+
}),
58+
collectData(),
59+
])
5360
this.setState(() => ({status: 'reporting'}))
5461

5562
try {

0 commit comments

Comments
 (0)