Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Rework permissions check for cam/mic

Richie McIlroy0315f5f80f21
diff --git a/apps/desktop/src/routes/permissions.tsx b/apps/desktop/src/routes/permissions.tsx
index 3e262e90b..127fa3ea5 100644
--- a/apps/desktop/src/routes/permissions.tsx
+++ b/apps/desktop/src/routes/permissions.tsx
@@ -27,26 +27,41 @@ export default function () {
const c = check.latest;
if (c?.os === "macOS") {
const hasScreenRecording = c?.screenRecording;
- let hasCamera = c?.camera;
- let hasMicrophone = c?.microphone;
-
- if (!hasCamera || !hasMicrophone) {
- try {
- const devices = await navigator.mediaDevices.enumerateDevices();
- hasCamera = devices.some((device) => device.kind === "videoinput");
- hasMicrophone = devices.some(
- (device) => device.kind === "audioinput"
- );
- } catch (error) {
- console.error("Error enumerating devices:", error);
- }
- }
+ const hasCamera = c?.camera || (await checkCameraPermission());
+ const hasMicrophone =
+ c?.microphone || (await checkMicrophonePermission());
return hasScreenRecording && hasCamera && hasMicrophone;
}
return false;
};
+ const checkCameraPermission = async () => {
+ try {
+ const cameraStream = await navigator.mediaDevices.getUserMedia({
+ video: true,
+ });
+ cameraStream.getTracks().forEach((track) => track.stop());
+ return true;
+ } catch (error) {
+ console.error("Error requesting camera permission:", error);
+ return false;
+ }
+ };
+
+ const checkMicrophonePermission = async () => {
+ try {
+ const microphoneStream = await navigator.mediaDevices.getUserMedia({
+ audio: true,
+ });
+ microphoneStream.getTracks().forEach((track) => track.stop());
+ return true;
+ } catch (error) {
+ console.error("Error requesting microphone permission:", error);
+ return false;
+ }
+ };
+
createEffect(async () => {
if (await permissionsGranted()) {
commands.openMainWindow();