From 1ef1c1b0b11c979e4bdfbc191478507834a6c260 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:14:40 +0000 Subject: [PATCH] fix: Re-add regular permissions check (1sec) --- .../src/components/windows/Permissions.tsx | 62 +++++++++---------- apps/desktop/src/utils/auth/index.ts | 2 +- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/apps/desktop/src/components/windows/Permissions.tsx b/apps/desktop/src/components/windows/Permissions.tsx index dc62d15b..004722d7 100644 --- a/apps/desktop/src/components/windows/Permissions.tsx +++ b/apps/desktop/src/components/windows/Permissions.tsx @@ -29,46 +29,42 @@ export const Permissions = () => { }; const checkCameraAccess = async () => { - if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { - try { - const stream = await navigator.mediaDevices.getUserMedia({ - video: true, - }); - await savePermissions("camera", true); - setPermissions((prev) => ({ - ...prev, - camera: true, - })); - stream.getTracks().forEach((track) => track.stop()); - } catch (error) { - console.log("Camera access denied"); - } + try { + const stream = await navigator.mediaDevices.getUserMedia({ video: true }); + // Assuming access is granted if the above line doesn't throw an error + await savePermissions("camera", true); + setPermissions((prev) => ({ + ...prev, + camera: true, + })); + // Stop using the camera after checking access + stream.getTracks().forEach((track) => track.stop()); + } catch (error) { + console.log("Camera access denied"); } }; const checkMicrophoneAccess = async () => { - if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { - try { - const stream = await navigator.mediaDevices.getUserMedia({ - audio: true, - }); - await savePermissions("microphone", true); - setPermissions((prev) => ({ - ...prev, - microphone: true, - })); - stream.getTracks().forEach((track) => track.stop()); - } catch (error) { - console.log("Microphone access denied"); - } + try { + const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); + // Assuming access is granted if the above line doesn't throw an error + await savePermissions("microphone", true); + setPermissions((prev) => ({ + ...prev, + microphone: true, + })); + // Stop using the microphone after checking access + stream.getTracks().forEach((track) => track.stop()); + } catch (error) { + console.log("Microphone access denied"); } }; useEffect(() => { const checkPermissions = async () => { - // if (!permissions.screen) { - // await checkScreenCapture(); - // } + if (!permissions.screen) { + checkScreenCapture(); + } if (!permissions.camera) { await checkCameraAccess(); } @@ -77,7 +73,9 @@ export const Permissions = () => { } }; - checkPermissions(); + const checkPermissionInterval = setInterval(checkPermissions, 1000); + + return () => clearInterval(checkPermissionInterval); }, [permissions]); const handlePermissionOpened = (permission: string) => { diff --git a/apps/desktop/src/utils/auth/index.ts b/apps/desktop/src/utils/auth/index.ts index 25fa73f4..43422602 100644 --- a/apps/desktop/src/utils/auth/index.ts +++ b/apps/desktop/src/utils/auth/index.ts @@ -10,7 +10,7 @@ const dynamicImports = { export const openSignIn = async (port: string) => { if (typeof window !== "undefined" && typeof navigator !== "undefined") { - const { open } = await dynamicImports.shell(); // Correctly accessing the shell module + const { open } = await dynamicImports.shell(); await open( `${process.env.NEXT_PUBLIC_URL}/api/desktop/session/request?port=${port}` );