mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-27 00:05:39 +00:00
fix: PopoverTypes and isScreenSource, isWindowSource
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:");
|
||||
}
|
||||
|
||||
export function mapRawSource(s: RawDesktopSource): DesktopSource {
|
||||
const isWindow = s.id.startsWith("window:");
|
||||
/**
|
||||
* 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: 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,
|
||||
|
||||
Reference in New Issue
Block a user