Skip to content

Commit b38c990

Browse files
committed
fix(chrome-extension): derive permission UI from grant not selection
1 parent 7f0527c commit b38c990

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

apps/chrome-extension/src/popup/components/camera-selector.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ export const CameraSelector = ({
3939
}: CameraSelectorProps) => {
4040
const cameraEnabled = selectedCameraId !== null;
4141
const triggerRef = useRef<HTMLButtonElement>(null);
42-
const { state: permissionState, requestPermission } =
43-
useMediaPermission("camera");
44-
45-
const permissionSupported = permissionState !== "unsupported";
46-
const hasDeviceAccess = availableCameras.length > 0;
47-
const hasAccess = permissionGranted || hasDeviceAccess || cameraEnabled;
48-
const shouldRequestPermission =
49-
permissionSupported && permissionState !== "granted" && !hasAccess;
42+
const { requestPermission } = useMediaPermission("camera");
43+
44+
// "Has access" tracks only the real browser grant — a live device or the
45+
// authoritative permission flag the offscreen document reports — never a
46+
// remembered device selection. A remembered camera must not hide that
47+
// Chrome has reset the grant, otherwise the panel shows an empty picker
48+
// with no way to recover from here.
49+
const hasAccess = permissionGranted || availableCameras.length > 0;
50+
const shouldRequestPermission = !hasAccess;
5051

5152
const statusPillDisabled = !shouldRequestPermission && !cameraEnabled;
5253

apps/chrome-extension/src/popup/components/microphone-selector.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export const MicrophoneSelector = ({
3939
}: MicrophoneSelectorProps) => {
4040
const micEnabled = selectedMicId !== null;
4141
const triggerRef = useRef<HTMLButtonElement>(null);
42-
const { state: permissionState, requestPermission } =
43-
useMediaPermission("microphone");
44-
45-
const permissionSupported = permissionState !== "unsupported";
46-
const hasDeviceAccess = availableMics.length > 0;
47-
const hasAccess = permissionGranted || hasDeviceAccess || micEnabled;
48-
const shouldRequestPermission =
49-
permissionSupported && permissionState !== "granted" && !hasAccess;
42+
const { requestPermission } = useMediaPermission("microphone");
43+
44+
// "Has access" tracks only the real browser grant — a live device or the
45+
// authoritative permission flag the offscreen document reports — never a
46+
// remembered/default mic selection. The mic defaults to on, so keying off
47+
// the selection would permanently hide a reset grant behind an "On" pill.
48+
const hasAccess = permissionGranted || availableMics.length > 0;
49+
const shouldRequestPermission = !hasAccess;
5050

5151
const statusPillDisabled =
5252
disabled || (!shouldRequestPermission && !micEnabled);

0 commit comments

Comments
 (0)