Skip to content

Commit

Permalink
fix(usePermission): state setting (#4167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga authored Aug 24, 2024
1 parent ea87ac5 commit 2aaa1c2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/core/usePermission/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ export function usePermission(
: permissionDesc as PermissionDescriptor
const state = shallowRef<PermissionState | undefined>()

const onChange = () => {
if (permissionStatus.value)
state.value = permissionStatus.value.state
const update = () => {
state.value = permissionStatus.value?.state ?? 'prompt'
}

useEventListener(permissionStatus, 'change', onChange)
useEventListener(permissionStatus, 'change', update)

const query = createSingletonPromise(async () => {
if (!isSupported.value)
Expand All @@ -88,10 +87,12 @@ export function usePermission(
if (!permissionStatus.value) {
try {
permissionStatus.value = await navigator!.permissions.query(desc)
onChange()
}
catch {
state.value = 'prompt'
permissionStatus.value = undefined
}
finally {
update()
}
}

Expand Down

0 comments on commit 2aaa1c2

Please sign in to comment.