-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add re request perm logic #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
97448aa
feat: add re request perm logic
sosweetham 065d2b9
fix: app settings page
sosweetham 4c102b9
fix: segregate common logic and add to onboarding
sosweetham 3c9c7a2
fix: format
sosweetham d2e2f52
Update infrastructure/eid-wallet/src-tauri/tauri.conf.json
coodos 66170bb
fix: sort imports
sosweetham 2d11370
Merge branch 'fix(eid-w)/reprompt-for-missing-camera-perms' of ssh.gi…
sosweetham 5297a84
fix: coderabbit suggestions
sosweetham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
infrastructure/eid-wallet/src/lib/ui/CameraPermissionDialog/CameraPermissionDialog.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <script lang="ts"> | ||
| import { ButtonAction, Drawer } from "$lib/ui"; | ||
|
|
||
| interface CameraPermissionDialogProps { | ||
| isOpen: boolean; | ||
| onOpenSettings: () => void; | ||
| onGoBack?: () => void; | ||
| onOpenChange?: (value: boolean) => void; | ||
| title?: string; | ||
| description?: string; | ||
| dismissible?: boolean; | ||
| } | ||
|
|
||
| let { | ||
| isOpen = $bindable(false), | ||
| onOpenSettings, | ||
| onGoBack, | ||
| onOpenChange, | ||
| title = "Camera Access Required", | ||
| description = "To continue, please grant camera permission in your device settings.", | ||
| dismissible = false, | ||
| }: CameraPermissionDialogProps = $props(); | ||
|
|
||
| function handleSwipe(value: boolean | undefined) { | ||
| // Only allow swipe to close when dismissible is true and onOpenChange is provided | ||
| if (!dismissible || !onOpenChange) { | ||
| return; | ||
| } | ||
| if (value) { | ||
| isOpen = false; | ||
| onOpenChange(false); | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <Drawer | ||
| isPaneOpen={isOpen} | ||
| handleSwipe={dismissible && onOpenChange ? handleSwipe : undefined} | ||
| dismissible={dismissible} | ||
| > | ||
| <div class="flex flex-col items-center text-center pb-4"> | ||
| <!-- Camera icon with slash --> | ||
| <svg | ||
| class="mx-auto mb-6" | ||
| width="80" | ||
| height="80" | ||
| viewBox="0 0 24 24" | ||
| fill="none" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M15.75 10.5l4.72-4.72a.75.75 0 011.28.53v11.38a.75.75 0 01-1.28.53l-4.72-4.72M4.5 18.75h9a2.25 2.25 0 002.25-2.25v-9a2.25 2.25 0 00-2.25-2.25h-9A2.25 2.25 0 002.25 7.5v9a2.25 2.25 0 002.25 2.25z" | ||
| stroke="currentColor" | ||
| stroke-width="1.5" | ||
| stroke-linecap="round" | ||
| stroke-linejoin="round" | ||
| class="text-gray-700" | ||
| /> | ||
| <path | ||
| d="M3 3l18 18" | ||
| stroke="currentColor" | ||
| stroke-width="1.5" | ||
| stroke-linecap="round" | ||
| class="text-gray-700" | ||
| /> | ||
| </svg> | ||
|
|
||
| <h4 class="font-semibold text-xl mb-3 text-gray-900"> | ||
| {title} | ||
| </h4> | ||
|
|
||
| <p class="text-gray-600 text-sm mb-6 max-w-xs"> | ||
| {description} | ||
| </p> | ||
|
|
||
| <div class="flex flex-col gap-3 w-full"> | ||
| <ButtonAction | ||
| variant="solid" | ||
| callback={onOpenSettings} | ||
| class="w-full" | ||
| > | ||
| Open Settings | ||
| </ButtonAction> | ||
|
|
||
| {#if onGoBack} | ||
| <ButtonAction | ||
| variant="soft" | ||
| callback={onGoBack} | ||
| class="w-full" | ||
| > | ||
| Go Back | ||
| </ButtonAction> | ||
| {:else} | ||
| <!-- Spacer to maintain consistent bottom spacing --> | ||
| <div class="h-10"></div> | ||
| {/if} | ||
| </div> | ||
| </div> | ||
| </Drawer> | ||
1 change: 1 addition & 0 deletions
1
infrastructure/eid-wallet/src/lib/ui/CameraPermissionDialog/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as CameraPermissionDialog } from "./CameraPermissionDialog.svelte"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
infrastructure/eid-wallet/src/lib/utils/cameraPermission.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { | ||
| type PermissionState, | ||
| checkPermissions, | ||
| openAppSettings, | ||
| requestPermissions, | ||
| } from "@tauri-apps/plugin-barcode-scanner"; | ||
| import { type Writable, writable } from "svelte/store"; | ||
|
|
||
| export interface CameraPermissionState { | ||
| status: PermissionState | null; | ||
| isDenied: boolean; | ||
| isGranted: boolean; | ||
| isChecking: boolean; | ||
| } | ||
|
|
||
| export interface CameraPermissionResult { | ||
| permissionState: Writable<CameraPermissionState>; | ||
| checkAndRequestPermission: () => Promise<boolean>; | ||
| retryPermission: () => Promise<boolean>; | ||
| openSettings: () => Promise<void>; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a camera permission manager that handles checking, requesting, | ||
| * and managing camera permissions using Tauri's barcode-scanner plugin. | ||
| * | ||
| * This can be used in both the scan page and onboarding flows where camera | ||
| * access is required. | ||
| */ | ||
| export function createCameraPermissionManager(): CameraPermissionResult { | ||
| const permissionState = writable<CameraPermissionState>({ | ||
| status: null, | ||
| isDenied: false, | ||
| isGranted: false, | ||
| isChecking: false, | ||
| }); | ||
|
|
||
| /** | ||
| * Check current permission status and request if needed. | ||
| * Returns true if permission is granted, false otherwise. | ||
| */ | ||
| async function checkAndRequestPermission(): Promise<boolean> { | ||
| permissionState.update((state) => ({ | ||
| ...state, | ||
| isChecking: true, | ||
| isDenied: false, | ||
| })); | ||
|
|
||
| let permissions: PermissionState | null = null; | ||
|
|
||
| try { | ||
| permissions = await checkPermissions(); | ||
| } catch { | ||
| permissions = null; | ||
| } | ||
|
|
||
| // If permission is prompt or denied, request it | ||
| if (permissions === "prompt" || permissions === "denied") { | ||
| try { | ||
| permissions = await requestPermissions(); | ||
| } catch { | ||
| permissions = null; | ||
| } | ||
| } | ||
|
|
||
| const isGranted = permissions === "granted"; | ||
| const isDenied = permissions === "denied"; | ||
|
|
||
| permissionState.set({ | ||
| status: permissions, | ||
| isDenied, | ||
| isGranted, | ||
| isChecking: false, | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!isGranted) { | ||
| console.warn("Camera permission not granted:", permissions); | ||
| } | ||
|
|
||
| return isGranted; | ||
| } | ||
|
|
||
| /** | ||
| * Retry permission request. If permission was previously denied (not just prompt), | ||
| * this will open app settings since the OS won't show the dialog again. | ||
| */ | ||
| async function retryPermission(): Promise<boolean> { | ||
| let permissions: PermissionState | null = null; | ||
|
|
||
| try { | ||
| permissions = await checkPermissions(); | ||
| } catch { | ||
| permissions = null; | ||
| } | ||
|
|
||
| // If permission is denied (not just prompt), open app settings | ||
| // because the OS won't show the permission dialog again | ||
| if (permissions === "denied") { | ||
| await openAppSettings(); | ||
| return false; | ||
| } | ||
|
|
||
| // Otherwise, attempt to request permissions again | ||
| return checkAndRequestPermission(); | ||
| } | ||
|
|
||
| /** | ||
| * Open the app's settings page in system settings. | ||
| */ | ||
| async function openSettings(): Promise<void> { | ||
| await openAppSettings(); | ||
| } | ||
|
|
||
| return { | ||
| permissionState, | ||
| checkAndRequestPermission, | ||
| retryPermission, | ||
| openSettings, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.