refactor(geolocation): simplify API, defer permission checks (#1773)

This commit is contained in:
Lucas Fernandes Nogueira
2024-09-16 11:01:13 -03:00
committed by GitHub
parent fd75401aee
commit 60765694f5
28 changed files with 454 additions and 13969 deletions
+23 -8
View File
@@ -87,16 +87,31 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```javascript
import { getCurrentPosition, watchPosition } from '@tauri-apps/plugin-log'
import {
checkPermissions,
requestPermissions,
getCurrentPosition,
watchPosition
} from '@tauri-apps/plugin-log'
const pos = await getCurrentPosition()
let permissions = await checkPermissions()
if (
permissions.location === 'prompt' ||
permissions.location === 'prompt-with-rationale'
) {
permissions = await requestPermissions(['location'])
}
await watchPosition(
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
(pos) => {
console.log(pos)
}
)
if (permissions.location === 'granted') {
const pos = await getCurrentPosition()
await watchPosition(
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
(pos) => {
console.log(pos)
}
)
}
```
## Contributing