11import { ipcRenderer } from 'electron' ;
2- import { type MouseEventHandler , useEffect , useState } from 'react' ;
2+ import { type MouseEventHandler , useState } from 'react' ;
33import {
44 type WrappedComponentProps ,
55 defineMessages ,
@@ -54,12 +54,6 @@ function MediaSource(props: IProps) {
5454 const [ trackerId , setTrackerId ] = useState < string | null > ( null ) ;
5555 const [ loadingSources , setLoadingSources ] = useState < boolean > ( false ) ;
5656
57- ipcRenderer . on ( `select-capture-device:${ service . id } ` , ( _event , data ) => {
58- if ( loadingSources ) return ;
59- setShow ( true ) ;
60- setTrackerId ( data . trackerId ) ;
61- } ) ;
62-
6357 const handleOnClick = ( e : any ) => {
6458 const { id } = e . currentTarget . dataset ;
6559 window [ 'ferdium' ] . actions . service . sendIPCMessage ( {
@@ -75,35 +69,35 @@ function MediaSource(props: IProps) {
7569 setTrackerId ( null ) ;
7670 } ;
7771
78- // biome-ignore lint/correctness/useExhaustiveDependencies: This effect should only run when `show` changes
79- useEffect ( ( ) => {
80- if ( show ) {
81- setLoadingSources ( true ) ;
82- ipcRenderer
83- . invoke ( 'get-desktop-capturer-sources' )
84- . then ( sources => {
85- if ( isWayland ) {
86- // On Linux, we do not need to prompt the user again for the source
87- handleOnClick ( {
88- currentTarget : { dataset : { id : sources [ 0 ] . id } } ,
89- } ) ;
90- return ;
91- }
72+ const showCaptureSources = ( ) => {
73+ setLoadingSources ( true ) ;
74+ ipcRenderer
75+ . invoke ( 'get-desktop-capturer-sources' )
76+ . then ( sources => {
77+ if ( isWayland ) {
78+ // On Linux, we do not need to prompt the user again for the source
79+ handleOnClick ( {
80+ currentTarget : { dataset : { id : sources [ 0 ] . id } } ,
81+ } ) ;
82+ return ;
83+ }
9284
93- setSources ( sources ) ;
94- setLoadingSources ( false ) ;
95- } )
96- // silence the error
97- . catch ( ( ) => {
98- setShow ( false ) ;
99- setSources ( [ ] ) ;
100- setLoadingSources ( false ) ;
101- } ) ;
102- } else {
103- setSources ( [ ] ) ;
104- setLoadingSources ( false ) ;
105- }
106- } , [ show ] ) ;
85+ setSources ( sources ) ;
86+ setLoadingSources ( false ) ;
87+ } )
88+ // silence the error
89+ . catch ( ( ) => {
90+ setShow ( false ) ;
91+ setSources ( [ ] ) ;
92+ setLoadingSources ( false ) ;
93+ } ) ;
94+ } ;
95+
96+ ipcRenderer . on ( `select-capture-device:${ service . id } ` , ( _event , data ) => {
97+ if ( loadingSources ) return ;
98+ showCaptureSources ( ) ;
99+ setTrackerId ( data . trackerId ) ;
100+ } ) ;
107101
108102 if ( ! show ) {
109103 return null ;
0 commit comments