File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export const CommsContext = React.createContext<any>(null);
18
18
*/
19
19
const CommsContextProvider : React . SFC = React . memo ( ( { children } ) => {
20
20
const [ commsData , setCommsData ] = useState ( [ ] ) ;
21
+ const [ currentApp , setCurrentApp ] = useState ( '' ) ;
21
22
22
23
function tryParseJSON ( jsonString : any ) {
23
24
try {
@@ -32,15 +33,17 @@ const CommsContextProvider: React.SFC = React.memo(({ children }) => {
32
33
}
33
34
34
35
const fetchCommsData = useCallback ( ( app : string , live : boolean ) => {
35
- ipcRenderer . removeAllListeners ( 'commsResponse' ) ;
36
- setCurrentApp ( app ) ;
37
- ipcRenderer . send ( 'commsRequest' ) ;
38
- ipcRenderer . on ( 'commsResponse' , ( event : Electron . Event , data : any ) => {
39
- let result : any ;
40
- if ( tryParseJSON ( data ) ) result = JSON . parse ( data ) ;
41
- setCommsData ( result ) ;
42
- } ) ;
43
- // }
36
+
37
+ if ( app !== currentApp || live ) {
38
+ ipcRenderer . removeAllListeners ( 'commsResponse' ) ;
39
+ setCurrentApp ( app ) ;
40
+ ipcRenderer . send ( 'commsRequest' ) ;
41
+ ipcRenderer . on ( 'commsResponse' , ( event : Electron . Event , data : any ) => {
42
+ let result : any ;
43
+ if ( tryParseJSON ( data ) ) result = JSON . parse ( data ) ;
44
+ setCommsData ( result ) ;
45
+ } ) ;
46
+ }
44
47
} , [ ] ) ;
45
48
46
49
return (
You can’t perform that action at this time.
0 commit comments