Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(desktop): update camera and microphone selection UI

Richie McIlroy4ff24d849b8a
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/CameraSelect.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/CameraSelect.tsx
index c10ad7967..6ddf328bc 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/CameraSelect.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/CameraSelect.tsx
@@ -5,6 +5,7 @@ import {
type ComponentProps,
createEffect,
createSignal,
+ Show,
} from "solid-js";
import { trackEvent } from "~/utils/analytics";
import { createCurrentRecordingQuery } from "~/utils/queries";
@@ -26,14 +27,102 @@ export default function CameraSelect(props: {
onChange: (camera: CameraInfo | null) => void;
permissions?: OSPermissionsCheck;
hidePreviewButton?: boolean;
+ onOpen?: () => void;
}) {
+ const currentRecording = createCurrentRecordingQuery();
+ const requestPermission = useRequestPermission();
+ const [cameraWindowOpen, setCameraWindowOpen] = createSignal(false);
+
+ const refreshCameraWindowState = async () => {
+ try {
+ setCameraWindowOpen(await commands.isCameraWindowOpen());
+ } catch {
+ setCameraWindowOpen(false);
+ }
+ };
+
+ createEffect(() => {
+ if (props.value) {
+ void refreshCameraWindowState();
+ } else {
+ setCameraWindowOpen(false);
+ }
+ });
+
+ createTimer(
+ () => {
+ if (props.value) {
+ void refreshCameraWindowState();
+ }
+ },
+ 2000,
+ setInterval,
+ );
+
+ const openCameraWindow = async (e: MouseEvent) => {
+ e.stopPropagation();
+ await commands.showWindow({ Camera: { centered: false } });
+ await refreshCameraWindowState();
+ };
+
+ const permissionGranted = () =>
+ props.permissions?.camera === "granted" ||
+ props.permissions?.camera === "notNeeded";
+
+ const showHiddenIndicator = () =>
+ props.value !== null &&
+ permissionGranted() &&
+ !cameraWindowOpen() &&
+ !props.hidePreviewButton;
+
return (
- <CameraSelectBase
- {...props}
- PillComponent={InfoPill}
- class="flex flex-row gap-2 items-center px-2 w-full h-[42px] rounded-lg border border-gray-5 transition-colors cursor-default disabled:opacity-70 bg-gray-3 disabled:text-gray-11 KSelect"
- iconClass="text-gray-10 size-4"
- />
+ <div class="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
+ <button
+ type="button"
+ disabled={!!currentRecording.data || props.disabled}
+ onClick={() => {
+ if (!permissionGranted()) {
+ requestPermission("camera", props.permissions?.camera);
+ return;
+ }
+ props.onOpen?.();
+ }}
+ class="flex flex-row gap-2 items-center px-2 w-full h-[42px] rounded-lg border border-gray-5 transition-colors cursor-default disabled:opacity-70 bg-gray-3 disabled:text-gray-11 KSelect"
+ >
+ <IconCapCamera class="text-gray-10 size-4" />
+ <p class="flex-1 text-sm text-left truncate">
+ {props.value?.display_name ?? NO_CAMERA}
+ </p>
+ <div class="flex items-center gap-1">
+ <Show when={showHiddenIndicator()}>
+ <button
+ type="button"
+ onClick={openCameraWindow}
+ onPointerDown={(e) => e.stopPropagation()}
+ class="flex items-center justify-center px-2 py-1 rounded-full bg-gray-6 text-gray-11 hover:bg-gray-7 transition-colors"
+ title="Show camera preview"
+ >
+ <IconLucideEyeOff class="size-3.5" />
+ </button>
+ </Show>
+ <TargetSelectInfoPill
+ PillComponent={InfoPill}
+ value={props.value}
+ permissionGranted={permissionGranted()}
+ requestPermission={() =>
+ requestPermission("camera", props.permissions?.camera)
+ }
+ onClick={(e) => {
+ if (!props.options) return;
+ if (props.value !== null) {
+ e.stopPropagation();
+ props.onChange(null);
+ }
+ }}
+ />
+ </div>
+ </button>
+ </div>
);
}
@@ -82,7 +171,7 @@ export function CameraSelectBase(props: {
const openCameraWindow = async (e: MouseEvent) => {
e.stopPropagation();
- await commands.showWindow("Camera");
+ await commands.showWindow({ Camera: { centered: false } });
await refreshCameraWindowState();
};
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
index b82149ad5..a64911eb1 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
@@ -23,15 +23,87 @@ export default function MicrophoneSelect(props: {
value: string | null;
onChange: (micName: string | null) => void;
permissions?: OSPermissionsCheck;
+ onOpen?: () => void;
}) {
+ const DB_SCALE = 40;
+ const currentRecording = createCurrentRecordingQuery();
+ const requestPermission = useRequestPermission();
+
+ const [dbs, setDbs] = createSignal<number | undefined>();
+ const [isInitialized, setIsInitialized] = createSignal(false);
+
+ const permissionGranted = () =>
+ props.permissions?.microphone === "granted" ||
+ props.permissions?.microphone === "notNeeded";
+
+ const handleMicrophoneChange = async (name: string | null) => {
+ if (!props.options) return;
+ props.onChange(name);
+ if (!name) setDbs();
+
+ trackEvent("microphone_selected", {
+ microphone_name: name ?? null,
+ enabled: !!name,
+ });
+ };
+
+ createTauriEventListener(events.audioInputLevelChange, (d) => {
+ if (!props.value) setDbs();
+ else setDbs(d);
+ });
+
+ const audioLevel = () =>
+ (1 - Math.max((dbs() ?? 0) + DB_SCALE, 0) / DB_SCALE) ** 0.5;
+
+ createEffect(() => {
+ if (!props.value || !permissionGranted() || isInitialized()) return;
+
+ setIsInitialized(true);
+ void handleMicrophoneChange(props.value);
+ });
+
return (
- <MicrophoneSelectBase
- {...props}
- class="flex overflow-hidden relative z-10 flex-row gap-2 items-center px-2 w-full h-[42px] rounded-lg border border-gray-5 transition-colors cursor-default disabled:opacity-70 bg-gray-3 disabled:text-gray-11 KSelect"
- levelIndicatorClass="bg-blue-7"
- iconClass="text-gray-10 size-4"
- PillComponent={InfoPill}
- />
+ <div class="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
+ <button
+ type="button"
+ disabled={!!currentRecording.data || props.disabled}
+ class="flex overflow-hidden relative z-10 flex-row gap-2 items-center px-2 w-full h-[42px] rounded-lg border border-gray-5 transition-colors cursor-default disabled:opacity-70 bg-gray-3 disabled:text-gray-11 KSelect"
+ onClick={() => {
+ if (!permissionGranted()) {
+ requestPermission("microphone", props.permissions?.microphone);
+ return;
+ }
+ props.onOpen?.();
+ }}
+ >
+ <Show when={props.value !== null && dbs()}>
+ {(_) => (
+ <div
+ class="opacity-50 left-0 inset-y-0 absolute transition-[right] duration-100 -z-10 bg-blue-7"
+ style={{ right: `${audioLevel() * 100}%` }}
+ />
+ )}
+ </Show>
+ <IconCapMicrophone class="text-gray-10 size-4" />
+ <p class="flex-1 text-sm text-left truncate">
+ {props.value ?? NO_MICROPHONE}
+ </p>
+ <TargetSelectInfoPill
+ PillComponent={InfoPill}
+ value={props.value}
+ permissionGranted={permissionGranted()}
+ requestPermission={() =>
+ requestPermission("microphone", props.permissions?.microphone)
+ }
+ onClick={(e) => {
+ if (props.value !== null) {
+ e.stopPropagation();
+ props.onChange(null);
+ }
+ }}
+ />
+ </button>
+ </div>
);
}
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
index 3f0403420..c8137b2e5 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
@@ -23,6 +23,7 @@ import {
createMemo,
createSignal,
ErrorBoundary,
+ For,
onCleanup,
onMount,
Show,
@@ -37,7 +38,11 @@ import { Input } from "~/routes/editor/ui";
import { authStore } from "~/store";
import { createSignInMutation } from "~/utils/auth";
import { createTauriEventListener } from "~/utils/createEventListener";
-import { createDevicesQuery } from "~/utils/devices";
+import {
+ type CameraWithDetails,
+ createStableDevicesQuery,
+ type MicrophoneWithDetails,
+} from "~/utils/devices";
import {
createCameraMutation,
createCurrentRecordingQuery,
@@ -49,7 +54,6 @@ import {
listWindowsWithThumbnails,
} from "~/utils/queries";
import {
- type CameraInfo,
type CaptureDisplay,
type CaptureDisplayWithThumbnail,
type CaptureWindow,
@@ -57,6 +61,7 @@ import {
commands,
type DeviceOrModelID,
events,
+ type OSPermissionsCheck,
type RecordingTargetMode,
type ScreenCaptureTarget,
type UploadProgress,
@@ -88,10 +93,11 @@ import type { RecordingWithPath, ScreenshotWithPath } from "./TargetCard";
import TargetDropdownButton from "./TargetDropdownButton";
import TargetMenuGrid from "./TargetMenuGrid";
import TargetTypeButton from "./TargetTypeButton";
+import useRequestPermission from "./useRequestPermission";
const WINDOW_SIZE = { width: 330, height: 395 } as const;
-const findCamera = (cameras: CameraInfo[], id: DeviceOrModelID) => {
+const findCamera = (cameras: CameraWithDetails[], id: DeviceOrModelID) => {
return cameras.find((c) => {
if (!id) return false;
return "DeviceID" in id
@@ -165,6 +171,20 @@ type TargetMenuPanelProps =
targets?: ScreenshotWithPath[];
onSelect: (target: ScreenshotWithPath) => void;
onViewAll: () => void;
+ }
+ | {
+ variant: "camera";
+ targets?: CameraWithDetails[];
+ selectedTarget: CameraWithDetails | null;
+ onSelect: (target: CameraWithDetails | null) => void;
+ permissions?: OSPermissionsCheck;
+ }
+ | {
+ variant: "microphone";
+ targets?: MicrophoneWithDetails[];
+ selectedTarget: MicrophoneWithDetails | null;
+ onSelect: (target: MicrophoneWithDetails | null) => void;
+ permissions?: OSPermissionsCheck;
};
type SharedTargetMenuProps = {
@@ -174,10 +194,388 @@ type SharedTargetMenuProps = {
onBack: () => void;
};
+type DeviceListPanelProps =
+ | {
+ variant: "camera";
+ targets: CameraWithDetails[];
+ selectedTarget: CameraWithDetails | null;
+ onSelect: (target: CameraWithDetails | null) => void;
+ isLoading?: boolean;
+ errorMessage?: string;
+ disabled?: boolean;
+ emptyMessage?: string;
+ permissions?: OSPermissionsCheck;
+ }
+ | {
+ variant: "microphone";
+ targets: MicrophoneWithDetails[];
+ selectedTarget: MicrophoneWithDetails | null;
+ onSelect: (target: MicrophoneWithDetails | null) => void;
+ isLoading?: boolean;
+ errorMessage?: string;
+ disabled?: boolean;
+ emptyMessage?: string;
+ permissions?: OSPermissionsCheck;
+ };
+
+function CameraListItem(props: {
+ camera: CameraWithDetails;
+ isSelected: boolean;
+ isFocused: boolean;
+ disabled?: boolean;
+ onSelect: () => void;
+ ref?: (el: HTMLButtonElement) => void;
+}) {
+ const formatDetails = () => {
+ if (!props.camera.bestFormat) return null;
+ const { width, height, frameRate } = props.camera.bestFormat;
+ return `${width}×${height} @ ${Math.round(frameRate)}fps`;
+ };
+
+ return (
+ <button
+ ref={props.ref}
+ type="button"
+ disabled={props.disabled}
+ onClick={props.onSelect}
+ class={cx(
+ "flex flex-col gap-0.5 px-3 py-2.5 rounded-lg text-sm text-left outline-none",
+ props.isSelected
+ ? "bg-blue-500 text-white"
+ : props.isFocused
+ ? "bg-gray-5 text-gray-12"
+ : "hover:bg-gray-4 text-gray-12",
+ props.disabled && "opacity-50 cursor-not-allowed",
+ )}
+ >
+ <div class="flex items-center gap-3 w-full">
+ <IconCapCamera class="size-4 shrink-0" />
+ <span class="truncate flex-1">{props.camera.display_name}</span>
+ <Show when={props.isSelected}>
+ <IconLucideCheck class="size-4 shrink-0" />
+ </Show>
+ </div>
+ <Show when={formatDetails()}>
+ {(details) => (
+ <span
+ class={cx(
+ "text-[11px] pl-7",
+ props.isSelected ? "text-white/70" : "text-gray-10",
+ )}
+ >
+ {details()}
+ </span>
+ )}
+ </Show>
+ </button>
+ );
+}
+
+function MicrophoneListItem(props: {
+ mic: MicrophoneWithDetails;
+ isSelected: boolean;
+ isFocused: boolean;
+ disabled?: boolean;
+ onSelect: () => void;
+ ref?: (el: HTMLButtonElement) => void;
+ audioLevel?: number;
+}) {
+ const formatDetails = () => {
+ if (!props.mic.sampleRate) return null;
+ const channels =
+ props.mic.channels === 1
+ ? "Mono"
+ : props.mic.channels === 2
+ ? "Stereo"
+ : `${props.mic.channels}ch`;
+ return `${props.mic.sampleRate / 1000}kHz ${channels}`;
+ };
+
+ return (
+ <button
+ ref={props.ref}
+ type="button"
+ disabled={props.disabled}
+ onClick={props.onSelect}
+ class={cx(
+ "relative overflow-hidden flex flex-col gap-0.5 px-3 py-2.5 rounded-lg text-sm text-left outline-none",
+ props.isSelected
+ ? "bg-blue-500 text-white"
+ : props.isFocused
+ ? "bg-gray-5 text-gray-12"
+ : "hover:bg-gray-4 text-gray-12",
+ props.disabled && "opacity-50 cursor-not-allowed",
+ )}
+ >
+ <Show when={props.isSelected && props.audioLevel !== undefined}>
+ <div
+ class="absolute inset-y-0 left-0 transition-[right] duration-100 rounded-lg"
+ style={{
+ right: `${(props.audioLevel ?? 1) * 100}%`,
+ "background-color": "rgba(255, 255, 255, 0.25)",
+ }}
+ />
+ </Show>
+ <div class="relative flex items-center gap-3 w-full">
+ <IconCapMicrophone class="size-4 shrink-0" />
+ <span class="truncate flex-1">{props.mic.name}</span>
+ <Show when={props.isSelected}>
+ <IconLucideCheck class="size-4 shrink-0" />
+ </Show>
+ </div>
+ <Show when={formatDetails()}>
+ {(details) => (
+ <span
+ class={cx(
+ "text-[11px] pl-7",
+ props.isSelected ? "text-white/70" : "text-gray-10",
+ )}
+ >
+ {details()}
+ </span>
+ )}
+ </Show>
+ </button>
+ );
+}
+
+function DeviceListPanel(props: DeviceListPanelProps) {
+ const DB_SCALE = 40;
+ const requestPermission = useRequestPermission();
+ const [focusedIndex, setFocusedIndex] = createSignal(-1);
+ const [dbs, setDbs] = createSignal<number | undefined>();
+ const itemRefs: HTMLButtonElement[] = [];
+ let containerRef: HTMLDivElement | undefined;
+
+ createTauriEventListener(events.audioInputLevelChange, (d) => {
+ if (props.variant !== "microphone" || props.selectedTarget === null) {
+ setDbs();
+ } else {
+ setDbs(d);
+ }
+ });
+
+ const audioLevel = () => {
+ const d = dbs();
+ if (d === undefined) return undefined;
+ return (1 - Math.max(d + DB_SCALE, 0) / DB_SCALE) ** 0.5;
+ };
+
+ const totalItems = () => props.targets.length + 1;
+
+ const getInitialFocusIndex = () => {
+ if (props.selectedTarget === null) return 0;
+ if (props.variant === "camera") {
+ const target = props.selectedTarget as CameraWithDetails;
+ const idx = (props.targets as CameraWithDetails[]).findIndex(
+ (c) => c.device_id === target.device_id,
+ );
+ return idx >= 0 ? idx + 1 : 0;
+ }
+ const target = props.selectedTarget as MicrophoneWithDetails;
+ const idx = (props.targets as MicrophoneWithDetails[]).findIndex(
+ (m) => m.name === target.name,
+ );
+ return idx >= 0 ? idx + 1 : 0;
+ };
+
+ onMount(() => {
+ setFocusedIndex(getInitialFocusIndex());
+ setTimeout(() => containerRef?.focus(), 50);
+ });
+
+ createEffect(() => {
+ const idx = focusedIndex();
+ if (idx >= 0 && itemRefs[idx]) {
+ itemRefs[idx].scrollIntoView({ block: "nearest" });
+ }
+ });
+
+ const permissionGranted = () => {
+ if (props.variant === "camera") {
+ return (
+ props.permissions?.camera === "granted" ||
+ props.permissions?.camera === "notNeeded"
+ );
+ }
+ return (
+ props.permissions?.microphone === "granted" ||
+ props.permissions?.microphone === "notNeeded"
+ );
+ };
+
+ const handleSelect = (
+ item: CameraWithDetails | MicrophoneWithDetails | null,
+ ) => {
+ if (!permissionGranted()) {
+ if (props.variant === "camera") {
+ requestPermission("camera", props.permissions?.camera);
+ } else {
+ requestPermission("microphone", props.permissions?.microphone);
+ }
+ return;
+ }
+ if (props.variant === "camera") {
+ (props.onSelect as (target: CameraWithDetails | null) => void)(
+ item as CameraWithDetails | null,
+ );
+ } else {
+ (props.onSelect as (target: MicrophoneWithDetails | null) => void)(
+ item as MicrophoneWithDetails | null,
+ );
+ }
+ };
+
+ const handleKeyDown = (e: KeyboardEvent) => {
+ const total = totalItems();
+ if (total === 0) return;
+
+ switch (e.key) {
+ case "ArrowDown": {
+ e.preventDefault();
+ setFocusedIndex((prev) => (prev + 1) % total);
+ break;
+ }
+ case "ArrowUp": {
+ e.preventDefault();
+ setFocusedIndex((prev) => (prev - 1 + total) % total);
+ break;
+ }
+ case "Enter": {
+ e.preventDefault();
+ const idx = focusedIndex();
+ if (idx === 0) {
+ handleSelect(null);
+ } else if (idx > 0 && idx <= props.targets.length) {
+ handleSelect(props.targets[idx - 1]);
+ }
+ break;
+ }
+ case "Home": {
+ e.preventDefault();
+ setFocusedIndex(0);
+ break;
+ }
+ case "End": {
+ e.preventDefault();
+ setFocusedIndex(total - 1);
+ break;
+ }
+ }
+ };
+
+ const isNoneSelected = () => props.selectedTarget === null;
+
+ const isCameraSelected = (camera: CameraWithDetails) => {
+ if (props.variant !== "camera") return false;
+ const target = props.selectedTarget as CameraWithDetails | null;
+ return target !== null && camera.device_id === target.device_id;
+ };
+
+ const isMicSelected = (mic: MicrophoneWithDetails) => {
+ if (props.variant !== "microphone") return false;
+ const target = props.selectedTarget as MicrophoneWithDetails | null;
+ return target !== null && mic.name === target.name;
+ };
+
+ return (
+ <div
+ ref={containerRef}
+ class="flex flex-col gap-1 outline-none"
+ tabIndex={0}
+ onKeyDown={handleKeyDown}
+ >
+ <Show when={props.errorMessage}>
+ <div class="py-6 text-sm text-center text-gray-11">
+ {props.errorMessage}
+ </div>
+ </Show>
+ <Show when={props.isLoading}>
+ <div class="py-6 text-sm text-center text-gray-11">Loading...</div>
+ </Show>
+ <Show
+ when={
+ !props.isLoading &&
+ !props.errorMessage &&
+ (props.targets.length > 0 || true)
+ }
+ >
+ <button
+ ref={(el) => {
+ itemRefs[0] = el;
+ }}
+ type="button"
+ disabled={props.disabled}
+ onClick={() => handleSelect(null)}
+ class={cx(
+ "flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm text-left outline-none",
+ isNoneSelected()
+ ? "bg-blue-500 text-white"
+ : focusedIndex() === 0
+ ? "bg-gray-5 text-gray-12"
+ : "hover:bg-gray-4 text-gray-12",
+ props.disabled && "opacity-50 cursor-not-allowed",
+ )}
+ >
+ <IconLucideCircleOff class="size-4 shrink-0" />
+ <span class="truncate flex-1">
+ {props.variant === "camera" ? "No Camera" : "No Microphone"}
+ </span>
+ <Show when={isNoneSelected()}>
+ <IconLucideCheck class="size-4 shrink-0" />
+ </Show>
+ </button>
+
+ <Show when={props.targets.length === 0}>
+ <div class="py-4 text-sm text-center text-gray-11">
+ {props.emptyMessage}
+ </div>
+ </Show>
+
+ <Show when={props.variant === "camera"}>
+ <For each={props.targets as CameraWithDetails[]}>
+ {(camera, index) => (
+ <CameraListItem
+ ref={(el) => {
+ itemRefs[index() + 1] = el;
+ }}
+ camera={camera}
+ isSelected={isCameraSelected(camera)}
+ isFocused={focusedIndex() === index() + 1}
+ disabled={props.disabled}
+ onSelect={() => handleSelect(camera)}
+ />
+ )}
+ </For>
+ </Show>
+
+ <Show when={props.variant === "microphone"}>
+ <For each={props.targets as MicrophoneWithDetails[]}>
+ {(mic, index) => (
+ <MicrophoneListItem
+ ref={(el) => {
+ itemRefs[index() + 1] = el;
+ }}
+ mic={mic}
+ isSelected={isMicSelected(mic)}
+ isFocused={focusedIndex() === index() + 1}
+ disabled={props.disabled}
+ onSelect={() => handleSelect(mic)}
+ audioLevel={isMicSelected(mic) ? audioLevel() : undefined}
+ />
+ )}
+ </For>
+ </Show>
+ </Show>
+ </div>
+ );
+}
+
function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {
const [search, setSearch] = createSignal("");
const trimmedSearch = createMemo(() => search().trim());
const normalizedQuery = createMemo(() => trimmedSearch().toLowerCase());
+ let scrollContainerRef: HTMLDivElement | undefined;
const placeholder =
props.variant === "display"
? "Search displays"
@@ -185,7 +583,11 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {
? "Search windows"
: props.variant === "recording"
? "Search recordings"
- : "Search screenshots";
+ : props.variant === "screenshot"
+ ? "Search screenshots"
+ : props.variant === "camera"
+ ? "Search cameras"
+ : "Search microphones";
const noResultsMessage =
props.variant === "display"
? "No matching displays"
@@ -193,7 +595,11 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {
? "No matching windows"
: props.variant === "recording"
? "No matching recordings"
- : "No matching screenshots";
+ : props.variant === "screenshot"
+ ? "No matching screenshots"
+ : props.variant === "camera"
+ ? "No matching cameras"
+ : "No matching microphones";
const handleImport = async () => {
const result = await dialog.open({
@@ -278,6 +684,48 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {
return targets.filter((target) => matchesQuery(target.pretty_name));
});
+ const filteredCameraTargets = createMemo<CameraWithDetails[]>((prev) => {
+ if (props.variant !== "camera") return [];
+ const query = normalizedQuery();
+ const targets = (props.targets ?? []) as CameraWithDetails[];
+ if (!query) {
+ if (
+ prev &&
+ prev.length === targets.length &&
+ prev.every((p, i) => p.device_id === targets[i]?.device_id)
+ ) {
+ return prev;
+ }
+ return [...targets];
+ }
+
+ const matchesQuery = (value?: string | null) =>
+ !!value && value.toLowerCase().includes(query);
+
+ return targets.filter((target) => matchesQuery(target.display_name));
+ }, []);
+
+ const filteredMicrophoneTargets = createMemo<MicrophoneWithDetails[]>(
+ (prev) => {
+ if (props.variant !== "microphone") return [];
+ const query = normalizedQuery();
+ const targets = (props.targets ?? []) as MicrophoneWithDetails[];
+ if (!query) {
+ if (
+ prev &&
+ prev.length === targets.length &&
+ prev.every((p, i) => p.name === targets[i]?.name)
+ ) {
+ return prev;
+ }
+ return [...targets];
+ }
+
+ return targets.filter((mic) => mic.name.toLowerCase().includes(query));
+ },
+ [],
+ );
+
return (
<div class="flex flex-col w-full h-full min-h-0">
<div class="flex gap-3 justify-between items-center mt-3">
@@ -326,7 +774,11 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {
</div>
</div>
<div class="flex flex-col flex-1 min-h-0 pt-4">
- <div class="px-2 custom-scroll flex-1 overflow-y-auto">
+ <div
+ ref={scrollContainerRef}
+ class="px-2 custom-scroll flex-1 overflow-y-auto"
+ style={{ "overflow-anchor": "none" }}
+ >
{props.variant === "display" ? (
<TargetMenuGrid
variant="display"
@@ -365,6 +817,34 @@ function TargetMenuPanel(props: TargetMenuPanelProps & SharedTargetMenuProps) {
onRefetch={props.onRefetch}
onViewAll={props.onViewAll}
/>
+ ) : props.variant === "camera" ? (
+ <DeviceListPanel
+ variant="camera"
+ targets={filteredCameraTargets()}
+ selectedTarget={props.selectedTarget}
+ isLoading={props.isLoading}
+ errorMessage={props.errorMessage}
+ onSelect={props.onSelect}
+ disabled={props.disabled}
+ emptyMessage={
+ trimmedSearch() ? noResultsMessage : "No cameras found"
+ }
+ permissions={props.permissions}
+ />
+ ) : props.variant === "microphone" ? (
+ <DeviceListPanel
+ variant="microphone"
+ targets={filteredMicrophoneTargets()}
+ selectedTarget={props.selectedTarget}
+ isLoading={props.isLoading}
+ errorMessage={props.errorMessage}
+ onSelect={props.onSelect}
+ disabled={props.disabled}
+ emptyMessage={
+ trimmedSearch() ? noResultsMessage : "No microphones found"
+ }
+ permissions={props.permissions}
+ />
) : (
<TargetMenuGrid
variant="screenshot"
@@ -471,14 +951,25 @@ function Page() {
const [recordingsMenuOpen, setRecordingsMenuOpen] = createSignal(false);
const [screenshotsMenuOpen, setScreenshotsMenuOpen] = createSignal(false);
const [modeInfoMenuOpen, setModeInfoMenuOpen] = createSignal(false);
+ const [cameraMenuOpen, setCameraMenuOpen] = createSignal(false);
+ const [microphoneMenuOpen, setMicrophoneMenuOpen] = createSignal(false);
const activeMenu = createMemo<
- "display" | "window" | "recording" | "screenshot" | "modeInfo" | null
+ | "display"
+ | "window"
+ | "recording"
+ | "screenshot"
+ | "modeInfo"
+ | "camera"
+ | "microphone"
+ | null
>(() => {
if (displayMenuOpen()) return "display";
if (windowMenuOpen()) return "window";
if (recordingsMenuOpen()) return "recording";
if (screenshotsMenuOpen()) return "screenshot";
if (modeInfoMenuOpen()) return "modeInfo";
+ if (cameraMenuOpen()) return "camera";
+ if (microphoneMenuOpen()) return "microphone";
return null;
});
const [hasOpenedDisplayMenu, setHasOpenedDisplayMenu] = createSignal(false);
@@ -692,6 +1183,8 @@ function Page() {
setRecordingsMenuOpen(false);
setScreenshotsMenuOpen(false);
setModeInfoMenuOpen(false);
+ setCameraMenuOpen(false);
+ setMicrophoneMenuOpen(false);
});
createUpdateCheck();
@@ -758,10 +1251,7 @@ function Page() {
});
});
- const devices = createDevicesQuery();
- const cameras = createMemo(() => devices.data?.cameras ?? []);
- const mics = createMemo(() => devices.data?.microphones ?? []);
- const permissions = createMemo(() => devices.data?.permissions);
+ const devices = createStableDevicesQuery();
const windowListSignature = createMemo(() =>
createWindowSignature(windows.data),
@@ -806,15 +1296,18 @@ function Page() {
});
createEffect(() => {
- const cameraList = cameras();
+ const cameraList = devices.cameras;
if (rawOptions.cameraID && findCamera(cameraList, rawOptions.cameraID)) {
setOptions("cameraLabel", null);
}
});
createEffect(() => {
- const micList = mics();
- if (rawOptions.micName && !micList.includes(rawOptions.micName)) {
+ const micList = devices.microphones;
+ if (
+ rawOptions.micName &&
+ !micList.find((m) => m.name === rawOptions.micName)
+ ) {
setOptions("micName", null);
}
});
@@ -847,9 +1340,10 @@ function Page() {
},
camera: () => {
if (!rawOptions.cameraID) return undefined;
- return findCamera(cameras(), rawOptions.cameraID);
+ return findCamera(devices.cameras, rawOptions.cameraID);
},
- micName: () => mics().find((name) => name === rawOptions.micName),
+ micName: () =>
+ devices.microphones.find((m) => m.name === rawOptions.micName),
target: (): ScreenCaptureTarget | undefined => {
switch (rawOptions.captureTarget.variant) {
case "display": {
@@ -947,21 +1441,39 @@ function Page() {
<div class="space-y-2">
<CameraSelect
disabled={devices.isPending}
- options={cameras()}
+ options={devices.cameras}
value={options.camera() ?? null}
onChange={(c) => {
if (!c) setCamera.mutate(null);
else if (c.model_id) setCamera.mutate({ ModelID: c.model_id });
else setCamera.mutate({ DeviceID: c.device_id });
}}
- permissions={permissions()}
+ permissions={devices.permissions}
+ onOpen={() => {
+ setCameraMenuOpen(true);
+ setDisplayMenuOpen(false);
+ setWindowMenuOpen(false);
+ setRecordingsMenuOpen(false);
+ setScreenshotsMenuOpen(false);
+ setModeInfoMenuOpen(false);
+ setMicrophoneMenuOpen(false);
+ }}
/>
<MicrophoneSelect
disabled={devices.isPending}
- options={mics()}
- value={options.micName() ?? null}
+ options={devices.microphones.map((m) => m.name)}
+ value={options.micName()?.name ?? null}
onChange={(v) => setMicInput.mutate(v)}
- permissions={permissions()}
+ permissions={devices.permissions}
+ onOpen={() => {
+ setMicrophoneMenuOpen(true);
+ setDisplayMenuOpen(false);
+ setWindowMenuOpen(false);
+ setRecordingsMenuOpen(false);
+ setScreenshotsMenuOpen(false);
+ setModeInfoMenuOpen(false);
+ setCameraMenuOpen(false);
+ }}
/>
<SystemAudio />
</div>
@@ -1237,6 +1749,8 @@ function Page() {
setWindowMenuOpen(false);
setRecordingsMenuOpen(false);
setScreenshotsMenuOpen(false);
+ setCameraMenuOpen(false);
+ setMicrophoneMenuOpen(false);
}}
/>
</div>
@@ -1365,6 +1879,41 @@ function Page() {
getCurrentWindow().hide();
}}
/>
+ ) : variant === "camera" ? (
+ <TargetMenuPanel
+ variant="camera"
+ targets={devices.cameras}
+ selectedTarget={options.camera() ?? null}
+ isLoading={devices.isPending}
+ onSelect={(c) => {
+ if (!c) setCamera.mutate(null);
+ else if (c.model_id)
+ setCamera.mutate({ ModelID: c.model_id });
+ else setCamera.mutate({ DeviceID: c.device_id });
+ setCameraMenuOpen(false);
+ }}
+ disabled={isRecording()}
+ onBack={() => {
+ setCameraMenuOpen(false);
+ }}
+ permissions={devices.permissions}
+ />
+ ) : variant === "microphone" ? (
+ <TargetMenuPanel
+ variant="microphone"
+ targets={devices.microphones}
+ selectedTarget={options.micName() ?? null}
+ isLoading={devices.isPending}
+ onSelect={(v) => {
+ setMicInput.mutate(v?.name ?? null);
+ setMicrophoneMenuOpen(false);
+ }}
+ disabled={isRecording()}
+ onBack={() => {
+ setMicrophoneMenuOpen(false);
+ }}
+ permissions={devices.permissions}
+ />
) : (
<ModeInfoPanel
onBack={() => {
diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsx
index 54227f6d6..ebc7994ef 100644
--- a/apps/desktop/src/routes/target-select-overlay.tsx
+++ b/apps/desktop/src/routes/target-select-overlay.tsx
@@ -58,8 +58,9 @@ import {
type ScreenCaptureTarget,
type TargetUnderCursor,
} from "~/utils/tauri";
-import CameraSelect from "./(window-chrome)/new-main/CameraSelect";
-import MicrophoneSelect from "./(window-chrome)/new-main/MicrophoneSelect";
+import { CameraSelectBase } from "./(window-chrome)/new-main/CameraSelect";
+import InfoPill from "./(window-chrome)/new-main/InfoPill";
+import { MicrophoneSelectBase } from "./(window-chrome)/new-main/MicrophoneSelect";
import {
RecordingOptionsProvider,
useRecordingOptions,
@@ -1366,7 +1367,7 @@ function RecordingControls(props: {
<Show when={(rawOptions.mode as string) !== "screenshot"}>
<div class="p-3 rounded-2xl border border-white/30 dark:border-white/10 bg-white/70 dark:bg-gray-2/70 shadow-lg backdrop-blur-xl">
<div class="grid grid-cols-2 gap-2 w-full">
- <CameraSelect
+ <CameraSelectBase
disabled={devices.isPending}
options={cameras()}
value={selectedCamera() ?? null}
@@ -1378,13 +1379,20 @@ function RecordingControls(props: {
}}
permissions={permissions()}
hidePreviewButton={props.target.variant === "cameraOnly"}
+ PillComponent={InfoPill}
+ class="flex flex-row gap-2 items-center px-2 w-full h-[42px] rounded-lg border border-gray-5 transition-colors cursor-default disabled:opacity-70 bg-gray-3 disabled:text-gray-11 KSelect"
+ iconClass="text-gray-10 size-4"
/>
- <MicrophoneSelect
+ <MicrophoneSelectBase
disabled={devices.isPending}
options={mics()}
value={selectedMicName()}
onChange={(value) => setMicInput.mutate(value)}
permissions={permissions()}
+ PillComponent={InfoPill}
+ class="flex overflow-hidden relative z-10 flex-row gap-2 items-center px-2 w-full h-[42px] rounded-lg border border-gray-5 transition-colors cursor-default disabled:opacity-70 bg-gray-3 disabled:text-gray-11 KSelect"
+ levelIndicatorClass="bg-blue-7"
+ iconClass="text-gray-10 size-4"
/>
</div>
</div>