Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Reorder camera preview window logic and improve error handling

Richie McIlroyd56ff6affa2c
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index e35510407..538161de9 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -444,18 +444,18 @@ async fn set_camera_input(
.map_err(|e| e.to_string())?;
}
Some(id) => {
- ShowCapWindow::Camera
- .show(&app_handle)
- .await
- .map_err(|err| error!("Failed to show camera preview window: {err}"))
- .ok();
-
camera_feed
.ask(feeds::camera::SetInput { id: id.clone() })
.await
.map_err(|e| e.to_string())?
.await
.map_err(|e| e.to_string())?;
+
+ ShowCapWindow::Camera
+ .show(&app_handle)
+ .await
+ .map_err(|err| error!("Failed to show camera preview window: {err}"))
+ .ok();
}
}
diff --git a/apps/desktop/src/utils/queries.ts b/apps/desktop/src/utils/queries.ts
index a70c79a2b..22096e20a 100644
--- a/apps/desktop/src/utils/queries.ts
+++ b/apps/desktop/src/utils/queries.ts
@@ -198,18 +198,26 @@ export function createCameraMutation() {
const rawMutate = async (model: DeviceOrModelID | null) => {
const before = rawOptions.cameraID ? { ...rawOptions.cameraID } : null;
setOptions("cameraID", reconcile(model));
- if (model) {
- await commands.showWindow("Camera");
- getCurrentWindow().setFocus();
- }
-
await commands.setCameraInput(model).catch(async (e) => {
+ const message =
+ typeof e === "string" ? e : e instanceof Error ? e.message : String(e);
+
+ if (message.includes("DeviceNotFound")) {
+ setOptions("cameraID", null);
+ console.warn("Selected camera is unavailable.");
+ return;
+ }
+
if (JSON.stringify(before) === JSON.stringify(model) || !before) {
setOptions("cameraID", null);
} else setOptions("cameraID", reconcile(before));
throw e;
});
+
+ if (model) {
+ getCurrentWindow().setFocus();
+ }
};
const setCameraInput = useMutation(() => ({