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

Function NativeCameraPreviewPage

apps/desktop/src/routes/camera.tsx:226–352  ·  view source on GitHub ↗
(props: {
	issue: Accessor<CameraPreviewIssue | null>;
})

Source from the content-addressed store, hash-verified

224}
225
226function NativeCameraPreviewPage(props: {
227 issue: Accessor<CameraPreviewIssue | null>;
228}) {
229 const isCameraOnlyMode = () => getCameraOnlyMode();
230
231 const [state, setState] = makePersisted(
232 createStore<CameraWindowState>(getDefaultCameraWindowState()),
233 { name: CAMERA_WINDOW_STATE_STORAGE_KEY },
234 );
235
236 const centerCameraOnlyWindow = () => {
237 ignoreMoveFor(1500);
238 void commands.ignoreCameraWindowPosition(1500);
239 void centerCurrentWindow();
240 setTimeout(() => {
241 void centerCurrentWindow();
242 }, 120);
243 };
244
245 onMount(() => {
246 if (isCameraOnlyMode()) {
247 centerCameraOnlyWindow();
248 }
249
250 const handleVisibilityChange = () => {
251 if (!document.hidden) {
252 setTimeout(() => {
253 commands.refreshCameraFeed().catch(() => {});
254 }, 500);
255 }
256 };
257 document.addEventListener("visibilitychange", handleVisibilityChange);
258 onCleanup(() =>
259 document.removeEventListener("visibilitychange", handleVisibilityChange),
260 );
261 });
262
263 createEffect(
264 on(
265 () => isCameraOnlyMode(),
266 (isCameraOnly, wasCameraOnly) => {
267 if (isCameraOnly && !wasCameraOnly) {
268 centerCameraOnlyWindow();
269 }
270 },
271 ),
272 );
273
274 createEffect(() => {
275 let currentSize = state.size as number | string;
276 if (typeof currentSize !== "number" || Number.isNaN(currentSize)) {
277 currentSize =
278 currentSize === "lg" ? CAMERA_PRESET_LARGE : CAMERA_DEFAULT_SIZE;
279 setState("size", currentSize);
280 return;
281 }
282
283 const clampedSize = Math.max(

Callers

nothing calls this directly

Calls 12

createCameraMutationFunction · 0.90
cameraBorderRadiusFunction · 0.90
createStoreFunction · 0.85
isCameraOnlyModeFunction · 0.85
centerCameraOnlyWindowFunction · 0.85
onFunction · 0.85
scaleFunction · 0.85
addEventListenerMethod · 0.80
removeEventListenerMethod · 0.80

Tested by

no test coverage detected