Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): add camera background controls
Richie McIlroy897010b32666
diff --git a/apps/desktop-gpui/src/editor_tabs.rs b/apps/desktop-gpui/src/editor_tabs.rsindex 5a0b24829..2728721d9 100644--- a/apps/desktop-gpui/src/editor_tabs.rs+++ b/apps/desktop-gpui/src/editor_tabs.rs@@ -51,11 +51,12 @@ pub const CAMERA_SHAPES: [(CameraShape, &str); 2] = [(CameraShape::Source, "Source"),];-/// The three `backgroundBlur` rows (`:3078-3082`).-pub const CAMERA_BLUR_MODES: [(BackgroundBlurMode, &str); 3] = [+pub const CAMERA_BLUR_MODES: &[(BackgroundBlurMode, &str)] = &[(BackgroundBlurMode::Off, "Off"),(BackgroundBlurMode::Light, "Light Blur"),(BackgroundBlurMode::Heavy, "Heavy Blur"),+ #[cfg(target_os = "macos")]+ (BackgroundBlurMode::Remove, "Remove Background"),];/// `CORNER_STYLE_OPTIONS` (`:399-402`).@@ -1266,7 +1267,7 @@ impl EditorWindow {}),),))- .child(ui::Subfield::plain(&theme, "Background Blur").child(+ .child(ui::Subfield::plain(&theme, "Background").child(div().w(px(160.)).child(self.menu_select(SidebarMenu::CameraBlur,"camera-blur",@@ -3394,7 +3395,10 @@ mod tests {assert_eq!(KEYBOARD_POSITIONS.len(), 6);assert_eq!(FONT_OPTIONS.len(), 3);assert_eq!(TEXT_WEIGHTS.len(), 3);- assert_eq!(CAMERA_BLUR_MODES.len(), 3);+ assert_eq!(+ CAMERA_BLUR_MODES.len(),+ if cfg!(target_os = "macos") { 4 } else { 3 }+ );// `MODEL_OPTIONS` (`CaptionsTab.tsx:87-116`): two Parakeet entries in// front of the two Whisper ones, so the Intel-macOS slice keeps// exactly the Whisper pair.diff --git a/apps/desktop/src/components/CameraPreviewChrome.tsx b/apps/desktop/src/components/CameraPreviewChrome.tsxindex 2477be89c..b57838a0f 100644--- a/apps/desktop/src/components/CameraPreviewChrome.tsx+++ b/apps/desktop/src/components/CameraPreviewChrome.tsx@@ -1,4 +1,5 @@import { ToggleButton as KToggleButton } from "@kobalte/core/toggle-button";+import { type as ostype } from "@tauri-apps/plugin-os";import { cx } from "cva";import {type ComponentProps,@@ -26,7 +27,14 @@ export const CAMERA_TOOLBAR_HEIGHT = 56;export const CAMERA_WINDOW_STATE_STORAGE_KEY = "cameraWindowState";export const CAMERA_WIDE_ASPECT_RATIO = 16 / 9;-const BLUR_MODES: BackgroundBlurMode[] = ["off", "light", "heavy"];+export const cameraBackgroundOptions = (+ macOS: boolean,+): { name: string; value: BackgroundBlurMode }[] => [+ { name: "Off", value: "off" },+ { name: "Light Blur", value: "light" },+ { name: "Heavy Blur", value: "heavy" },+ ...(macOS ? [{ name: "Remove Background", value: "remove" as const }] : []),+];const RESIZE_CORNERS = ["nw", "ne", "sw", "se"] as const;type ResizeCorner = (typeof RESIZE_CORNERS)[number];@@ -78,12 +86,14 @@ export const normalizeBackgroundBlurMode = (export const cycleBlurMode = (current: BackgroundBlurMode | boolean,+ macOS = false,): BackgroundBlurMode => {if (typeof current === "boolean") {return current ? "heavy" : "light";}- const idx = BLUR_MODES.indexOf(current);- return BLUR_MODES[(idx + 1) % BLUR_MODES.length];+ const modes = cameraBackgroundOptions(macOS).map((option) => option.value);+ const idx = modes.indexOf(current);+ return modes[(idx + 1) % modes.length];};export const blurModeLabel = (mode: BackgroundBlurMode | boolean): string => {@@ -93,6 +103,8 @@ export const blurModeLabel = (mode: BackgroundBlurMode | boolean): string => {return "Light";case "heavy":return "Heavy";+ case "remove":+ return "Cutout";default:return "";}@@ -106,6 +118,7 @@ export const cameraToolbarScale = (size: number) => {};export function cameraBorderRadius(state: CameraWindowState) {+ if (state.backgroundBlur === "remove") return "0px";if (state.shape === "round") return "9999px";const normalized =(clampCameraSize(state.size) - CAMERA_MIN_SIZE) /@@ -182,7 +195,9 @@ export function CameraPreviewToolbar(props: {props.state.backgroundBlur !== false}onClick={() =>- props.setState("backgroundBlur", (mode) => cycleBlurMode(mode))+ props.setState("backgroundBlur", (mode) =>+ cycleBlurMode(mode, ostype() === "macos"),+ )}><div class="relative">diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsxindex a95b1977b..3b4875f00 100644--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx@@ -45,6 +45,7 @@ import {import { createStore, produce } from "solid-js/store";import { Dynamic } from "solid-js/web";import toast from "solid-toast";+import { cameraBackgroundOptions } from "~/components/CameraPreviewChrome";import { Toggle } from "~/components/Toggle";import {animatedGradientsStore,@@ -3257,25 +3258,15 @@ function CameraConfig(props: { scrollRef: HTMLDivElement }) {onChange={(mirror) => setProject("camera", "mirror", mirror)}/></Subfield>- <Subfield name="Background Blur">+ <Subfield name="Background"><KSelect<{ name: string; value: BackgroundBlurMode }>- options={[- { name: "Off", value: "off" },- { name: "Light Blur", value: "light" },- { name: "Heavy Blur", value: "heavy" },- ]}+ options={cameraBackgroundOptions(ostype() === "macos")}optionValue="value"optionTextValue="name"value={- (- [- { name: "Off", value: "off" },- { name: "Light Blur", value: "light" },- { name: "Heavy Blur", value: "heavy" },- ] as const- ).find(- (v) =>- v.value ===+ cameraBackgroundOptions(ostype() === "macos").find(+ (option) =>+ option.value ===(project.camera.backgroundBlur?.mode ?? "off"),) ?? { name: "Off", value: "off" }}diff --git a/apps/desktop/src/utils/camera-background.test.ts b/apps/desktop/src/utils/camera-background.test.tsnew file mode 100644index 000000000..c62d18a8f--- /dev/null+++ b/apps/desktop/src/utils/camera-background.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from "vitest";+import {+ cameraBackgroundOptions,+ cameraBorderRadius,+ cycleBlurMode,+ getDefaultCameraWindowState,+ normalizeBackgroundBlurMode,+} from "../components/CameraPreviewChrome";++describe("camera background effects", () => {+ it("offers removal only on macOS and keeps the existing modes everywhere", () => {+ expect(+ cameraBackgroundOptions(false).map((option) => option.value),+ ).toEqual(["off", "light", "heavy"]);+ expect(cameraBackgroundOptions(true).map((option) => option.value)).toEqual(+ ["off", "light", "heavy", "remove"],+ );+ expect(cycleBlurMode("heavy", true)).toBe("remove");+ expect(cycleBlurMode("remove", true)).toBe("off");+ expect(cycleBlurMode("heavy", false)).toBe("off");+ });++ it("preserves legacy boolean settings", () => {+ expect(normalizeBackgroundBlurMode(true)).toBe("heavy");+ expect(normalizeBackgroundBlurMode(false)).toBe("off");+ expect(normalizeBackgroundBlurMode(undefined)).toBe("off");+ expect(normalizeBackgroundBlurMode("remove")).toBe("remove");+ });++ it("removes the clipping shape without overwriting the stored shape", () => {+ const state = {+ ...getDefaultCameraWindowState(),+ backgroundBlur: "remove" as const,+ };+ expect(cameraBorderRadius(state)).toBe("0px");+ expect(state.shape).toBe("round");+ expect(cameraBorderRadius({ ...state, backgroundBlur: "off" })).toBe(+ "9999px",+ );+ });+});