Skip to content

Commit 312dbd0

Browse files
authored
Fix camera and mic permissions (#862)
* fix permission * remove logs * cleanup
1 parent 072995e commit 312dbd0

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

apps/desktop/src-tauri/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ fn open_external_link(app: tauri::AppHandle, url: String) -> Result<(), String>
16781678

16791679
#[tauri::command]
16801680
#[specta::specta]
1681-
async fn reset_camera_permissions(_app: AppHandle) -> Result<(), ()> {
1681+
async fn reset_camera_permissions(_app: AppHandle) -> Result<(), String> {
16821682
#[cfg(target_os = "macos")]
16831683
{
16841684
#[cfg(debug_assertions)]
@@ -1692,7 +1692,7 @@ async fn reset_camera_permissions(_app: AppHandle) -> Result<(), ()> {
16921692
.arg("Camera")
16931693
.arg(bundle_id)
16941694
.output()
1695-
.expect("Failed to reset camera permissions");
1695+
.map_err(|_| "Failed to reset camera permissions".to_string())?;
16961696
}
16971697

16981698
Ok(())

apps/desktop/src-tauri/src/permissions.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,25 @@ pub fn open_permission_settings(permission: OSPermission) {
6161
pub async fn request_permission(permission: OSPermission) {
6262
#[cfg(target_os = "macos")]
6363
{
64+
use futures::executor::block_on;
65+
6466
match permission {
6567
OSPermission::ScreenRecording => {
6668
scap::request_permission();
6769
}
6870
OSPermission::Camera => {
69-
av::CaptureDevice::request_access_for_media_type(av::MediaType::video());
71+
std::thread::spawn(|| {
72+
let _ = block_on(av::CaptureDevice::request_access_for_media_type(
73+
av::MediaType::video(),
74+
));
75+
});
7076
}
7177
OSPermission::Microphone => {
72-
av::CaptureDevice::request_access_for_media_type(av::MediaType::audio());
78+
std::thread::spawn(|| {
79+
let _ = block_on(av::CaptureDevice::request_access_for_media_type(
80+
av::MediaType::audio(),
81+
));
82+
});
7383
}
7484
OSPermission::Accessibility => request_accessibility_permission(),
7585
}

apps/desktop/src/routes/(window-chrome)/(main).tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ function Page() {
422422
options={cameras}
423423
value={options.cameraID() ?? null}
424424
onChange={(v) => {
425-
console.log({ v });
426425
if (!v) setCamera.mutate(null);
427426
else if (v.model_id) setCamera.mutate({ ModelID: v.model_id });
428427
else setCamera.mutate({ DeviceID: v.device_id });
@@ -574,7 +573,6 @@ function AreaSelectButton(props: {
574573
}
575574

576575
const { screen } = props;
577-
console.log({ screen });
578576
if (!screen) return;
579577

580578
trackEvent("crop_area_enabled", {
@@ -719,6 +717,11 @@ function CameraSelect(props: {
719717
disabled={!!currentRecording.data || props.disabled}
720718
class="flex flex-row items-center h-[2rem] px-[0.375rem] gap-[0.375rem] border rounded-lg border-gray-3 w-full disabled:text-gray-11 transition-colors KSelect"
721719
onClick={() => {
720+
if (!permissionGranted()) {
721+
requestPermission("camera");
722+
return;
723+
}
724+
722725
Promise.all([
723726
CheckMenuItem.new({
724727
text: NO_CAMERA,
@@ -820,6 +823,11 @@ function MicrophoneSelect(props: {
820823
disabled={!!currentRecording.data || props.disabled}
821824
class="relative flex flex-row items-center h-[2rem] px-[0.375rem] gap-[0.375rem] border rounded-lg border-gray-3 w-full disabled:text-gray-11 transition-colors KSelect overflow-hidden z-10"
822825
onClick={() => {
826+
if (!permissionGranted()) {
827+
requestPermission("microphone");
828+
return;
829+
}
830+
823831
Promise.all([
824832
CheckMenuItem.new({
825833
text: NO_MICROPHONE,
@@ -930,7 +938,6 @@ function TargetSelect<T extends { id: number; name: string }>(props: {
930938
disabled={props.disabled}
931939
onClick={() => {
932940
if (props.options.length > 1) {
933-
console.log({ options: props.options, value: props.value });
934941
Promise.all(
935942
props.options.map((o) =>
936943
CheckMenuItem.new({
@@ -976,6 +983,7 @@ function TargetSelectInfoPill<T>(props: {
976983
onClick={(e) => {
977984
if (!props.permissionGranted) {
978985
props.requestPermission();
986+
e.stopPropagation();
979987
return;
980988
}
981989

0 commit comments

Comments
 (0)