MCPcopy Create free account
hub / github.com/Roy3838/Observer / ScreenSelectorWindow

Function ScreenSelectorWindow

app/src/desktop/ScreenSelectorWindow.tsx:19–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17}
18
19export default function ScreenSelectorWindow() {
20 const [targets, setTargets] = useState<CaptureTarget[]>([]);
21 const [loading, setLoading] = useState(true);
22 const [error, setError] = useState<string | null>(null);
23 const [selectedTarget, setSelectedTarget] = useState<string | null>(null);
24 const [starting, setStarting] = useState(false);
25
26 // Load targets - only called when window becomes visible
27 const loadTargets = useCallback(async () => {
28 setLoading(true);
29 setError(null);
30 try {
31 // Non-ACL-gated app-command wrapper (see sc_get_capture_targets in lib.rs).
32 const targetsResult = await invoke<CaptureTarget[]>('sc_get_capture_targets', {
33 includeThumbnails: true
34 });
35 setTargets(targetsResult);
36 } catch (e) {
37 console.error('Failed to load capture targets:', e);
38 const message = e instanceof Error ? e.message : String(e);
39 setError(message);
40 // Propagate the real error to the awaiting main-window request so it isn't
41 // misreported as a user cancellation. Uses a plain app command (not the
42 // ACL-gated event plugin) to dodge the Linux capability-binding race.
43 await invoke('report_target_selection_error', { message });
44 } finally {
45 setLoading(false);
46 }
47 }, []);
48
49 // Only load targets when window becomes visible (not on mount)
50 // This prevents permission prompts at app startup
51 useEffect(() => {
52 let mounted = true;
53
54 const checkVisibilityAndLoad = async () => {
55 try {
56 const currentWindow = getCurrentWindow();
57 const isVisible = await currentWindow.isVisible();
58 if (isVisible && mounted) {
59 loadTargets();
60 }
61 } catch (e) {
62 console.error('Failed to check window visibility:', e);
63 }
64 };
65
66 // Check immediately
67 checkVisibilityAndLoad();
68
69 // Also listen for window focus events (when window is shown)
70 const setupListener = async () => {
71 const currentWindow = getCurrentWindow();
72 const unlisten = await currentWindow.onFocusChanged(({ payload: focused }) => {
73 if (focused && mounted) {
74 loadTargets();
75 }
76 });

Callers

nothing calls this directly

Calls 6

checkVisibilityAndLoadFunction · 0.85
setupListenerFunction · 0.85
handleSelectFunction · 0.85
errorMethod · 0.80
filterMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected