Repository navigation
Fix Permission CTD for packaged/unpackaged apps using CameraView - #3157
ne0rrmatrix wants to merge 15 commits into
Conversation
Updated CameraViewPage to grant permissions automatically for unpackaged apps, avoiding unnecessary prompts. Changed CreateStopCameraPreviewCommand to use Command<CancellationToken> for consistency with start command.
|
@VladislavAntonyuk can you take one more pass. I realized i excluded android,ios and mac catalyst. Fixed now. |
Refactored the logic for requesting camera and microphone permissions in OnAppearing. Instead of explicitly checking for Android, iOS, or MacCatalyst, permissions are now requested on all non-Windows platforms or when the app is packaged. This makes the condition more maintainable and future-proof.
|
We found the same issue in the PR #3140 and fixed it in a similar way. Let's see which PR is merged sooner :-) |
|
@ne0rrmatrix could you please rebase |
Changed StopCameraPreviewCommand and its BindableProperty from ICommand to Command<CancellationToken> for consistency with StartCameraPreviewCommand. Updated documentation to reflect the new parameter requirements and usage.
| public static readonly BindableProperty StopCameraPreviewCommandProperty = | ||
| BindableProperty.CreateReadOnly(nameof(StopCameraPreviewCommand), typeof(ICommand), typeof(CameraView), null, BindingMode.OneWayToSource, defaultValueCreator: CreateStopCameraPreviewCommand).BindableProperty; | ||
| BindableProperty.CreateReadOnly(nameof(StopCameraPreviewCommand), typeof(Command<CancellationToken>), typeof(CameraView), null, BindingMode.OneWayToSource, defaultValueCreator: CreateStopCameraPreviewCommand).BindableProperty; |
There was a problem hiding this comment.
Do we want to align this with every other command or do we want to keep this as an ICommand? @VladislavAntonyuk @TheCodeTraveler
There was a problem hiding this comment.
@ne0rrmatrix I don't think any change related to StopCameraPreviewCommand in this PR is needed.
The original issue #3156 has already been fixed in #3167, and the fix was to change StopCameraPreviewCommand from Command<CancellationToken> to ICommand.
The root cause of the issue was that the method CameraView.StopCameraPreview() which the StopCameraPreviewCommand calls internally has a return type void instead of a Task. This means StopCameraPreviewCommand does not need to use a CancelationToken.
| static Command<CancellationToken> CreateStopCameraPreviewCommand(BindableObject bindable) | ||
| { | ||
| var cameraView = (CameraView)bindable; | ||
| return new Command(cameraView.StopCameraPreview); | ||
| return new(token => cameraView.StopCameraPreview()); | ||
| } |
| /// <summary> | ||
| /// Gets the <see cref="ICommand"/> that stops the camera preview. | ||
| /// Gets the <see cref="Command{CancellationToken}"/> that stops the camera preview. | ||
| /// </summary> | ||
| public ICommand StopCameraPreviewCommand => (ICommand)GetValue(StopCameraPreviewCommandProperty); | ||
| /// <remarks> | ||
| /// <see cref="StopCameraPreviewCommand"/> has a <see cref="Type"/> of Command<CancellationToken> which requires a <see cref="CancellationToken"/> as a CommandParameter. See <see cref="Command{CancellationToken}"/> and <see cref="System.Windows.Input.ICommand.Execute(object)"/> for more information on passing a <see cref="CancellationToken"/> into <see cref="Command{T}"/> as a CommandParameter | ||
| /// </remarks> | ||
| public Command<CancellationToken> StopCameraPreviewCommand => (Command<CancellationToken>)GetValue(StopCameraPreviewCommandProperty); | ||
|
|
| { | ||
| var cameraView = (CameraView)bindable; | ||
| return new Command(cameraView.StopCameraPreview); | ||
| return new(token => cameraView.StopCameraPreview()); |
There was a problem hiding this comment.
As mentioned in my previous comment, I believe this change is not necessary as the token added in the lambda function here is not used.
|
@ne0rrmatrix is it still needed? Gerald made similar changes. |
It has been a long while since I looked at this. Looking at the fix it deals specifically with how to handle packaged vs unpackaged and there are classes that are available for packaged that were being used and are no longer being used. So this is stale now. The issue it fixes is no longer present in the toolkit. Or at least mitigated by @jfversluis. I am closing this now. It can be reopened or made fresh if it is needed in the future. |
Description of Change
There is a bug in CameraView in sample app where it requests permission for microphone and camera in an unpackaged app. This will crash the sample app. An unpackaged app does not require permissions for either camera or microphone when not packaged.
This also fixes a bug where the method signature for a
Commandis incorrect which is crashing sample app.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
This is another packaged/unpackaged app issue that is related to permissions. Includes a second bug that needed to be fixed to test and prevent crashes.