MCPcopy
hub / github.com/CapSoftware/Cap / rawMutate

Function rawMutate

apps/desktop/src/utils/queries.ts:276–312  ·  view source on GitHub ↗
(
		model: DeviceOrModelID | null,
		skipCameraWindow?: boolean,
	)

Source from the content-addressed store, hash-verified

274 const { setOptions, rawOptions } = useRecordingOptions();
275
276 const rawMutate = async (
277 model: DeviceOrModelID | null,
278 skipCameraWindow?: boolean,
279 ) => {
280 const before = rawOptions.cameraID ? { ...rawOptions.cameraID } : null;
281 setOptions("cameraID", reconcile(model));
282 await commands
283 .setCameraInput(model, skipCameraWindow ?? null)
284 .catch(async (e) => {
285 const message =
286 typeof e === "string"
287 ? e
288 : e instanceof Error
289 ? e.message
290 : String(e);
291
292 if (
293 message.includes("DeviceNotFound") ||
294 message.includes("CameraTimeout") ||
295 message.includes("Failed to initialize camera")
296 ) {
297 setOptions("cameraID", null);
298 console.warn("Selected camera is unavailable.");
299 return;
300 }
301
302 if (JSON.stringify(before) === JSON.stringify(model) || !before) {
303 setOptions("cameraID", null);
304 } else setOptions("cameraID", reconcile(before));
305
306 throw e;
307 });
308
309 if (model && !skipCameraWindow) {
310 getCurrentWindow().setFocus();
311 }
312 };
313
314 const setCameraInput = useMutation(() => ({
315 mutationFn: (args: {

Callers 1

createCameraMutationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected