Skip to content

Commit

Permalink
fix: Re-add regular permissions check (1sec)
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Mar 19, 2024
1 parent 1b7460b commit 1ef1c1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
62 changes: 30 additions & 32 deletions apps/desktop/src/components/windows/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -77,7 +73,9 @@ export const Permissions = () => {
}
};

checkPermissions();
const checkPermissionInterval = setInterval(checkPermissions, 1000);

return () => clearInterval(checkPermissionInterval);
}, [permissions]);

const handlePermissionOpened = (permission: string) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/utils/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
Expand Down

1 comment on commit 1ef1c1b

@vercel
Copy link

@vercel vercel bot commented on 1ef1c1b Mar 19, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.