Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): improve camera and microphone permission request flow
Richie McIlroy3fe4ccf04e0b
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 9918b2e0c..42cd1368d 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -3464,8 +3464,6 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {async move {if !permissions.screen_recording.permitted()|| !permissions.accessibility.permitted()- || !permissions.microphone.permitted()- || !permissions.camera.permitted()|| GeneralSettingsStore::get(&app).ok().flatten()diff --git a/apps/desktop/src-tauri/src/permissions.rs b/apps/desktop/src-tauri/src/permissions.rsindex e4cb26a5b..21c913779 100644--- a/apps/desktop/src-tauri/src/permissions.rs+++ b/apps/desktop/src-tauri/src/permissions.rs@@ -64,10 +64,18 @@ pub fn open_permission_settings(_permission: OSPermission) {#[tauri::command]#[specta::specta]-#[instrument]-pub async fn request_permission(_permission: OSPermission) {+#[instrument(skip(app))]+pub async fn request_permission(app: tauri::AppHandle, _permission: OSPermission) {#[cfg(target_os = "macos")]{+ let needs_activation =+ matches!(_permission, OSPermission::Camera | OSPermission::Microphone);++ if needs_activation {+ app.set_activation_policy(tauri::ActivationPolicy::Regular)+ .ok();+ }+match _permission {OSPermission::ScreenRecording => {scap_screencapturekit::request_permission();@@ -110,6 +118,11 @@ pub async fn request_permission(_permission: OSPermission) {}}}++ if needs_activation {+ app.set_activation_policy(tauri::ActivationPolicy::Accessory)+ .ok();+ }}}diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsxindex 2f05e6b66..17ba64db0 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx@@ -21,6 +21,7 @@ export default function TargetSelectInfoPill<T>(props: {}}onClick={(e) => {if (!props.permissionGranted) {+ e.stopPropagation();props.requestPermission();return;}diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/useRequestPermission.ts b/apps/desktop/src/routes/(window-chrome)/new-main/useRequestPermission.tsindex 04aca4ab8..3630e4f2a 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/useRequestPermission.ts+++ b/apps/desktop/src/routes/(window-chrome)/new-main/useRequestPermission.ts@@ -1,4 +1,5 @@import { useQueryClient } from "@tanstack/solid-query";+import { getCurrentWindow } from "@tauri-apps/api/window";import { devicesSnapshot } from "~/utils/devices";import { commands, type OSPermissionStatus } from "~/utils/tauri";@@ -15,12 +16,20 @@ export default function useRequestPermission() {return;}- if (type === "camera") {- await commands.resetCameraPermissions();- } else if (type === "microphone") {- await commands.resetMicrophonePermissions();+ const window = getCurrentWindow();+ await window.setAlwaysOnTop(false);+ try {+ await commands.requestPermission(type);++ const check = await commands.doPermissionsCheck(false);+ const status = type === "camera" ? check.camera : check.microphone;++ if (status !== "granted") {+ await commands.openPermissionSettings(type);+ }+ } finally {+ await window.setAlwaysOnTop(true);}- await commands.requestPermission(type);await queryClient.refetchQueries(devicesSnapshot);} catch (error) {console.error(`Failed to get ${type} permission:`, error);diff --git a/apps/desktop/src/routes/(window-chrome)/setup.tsx b/apps/desktop/src/routes/(window-chrome)/setup.tsxindex 7e612d82f..121735857 100644--- a/apps/desktop/src/routes/(window-chrome)/setup.tsx+++ b/apps/desktop/src/routes/(window-chrome)/setup.tsx@@ -49,6 +49,7 @@ const permissions = [key: "microphone" as const,description: "This permission is required to record audio in your Caps.",requiresManualGrant: false,+ optional: true,},{name: "Camera",@@ -56,6 +57,7 @@ const permissions = [description:"This permission is required to record your camera in your Caps.",requiresManualGrant: false,+ optional: true,},] as const;@@ -182,8 +184,9 @@ export default function () {class="px-12"size="lg"disabled={- permissions.find((p) => !isPermitted(check()?.[p.key])) !==- undefined+ permissions.find(+ (p) => !p.optional && !isPermitted(check()?.[p.key]),+ ) !== undefined}onClick={() => setCurrentStep("mode")}>