Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private AutosaveManager(BibDatabaseContext bibDatabaseContext, CoarseChangeFilte
this.executor.scheduleAtFixedRate(
() -> {
if (needsSave) {
eventBus.post(new AutosaveEvent());
needsSave = false;
eventBus.post(new AutosaveEvent());
needsSave = false;
}
},
DELAY_BETWEEN_AUTOSAVE_ATTEMPTS_IN_SECONDS,
Expand All @@ -61,7 +61,11 @@ public void listen(@SuppressWarnings("unused") BibDatabaseContextChangedEvent ev
}

private void shutdown() {
coarseChangeFilter.unregisterListener(this);
try {
coarseChangeFilter.unregisterListener(this);
} catch (IllegalArgumentException e) {
// ignore exception if the listener was not registered before
}
runningInstances.remove(this);
}

Expand All @@ -83,7 +87,7 @@ public static AutosaveManager start(BibDatabaseContext bibDatabaseContext, Coars
*/
public static void shutdown(BibDatabaseContext bibDatabaseContext) {
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).findAny()
.ifPresent(instance -> instance.shutdown());
.ifPresent(AutosaveManager::shutdown);
}

public void registerListener(Object listener) {
Expand Down
Loading