Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): remove microphone auto-init effect and add optimistic rollback

Richie McIlroy0e074ce105fc
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 a64911eb1..4f8ac4706 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/MicrophoneSelect.tsx
@@ -3,7 +3,6 @@ import { cx } from "cva";
import {
type Component,
type ComponentProps,
- createEffect,
createSignal,
Show,
} from "solid-js";
@@ -30,7 +29,6 @@ export default function MicrophoneSelect(props: {
const requestPermission = useRequestPermission();
const [dbs, setDbs] = createSignal<number | undefined>();
- const [isInitialized, setIsInitialized] = createSignal(false);
const permissionGranted = () =>
props.permissions?.microphone === "granted" ||
@@ -55,13 +53,6 @@ export default function MicrophoneSelect(props: {
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 (
<div class="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
<button
@@ -98,7 +89,7 @@ export default function MicrophoneSelect(props: {
onClick={(e) => {
if (props.value !== null) {
e.stopPropagation();
- props.onChange(null);
+ void handleMicrophoneChange(null);
}
}}
/>
@@ -125,7 +116,6 @@ export function MicrophoneSelectBase(props: {
const currentRecording = createCurrentRecordingQuery();
const [dbs, setDbs] = createSignal<number | undefined>();
- const [isInitialized, setIsInitialized] = createSignal(false);
const requestPermission = useRequestPermission();
@@ -154,13 +144,6 @@ export function MicrophoneSelectBase(props: {
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({ name: props.value });
- });
-
return (
<div class="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
<button
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 62a814902..24024d49a 100644
--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
@@ -1416,8 +1416,14 @@ function Page() {
const setMicInput = createMutation(() => ({
mutationFn: async (name: string | null) => {
- await commands.setMicInput(name);
- setOptions("micName", name);
+ const previous = rawOptions.micName ?? null;
+ if (previous !== name) setOptions("micName", name);
+ try {
+ await commands.setMicInput(name);
+ } catch (error) {
+ if (previous !== name) setOptions("micName", previous);
+ throw error;
+ }
},
}));
diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsx
index 994c61ae4..cd922e5d2 100644
--- a/apps/desktop/src/routes/target-select-overlay.tsx
+++ b/apps/desktop/src/routes/target-select-overlay.tsx
@@ -1175,8 +1175,14 @@ function RecordingControls(props: {
const permissions = createMemo(() => devices.data?.permissions);
const setMicInput = createMutation(() => ({
mutationFn: async (name: string | null) => {
- await commands.setMicInput(name);
- setOptions("micName", name);
+ const previous = rawOptions.micName ?? null;
+ if (previous !== name) setOptions("micName", name);
+ try {
+ await commands.setMicInput(name);
+ } catch (error) {
+ if (previous !== name) setOptions("micName", previous);
+ throw error;
+ }
},
}));
const setCamera = createCameraMutation();