-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ErrorBoundaryMain add error boundary for main process * remove error test remove error test * throw an error throw an error for demonstration purpose * add IPC error handler add IPC error handler * handle fetchedApps undefined handle fetchedApps undefined
- Loading branch information
1 parent
66cdbd8
commit 72386c5
Showing
5 changed files
with
107 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect } from 'react'; | ||
import { showSnackbar } from 'renderer/store/snackbar'; | ||
import { useAppDispatch } from 'renderer/utils/hooks'; | ||
|
||
// Global variable to check if the listener has already been attached | ||
let hasListenerBeenAttached = false; | ||
|
||
function useErrorBoundaryMain() { | ||
const dispatch = useAppDispatch(); | ||
|
||
useEffect(() => { | ||
if (hasListenerBeenAttached) { | ||
// If the listener is already attached, no need to attach it again | ||
return; | ||
} | ||
|
||
function handleUnhandledError(message: any) { | ||
console.error('Unhandled error from main process:', message); | ||
dispatch(showSnackbar('Something went wrong')); | ||
} | ||
|
||
window.electron.ipcRenderer.onUnhandledError(handleUnhandledError); | ||
hasListenerBeenAttached = true; | ||
|
||
return () => { //clean mount | ||
window.electron.ipcRenderer.offUnhandledError(handleUnhandledError); | ||
}; | ||
}, [dispatch]); | ||
} | ||
|
||
export default useErrorBoundaryMain; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters