Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix: PopoverTypes and isScreenSource, isWindowSource

Alan Trebugeaisb8f8d11a9239
diff --git a/src/components/launch/SourceSelector.tsx b/src/components/launch/SourceSelector.tsx
index b0bba991..2b825c4b 100644
--- a/src/components/launch/SourceSelector.tsx
+++ b/src/components/launch/SourceSelector.tsx
@@ -5,7 +5,12 @@ import { useScopedT } from "@/contexts/I18nContext";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
-import { mapRawSource, type DesktopSource, type RawDesktopSource } from "./popovers/launchPopoverTypes";
+import {
+ mapRawSource,
+ isScreenSource,
+ isWindowSource,
+ type DesktopSource,
+} from "./popovers/launchPopoverTypes";
import "./launchTheme.css";
import "./SourceSelector.css";
@@ -212,7 +217,7 @@ export const SourceSelector = React.memo(function SourceSelector({
thumbnailSize: { width: 160, height: 90 },
fetchWindowIcons: true,
});
- setInternalSources(rawSources.map((s) => mapRawSource(s as RawDesktopSource)));
+ setInternalSources(rawSources.map((s) => mapRawSource(s as DesktopSource)));
} catch (error) {
console.error("Failed to fetch sources:", error);
} finally {
@@ -244,11 +249,11 @@ export const SourceSelector = React.memo(function SourceSelector({
// Split sources for internal use
const internalScreenSources = useMemo(
- () => internalSources.filter((s) => s.sourceType === "screen" || s.id.startsWith("screen:")),
+ () => internalSources.filter(isScreenSource),
[internalSources],
);
const internalWindowSources = useMemo(
- () => internalSources.filter((s) => s.sourceType === "window" || s.id.startsWith("window:")),
+ () => internalSources.filter(isWindowSource),
[internalSources],
);
@@ -302,7 +307,7 @@ export const SourceSelector = React.memo(function SourceSelector({
const trigger = children ? (
React.isValidElement(children) ? (
- React.cloneElement(children as React.ReactElement<any>, {
+ React.cloneElement(children as React.ReactElement<React.HTMLAttributes<HTMLElement>>, {
onPointerEnter: prefetchSources,
onFocusCapture: prefetchSources,
})
diff --git a/src/components/launch/popovers/SourcePopover.tsx b/src/components/launch/popovers/SourcePopover.tsx
index 3f82dab8..5459fae1 100644
--- a/src/components/launch/popovers/SourcePopover.tsx
+++ b/src/components/launch/popovers/SourcePopover.tsx
@@ -1,7 +1,12 @@
import { useCallback, useMemo, type ReactNode, useState } from "react";
import { SourceSelector } from "../SourceSelector";
import { useLaunchPopoverCoordinator } from "./LaunchPopoverCoordinator";
-import { mapRawSource, type DesktopSource, type RawDesktopSource } from "./launchPopoverTypes";
+import {
+ mapRawSource,
+ isScreenSource,
+ isWindowSource,
+ type DesktopSource,
+} from "./launchPopoverTypes";
const POPOVER_ID = "sources";
@@ -30,7 +35,7 @@ export function SourcePopover({
thumbnailSize: { width: 160, height: 90 },
fetchWindowIcons: true,
});
- setSources(rawSources.map((s) => mapRawSource(s as RawDesktopSource)));
+ setSources(rawSources.map((s) => mapRawSource(s as DesktopSource)));
} catch (error) {
console.error("Failed to fetch sources:", error);
} finally {
@@ -38,14 +43,8 @@ export function SourcePopover({
}
}, []);
- const screenSources = useMemo(
- () => sources.filter((s) => s.sourceType === "screen" || s.id.startsWith("screen:")),
- [sources],
- );
- const windowSources = useMemo(
- () => sources.filter((s) => s.sourceType === "window" || s.id.startsWith("window:")),
- [sources],
- );
+ const screenSources = useMemo(() => sources.filter(isScreenSource), [sources]);
+ const windowSources = useMemo(() => sources.filter(isWindowSource), [sources]);
return (
<SourceSelector
diff --git a/src/components/launch/popovers/launchPopoverTypes.ts b/src/components/launch/popovers/launchPopoverTypes.ts
index 16dece16..1585aaed 100644
--- a/src/components/launch/popovers/launchPopoverTypes.ts
+++ b/src/components/launch/popovers/launchPopoverTypes.ts
@@ -9,28 +9,31 @@ export interface DesktopSource {
windowTitle?: string;
}
-export interface RawDesktopSource {
- id: string;
- name: string;
- thumbnail: string | null;
- display_id: string;
- appIcon: string | null;
- sourceType?: "screen" | "window";
- appName?: string;
- windowTitle?: string;
+/**
+ * Check if a source is a screen/display
+ */
+export function isScreenSource(s: DesktopSource): boolean {
+ return s.sourceType === "screen" || s.id.startsWith("screen:");
+}
+
+/**
+ * Check if a source is an application window
+ */
+export function isWindowSource(s: DesktopSource): boolean {
+ return s.sourceType === "window" || s.id.startsWith("window:");
}
-export function mapRawSource(s: RawDesktopSource): DesktopSource {
- const isWindow = s.id.startsWith("window:");
+export function mapRawSource(s: DesktopSource): DesktopSource {
+ const isWindow = isWindowSource(s);
const type = s.sourceType ?? (isWindow ? "window" : "screen");
let displayName = s.name;
let appName = s.appName;
- if (isWindow && !appName && s.name.includes(" — ")) {
+ if (isWindow && s.windowTitle) {
+ displayName = s.windowTitle;
+ } else if (isWindow && !appName && s.name.includes(" — ")) {
const parts = s.name.split(" — ");
appName = parts[0]?.trim();
displayName = parts.slice(1).join(" — ").trim() || s.name;
- } else if (isWindow && s.windowTitle) {
- displayName = s.windowTitle;
}
return {
id: s.id,