@@ -136,24 +136,44 @@ define_class!(
136136 capture_type: WKMediaCaptureType ,
137137 decision_handler: & Block <dyn Fn ( WKPermissionDecision ) >,
138138 ) {
139- // Determine permission kind based on capture type
140- let permission_kind = match capture_type {
141- WKMediaCaptureType :: Camera => PermissionKind :: Camera ,
142- WKMediaCaptureType :: Microphone => PermissionKind :: Microphone ,
143- WKMediaCaptureType :: CameraAndMicrophone => PermissionKind :: Microphone , // Treat as microphone for now
144- _ => PermissionKind :: Other ,
145- } ;
146-
147139 // Call user's permission handler if set
148140 let decision = if let Some ( handler) = & self . ivars( ) . permission_handler {
149- match handler( permission_kind) {
150- PermissionResponse :: Allow => WKPermissionDecision :: Grant ,
151- PermissionResponse :: Deny => WKPermissionDecision :: Deny ,
152- PermissionResponse :: Default => WKPermissionDecision :: Grant , // Default to grant for backwards compatibility
153- PermissionResponse :: Prompt => WKPermissionDecision :: Prompt ,
141+ match capture_type {
142+ WKMediaCaptureType :: Camera => match handler( PermissionKind :: Camera ) {
143+ PermissionResponse :: Allow => WKPermissionDecision :: Grant ,
144+ PermissionResponse :: Deny => WKPermissionDecision :: Deny ,
145+ PermissionResponse :: Default => WKPermissionDecision :: Grant ,
146+ PermissionResponse :: Prompt => WKPermissionDecision :: Prompt ,
147+ } ,
148+ WKMediaCaptureType :: Microphone => match handler( PermissionKind :: Microphone ) {
149+ PermissionResponse :: Allow => WKPermissionDecision :: Grant ,
150+ PermissionResponse :: Deny => WKPermissionDecision :: Deny ,
151+ PermissionResponse :: Default => WKPermissionDecision :: Grant ,
152+ PermissionResponse :: Prompt => WKPermissionDecision :: Prompt ,
153+ } ,
154+ WKMediaCaptureType :: CameraAndMicrophone => {
155+ let mic_res = handler( PermissionKind :: Microphone ) ;
156+ let cam_res = handler( PermissionKind :: Camera ) ;
157+
158+ match ( mic_res, cam_res) {
159+ ( PermissionResponse :: Allow , PermissionResponse :: Allow ) => WKPermissionDecision :: Grant ,
160+ ( PermissionResponse :: Deny , _) | ( _, PermissionResponse :: Deny ) => {
161+ WKPermissionDecision :: Deny
162+ }
163+ ( PermissionResponse :: Prompt , _) | ( _, PermissionResponse :: Prompt ) => {
164+ WKPermissionDecision :: Prompt
165+ }
166+ _ => WKPermissionDecision :: Grant ,
167+ }
168+ }
169+ _ => match handler( PermissionKind :: Other ) {
170+ PermissionResponse :: Allow => WKPermissionDecision :: Grant ,
171+ PermissionResponse :: Deny => WKPermissionDecision :: Deny ,
172+ PermissionResponse :: Default => WKPermissionDecision :: Grant ,
173+ PermissionResponse :: Prompt => WKPermissionDecision :: Prompt ,
174+ } ,
154175 }
155176 } else {
156- // No handler set, default to grant (backwards compatible behavior)
157177 WKPermissionDecision :: Grant
158178 } ;
159179
0 commit comments