Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: show not-connected state on device rows

Richie McIlroy0598c7344062
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 0f3a09e95..2141df992 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/CameraSelect.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/CameraSelect.tsx
@@ -35,6 +35,8 @@ export default function CameraSelect(props: {
value: CameraInfo | null;
selectedLabel?: string | null;
isSelected?: boolean;
+ /** The selected camera is remembered but not currently connected. */
+ disconnected?: boolean;
onChange: (camera: CameraInfo | null) => void;
permissions?: OSPermissionsCheck;
hidePreviewButton?: boolean;
@@ -93,6 +95,8 @@ export default function CameraSelect(props: {
props.permissions.camera === "granted" ||
props.permissions.camera === "notNeeded";
+ const notConnected = () => !!props.disconnected && permissionGranted();
+
const hasSelection = () => props.isSelected ?? props.value !== null;
const label = () =>
@@ -104,10 +108,14 @@ export default function CameraSelect(props: {
props.value !== null &&
permissionGranted() &&
!cameraWindowOpen() &&
- !props.hidePreviewButton;
+ !props.hidePreviewButton &&
+ !notConnected();
const showSettingsShortcut = () =>
- hasSelection() && permissionGranted() && !!props.onOpenSettings;
+ hasSelection() &&
+ permissionGranted() &&
+ !!props.onOpenSettings &&
+ !notConnected();
const isDisabled = () => !!currentRecording.data || props.disabled;
@@ -127,7 +135,12 @@ export default function CameraSelect(props: {
aria-haspopup="menu"
>
<IconCapCamera class={DEVICE_ROW_ICON_CLASS} />
- <p class={DEVICE_ROW_LABEL_CLASS}>{label()}</p>
+ <p
+ class={cx(DEVICE_ROW_LABEL_CLASS, notConnected() && "text-gray-10")}
+ title={notConnected() ? "Not connected" : undefined}
+ >
+ {label()}
+ </p>
<div class={DEVICE_ROW_TRAILING_CLASS}>
<Show when={showHiddenIndicator()}>
<button
@@ -160,6 +173,7 @@ export default function CameraSelect(props: {
<TargetSelectInfoPill
PillComponent={InfoPill}
value={hasSelection() ? true : null}
+ disconnected={notConnected()}
permissionGranted={permissionGranted()}
requestPermission={() =>
requestPermission("camera", props.permissions?.camera)
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 4084064b0..2a3543c20 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
@@ -27,6 +27,8 @@ export default function MicrophoneSelect(props: {
disabled?: boolean;
options: string[];
value: string | null;
+ /** The selected microphone is remembered but not currently connected. */
+ disconnected?: boolean;
onChange: (micName: string | null) => void;
permissions?: OSPermissionsCheck;
onOpen?: () => void;
@@ -43,6 +45,8 @@ export default function MicrophoneSelect(props: {
props.permissions.microphone === "granted" ||
props.permissions.microphone === "notNeeded";
+ const notConnected = () => !!props.disconnected && permissionGranted();
+
const handleMicrophoneChange = async (name: string | null) => {
if (!props.options) return;
props.onChange(name);
@@ -62,10 +66,14 @@ export default function MicrophoneSelect(props: {
const audioLevel = () =>
(1 - Math.max((dbs() ?? 0) + DB_SCALE, 0) / DB_SCALE) ** 0.5;
- const showLevel = () => props.value !== null && dbs() !== undefined;
+ const showLevel = () =>
+ props.value !== null && dbs() !== undefined && !notConnected();
const showSettingsShortcut = () =>
- props.value !== null && permissionGranted() && !!props.onOpenSettings;
+ props.value !== null &&
+ permissionGranted() &&
+ !!props.onOpenSettings &&
+ !notConnected();
const isDisabled = () => !!currentRecording.data || props.disabled;
@@ -95,7 +103,12 @@ export default function MicrophoneSelect(props: {
/>
</Show>
<IconCapMicrophone class={DEVICE_ROW_ICON_CLASS} />
- <p class={DEVICE_ROW_LABEL_CLASS}>{props.value ?? NO_MICROPHONE}</p>
+ <p
+ class={cx(DEVICE_ROW_LABEL_CLASS, notConnected() && "text-gray-10")}
+ title={notConnected() ? "Not connected" : undefined}
+ >
+ {props.value ?? NO_MICROPHONE}
+ </p>
<div class={DEVICE_ROW_TRAILING_CLASS}>
<Show when={showSettingsShortcut()}>
<button
@@ -116,6 +129,7 @@ export default function MicrophoneSelect(props: {
<TargetSelectInfoPill
PillComponent={InfoPill}
value={props.value}
+ disconnected={notConnected()}
permissionGranted={permissionGranted()}
requestPermission={() =>
requestPermission("microphone", props.permissions?.microphone)
diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx
index 86a827920..8d224a12d 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetSelectInfoPill.tsx
@@ -5,6 +5,8 @@ import type { InfoPillVariant } from "./InfoPill";
export default function TargetSelectInfoPill<T>(props: {
value: T | null;
permissionGranted: boolean;
+ /** The selected device is remembered but not currently connected. */
+ disconnected?: boolean;
requestPermission: () => void;
onClick: (e: MouseEvent) => void;
PillComponent: Component<
@@ -13,6 +15,7 @@ export default function TargetSelectInfoPill<T>(props: {
}) {
const variant = (): InfoPillVariant => {
if (!props.permissionGranted) return "red";
+ if (props.disconnected) return "gray";
return props.value !== null ? "blue" : "gray";
};
@@ -35,7 +38,13 @@ export default function TargetSelectInfoPill<T>(props: {
props.onClick(e);
}}
>
- {!props.permissionGranted ? "Allow" : props.value !== null ? "On" : "Off"}
+ {!props.permissionGranted
+ ? "Allow"
+ : props.disconnected
+ ? "Not connected"
+ : props.value !== null
+ ? "On"
+ : "Off"}
</Dynamic>
);
}