Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

Merge main into PR #186 and resolve SourceSelector conflict

Siddharth9687157abafc
diff --cc src/components/launch/SourceSelector.tsx
index 741656073,43feeafae..0d94efacc
--- a/src/components/launch/SourceSelector.tsx
+++ b/src/components/launch/SourceSelector.tsx
@@@ -14,146 -13,146 +13,149 @@@ interface DesktopSource
}
export function SourceSelector() {
- const [sources, setSources] = useState<DesktopSource[]>([]);
- const [selectedSource, setSelectedSource] = useState<DesktopSource | null>(null);
- const [loading, setLoading] = useState(true);
+ const [sources, setSources] = useState<DesktopSource[]>([]);
+ const [selectedSource, setSelectedSource] = useState<DesktopSource | null>(null);
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ async function fetchSources() {
+ setLoading(true);
+ try {
+ const rawSources = await window.electronAPI.getSources({
+ types: ["screen", "window"],
+ thumbnailSize: { width: 320, height: 180 },
+ fetchWindowIcons: true,
+ });
+ setSources(
+ rawSources.map((source) => ({
+ id: source.id,
+ name:
+ source.id.startsWith("window:") && source.name.includes(" — ")
+ ? source.name.split(" — ")[1] || source.name
+ : source.name,
+ thumbnail: source.thumbnail,
+ display_id: source.display_id,
+ appIcon: source.appIcon,
+ })),
+ );
+ } catch (error) {
+ console.error("Error loading sources:", error);
+ } finally {
+ setLoading(false);
+ }
+ }
+ fetchSources();
+ }, []);
- useEffect(() => {
- async function fetchSources() {
- setLoading(true);
- try {
- const rawSources = await window.electronAPI.getSources({
- types: ['screen', 'window'],
- thumbnailSize: { width: 320, height: 180 },
- fetchWindowIcons: true
- });
- setSources(
- rawSources.map(source => ({
- id: source.id,
- name:
- source.id.startsWith('window:') && source.name.includes(' — ')
- ? source.name.split(' — ')[1] || source.name
- : source.name,
- thumbnail: source.thumbnail,
- display_id: source.display_id,
- appIcon: source.appIcon
- }))
- );
- } catch (error) {
- console.error('Error loading sources:', error);
- } finally {
- setLoading(false);
- }
- }
- fetchSources();
- }, []);
+ const screenSources = sources.filter((s) => s.id.startsWith("screen:"));
+ const windowSources = sources.filter((s) => s.id.startsWith("window:"));
- const screenSources = sources.filter(s => s.id.startsWith('screen:'));
- const windowSources = sources.filter(s => s.id.startsWith('window:'));
+ const handleSourceSelect = (source: DesktopSource) => setSelectedSource(source);
+ const handleShare = async () => {
+ if (selectedSource) await window.electronAPI.selectSource(selectedSource);
+ };
- const handleSourceSelect = (source: DesktopSource) => setSelectedSource(source);
- const handleShare = async () => {
- if (selectedSource) await window.electronAPI.selectSource(selectedSource);
- };
+ if (loading) {
+ return (
+ <div
+ className={`h-full flex items-center justify-center ${styles.glassContainer}`}
+ style={{ minHeight: "100vh" }}
+ >
+ <div className="text-center">
+ <div className="animate-spin rounded-full h-6 w-6 border-b-2 border-[#34B27B] mx-auto mb-2" />
+ <p className="text-xs text-zinc-400">Loading sources...</p>
+ </div>
+ </div>
+ );
+ }
- if (loading) {
- return (
- <div className={`h-full flex items-center justify-center ${styles.glassContainer}`} style={{ minHeight: '100vh' }}>
- <div className="text-center">
- <div className="animate-spin rounded-full h-6 w-6 border-b-2 border-zinc-600 mx-auto mb-2" />
- <p className="text-xs text-zinc-300">Loading sources...</p>
- </div>
- </div>
- );
- }
+ const renderSourceCard = (source: DesktopSource) => {
+ const isSelected = selectedSource?.id === source.id;
+ return (
+ <div
+ key={source.id}
+ className={`${styles.sourceCard} ${isSelected ? styles.selected : ""} p-2`}
+ onClick={() => handleSourceSelect(source)}
+ >
+ <div className="relative mb-1.5">
+ <img
+ src={source.thumbnail || ""}
+ alt={source.name}
+ className="w-full aspect-video object-cover rounded-lg"
+ />
+ {isSelected && (
+ <div className="absolute -top-1.5 -right-1.5">
+ <div className={styles.checkBadge}>
+ <MdCheck size={12} className="text-white" />
+ </div>
+ </div>
+ )}
+ </div>
+ <div className="flex items-center gap-1.5">
+ {source.appIcon && (
+ <img src={source.appIcon} alt="" className={`${styles.icon} flex-shrink-0`} />
+ )}
+ <div className={`${styles.name} truncate`}>{source.name}</div>
+ </div>
+ </div>
+ );
+ };
- return (
- <div className={`min-h-screen flex flex-col items-center justify-center ${styles.glassContainer}`}>
- <div className="flex-1 flex flex-col w-full max-w-xl" style={{ padding: 0 }}>
- <Tabs defaultValue={screenSources.length === 0 ? "windows" : "screens"}>
- <TabsList className="grid grid-cols-2 mb-3 bg-zinc-900/40 rounded-full">
- <TabsTrigger value="screens" className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-zinc-200 rounded-full text-xs py-1">Screens ({screenSources.length})</TabsTrigger>
- <TabsTrigger value="windows" className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-zinc-200 rounded-full text-xs py-1">Windows ({windowSources.length})</TabsTrigger>
- </TabsList>
- <div className="h-72 flex flex-col justify-stretch">
- <TabsContent value="screens" className="h-full">
- <div className={`grid grid-cols-2 gap-2 h-full overflow-y-auto pr-1 relative ${styles.sourceGridScroll}`}>
- {screenSources.map(source => (
- <Card
- key={source.id}
- className={`${styles.sourceCard} ${selectedSource?.id === source.id ? styles.selected : ''} cursor-pointer h-fit p-2 scale-95`}
- style={{ margin: 8, width: '90%', maxWidth: 220 }}
- onClick={() => handleSourceSelect(source)}
- >
- <div className="p-1">
- <div className="relative mb-1">
- <img
- src={source.thumbnail || ''}
- alt={source.name}
- className="w-full aspect-video object-cover rounded border border-zinc-800"
- />
- {selectedSource?.id === source.id && (
- <div className="absolute -top-1 -right-1">
- <div className="w-4 h-4 bg-[#34B27B] rounded-full flex items-center justify-center shadow-md">
- <MdCheck className={styles.icon} />
- </div>
- </div>
- )}
- </div>
- <div className={styles.name + " truncate"}>{source.name}</div>
- </div>
- </Card>
- ))}
- </div>
- </TabsContent>
- <TabsContent value="windows" className="h-full">
- <div className={`grid grid-cols-2 gap-2 h-full overflow-y-auto pr-1 relative ${styles.sourceGridScroll}`}>
- {windowSources.map(source => (
- <Card
- key={source.id}
- className={`${styles.sourceCard} ${selectedSource?.id === source.id ? styles.selected : ''} cursor-pointer h-fit p-2 scale-95`}
- style={{ margin: 8, width: '90%', maxWidth: 220 }}
- onClick={() => handleSourceSelect(source)}
- >
- <div className="p-1">
- <div className="relative mb-1">
- <img
- src={source.thumbnail || ''}
- alt={source.name}
- className="w-full aspect-video object-cover rounded border border-gray-700"
- />
- {selectedSource?.id === source.id && (
- <div className="absolute -top-1 -right-1">
- <div className="w-4 h-4 bg-blue-600 rounded-full flex items-center justify-center shadow-md">
- <MdCheck className={styles.icon} />
- </div>
- </div>
- )}
- </div>
- <div className="flex items-center gap-1">
- {source.appIcon && (
- <img
- src={source.appIcon}
- alt="App icon"
- className={styles.icon + " flex-shrink-0"}
- />
- )}
- <div className={styles.name + " truncate"}>{source.name}</div>
- </div>
- </div>
- </Card>
- ))}
- </div>
- </TabsContent>
- </div>
- </Tabs>
- </div>
- <div className="border-t border-zinc-800 p-2 w-full max-w-xl">
- <div className="flex justify-center gap-2">
- <Button variant="outline" onClick={() => window.close()} className="px-4 py-1 text-xs bg-zinc-800 border-zinc-700 text-zinc-200 hover:bg-zinc-700">Cancel</Button>
- <Button onClick={handleShare} disabled={!selectedSource} className="px-4 py-1 text-xs bg-[#34B27B] text-white hover:bg-[#34B27B]/80 disabled:opacity-50 disabled:bg-zinc-700">Share</Button>
- </div>
- </div>
- </div>
- );
+ return (
+ <div className={`min-h-screen flex flex-col ${styles.glassContainer}`}>
+ <div className="flex-1 flex flex-col w-full px-4 pt-4">
- <Tabs defaultValue="screens" className="flex-1 flex flex-col">
++ <Tabs
++ defaultValue={screenSources.length === 0 ? "windows" : "screens"}
++ className="flex-1 flex flex-col"
++ >
+ <TabsList className="grid grid-cols-2 mb-3 bg-white/5 rounded-full">
+ <TabsTrigger
+ value="screens"
+ className="data-[state=active]:bg-white/15 data-[state=active]:text-white text-zinc-400 rounded-full text-xs py-1 transition-all"
+ >
- Screens
++ Screens ({screenSources.length})
+ </TabsTrigger>
+ <TabsTrigger
+ value="windows"
+ className="data-[state=active]:bg-white/15 data-[state=active]:text-white text-zinc-400 rounded-full text-xs py-1 transition-all"
+ >
- Windows
++ Windows ({windowSources.length})
+ </TabsTrigger>
+ </TabsList>
+ <div className="flex-1 min-h-0">
+ <TabsContent value="screens" className="h-full mt-0">
+ <div
+ className={`grid grid-cols-2 gap-3 h-[280px] overflow-y-auto pr-1 auto-rows-min ${styles.sourceGridScroll}`}
+ >
+ {screenSources.map(renderSourceCard)}
+ </div>
+ </TabsContent>
+ <TabsContent value="windows" className="h-full mt-0">
+ <div
+ className={`grid grid-cols-2 gap-3 h-[280px] overflow-y-auto pr-1 auto-rows-min ${styles.sourceGridScroll}`}
+ >
+ {windowSources.map(renderSourceCard)}
+ </div>
+ </TabsContent>
+ </div>
+ </Tabs>
+ </div>
+ <div className="p-3 flex justify-center gap-2">
+ <Button
+ variant="ghost"
+ onClick={() => window.close()}
+ className="px-5 py-1 text-xs text-zinc-400 hover:text-white hover:bg-white/5 rounded-full"
+ >
+ Cancel
+ </Button>
+ <Button
+ onClick={handleShare}
+ disabled={!selectedSource}
+ className="px-5 py-1 text-xs bg-[#34B27B] text-white hover:bg-[#34B27B]/80 disabled:opacity-30 disabled:bg-zinc-700 rounded-full"
+ >
+ Share
+ </Button>
+ </div>
+ </div>
+ );
}