mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-07 12:26:41 +02:00
30 lines
680 B
Svelte
30 lines
680 B
Svelte
<script>
|
|
import {
|
|
checkPermissions,
|
|
requestPermissions,
|
|
getCurrentPosition
|
|
} from '@tauri-apps/plugin-geolocation'
|
|
|
|
export let onMessage
|
|
|
|
async function getPosition() {
|
|
let permissions = await checkPermissions()
|
|
if (
|
|
permissions.location === 'prompt' ||
|
|
permissions.location === 'prompt-with-rationale'
|
|
) {
|
|
permissions = await requestPermissions(['location'])
|
|
}
|
|
|
|
if (permissions.location === 'granted') {
|
|
getCurrentPosition().then(onMessage).catch(onMessage)
|
|
} else {
|
|
onMessage('permission denied')
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<button class="btn" id="cli-matches" on:click={getPosition}>
|
|
Get Position
|
|
</button>
|