From 486665191396674e6fd644e6a8de448bbaf606e2 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 22 Mar 2023 17:59:10 +0530 Subject: [PATCH] add error handling to continuousExport toggle functions --- src/components/ExportModal.tsx | 15 ++++++----- src/services/exportService.ts | 49 +++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/components/ExportModal.tsx b/src/components/ExportModal.tsx index e264720ed..ffc29cf3f 100644 --- a/src/components/ExportModal.tsx +++ b/src/components/ExportModal.tsx @@ -84,13 +84,14 @@ export default function ExportModal(props: Props) { }, []); useEffect(() => { - if (!isElectron()) { - return; - } - if (continuousExport) { - exportService.enableContinuousExport(startExport); - } else { - exportService.disableContinuousExport(); + try { + if (continuousExport) { + exportService.enableContinuousExport(startExport); + } else { + exportService.disableContinuousExport(); + } + } catch (e) { + logError(e, 'error handling continuousExport change'); } }, [continuousExport]); diff --git a/src/services/exportService.ts b/src/services/exportService.ts index 9079fb35c..41de5d9b3 100644 --- a/src/services/exportService.ts +++ b/src/services/exportService.ts @@ -77,32 +77,43 @@ class ExportService { } enableContinuousExport(startExport: () => void) { - if (this.continuousExportEventListener) { - return; - } - startExport(); - this.continuousExportEventListener = () => { - addLogLine('continuous export triggered'); - if (this.exportInProgress) { - addLogLine('export in progress, skipping'); + try { + if (this.continuousExportEventListener) { return; } startExport(); - }; - eventBus.addListener( - Events.LOCAL_FILES_UPDATED, - this.continuousExportEventListener - ); + this.continuousExportEventListener = () => { + addLogLine('continuous export triggered'); + if (this.exportInProgress) { + addLogLine('export in progress, skipping'); + return; + } + startExport(); + }; + eventBus.addListener( + Events.LOCAL_FILES_UPDATED, + this.continuousExportEventListener + ); + } catch (e) { + logError(e, 'failed to enableContinuousExport '); + throw e; + } } disableContinuousExport() { - if (!this.continuousExportEventListener) { - return; + try { + if (!this.continuousExportEventListener) { + return; + } + eventBus.removeListener( + Events.LOCAL_FILES_UPDATED, + this.continuousExportEventListener + ); + this.continuousExportEventListener = null; + } catch (e) { + logError(e, 'failed to disableContinuousExport'); + throw e; } - eventBus.removeListener( - Events.LOCAL_FILES_UPDATED, - this.continuousExportEventListener - ); } stopRunningExport() {