Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Maui.Core;
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permissions and PermissionStatus are used in this file, but there is no using Microsoft.Maui.ApplicationModel; (or fully-qualified references). Unless there’s a project-wide global using (none found in this project), this will not compile on Windows. Add the appropriate using or fully qualify the types.

Suggested change
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Core;
using Microsoft.Maui.ApplicationModel;

Copilot uses AI. Check for mistakes.
using Windows.Devices.Enumeration;
using Windows.Media;
using Windows.Media.Capture;

namespace CommunityToolkit.Maui.Extensions;
Expand All @@ -13,20 +14,44 @@ public static async Task UpdateAvailability(this ICameraView cameraView, Cancell
cameraView.IsAvailable = videoCaptureDevices.Count > 0;
}

public static Task InitializeCameraForCameraView(this MediaCapture mediaCapture, string deviceId, CancellationToken token)
public static async Task InitializeCameraForCameraView(this MediaCapture mediaCapture, string deviceId, CancellationToken token)
{
try
{
return mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
var settings = new MediaCaptureInitializationSettings
{
VideoDeviceId = deviceId,
PhotoCaptureSource = PhotoCaptureSource.Auto
}).AsTask(token);
};

PermissionStatus microphonePermissionStatus = PermissionStatus.Unknown;
var isMicrophoneCapable = Permissions.IsCapabilityDeclared("microphone");

if (isMicrophoneCapable)
{
microphonePermissionStatus = await Permissions.CheckStatusAsync<Permissions.Microphone>();
}

if (!isMicrophoneCapable || microphonePermissionStatus != PermissionStatus.Granted)
{
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
settings.MediaCategory = MediaCategory.Media;
settings.AudioProcessing = AudioProcessing.Default;
}

var cameraPermissionStatus = await Permissions.CheckStatusAsync<Permissions.Camera>();
if (cameraPermissionStatus == PermissionStatus.Granted)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed all permission checks from the library. It is now up to developers to request permission they need and when they need, with the way to use their own UI for user permissions.

Copy link
Copy Markdown
Author

@AopBK AopBK Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification.
In my PR, the CameraViewExtensions.Windows.cs only checks the permission status, but does not request or manage permissions. The actual permission requests are handled in the CameraViewPage, as expected.
@VladislavAntonyuk ,could you please advise on how to best implement this in line with the library’s current design?
For example, should I pass a parameter from the manager, or is there another approach you recommend?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VladislavAntonyuk How can we proceed? Can you check my comment

{
await mediaCapture.InitializeAsync(settings).AsTask(token);
}
else
{
throw new CameraException("Camera permission is not granted.");
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new CameraException message is less actionable than other platform messages (e.g., iOS includes guidance to enable permissions in settings). Consider expanding this message to tell Windows users where to enable camera access (e.g., Windows Privacy settings / app permissions), or align it with the existing wording used elsewhere in the camera implementation.

Suggested change
throw new CameraException("Camera permission is not granted.");
throw new CameraException("Camera permission is not granted. To enable camera access, open Windows Settings > Privacy & security > Camera and allow camera access for this app.");

Copilot uses AI. Check for mistakes.
}
}
catch (System.Runtime.InteropServices.COMException)
{
// Camera already initialized
return Task.CompletedTask;
}
}
}
Loading