add error handling to continuousExport toggle functions

This commit is contained in:
Abhinav 2023-03-22 17:59:10 +05:30
parent 8f14580bb5
commit 4866651913
2 changed files with 38 additions and 26 deletions

View file

@ -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]);

View file

@ -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() {