mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 18:51:26 +00:00
Add timeout to periodic missing vaults check
This commit is contained in:
@@ -23,7 +23,8 @@ public class AutoUnlocker {
|
||||
private final ObservableList<Vault> vaults;
|
||||
private final FxApplicationWindows appWindows;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private ScheduledFuture<?> future;
|
||||
private ScheduledFuture<?> checkFuture;
|
||||
private ScheduledFuture<?> timeoutFuture;
|
||||
private boolean isPeriodicCheckActive = false;
|
||||
|
||||
@Inject
|
||||
@@ -47,12 +48,13 @@ public class AutoUnlocker {
|
||||
public void startMissingVaultsChecker() {
|
||||
if (!isPeriodicCheckActive && getMissingAutoUnlockVaults().count() > 0) {
|
||||
LOG.info("Found MISSING vaults, starting periodic check");
|
||||
future = scheduler.scheduleWithFixedDelay(this::tick, 0, 1, TimeUnit.SECONDS);
|
||||
checkFuture = scheduler.scheduleWithFixedDelay(this::check, 0, 1, TimeUnit.SECONDS);
|
||||
timeoutFuture = scheduler.schedule(this::timeout, 2, TimeUnit.MINUTES);
|
||||
isPeriodicCheckActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
private void check() {
|
||||
// Find the vaults that are missing but have an existing directory
|
||||
Vault[] vaultArray = getMissingAutoUnlockVaults().filter(v -> v.getPath().toFile().isDirectory()).toArray(Vault[]::new);
|
||||
if (vaultArray.length > 0) {
|
||||
@@ -71,10 +73,17 @@ public class AutoUnlocker {
|
||||
if (getMissingAutoUnlockVaults().count() == 0) {
|
||||
LOG.info("No more MISSING vaults, stopping periodic check");
|
||||
isPeriodicCheckActive = false;
|
||||
future.cancel(false);
|
||||
checkFuture.cancel(false);
|
||||
timeoutFuture.cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void timeout() {
|
||||
LOG.info("MISSING vaults periodic check timed out");
|
||||
isPeriodicCheckActive = false;
|
||||
checkFuture.cancel(false);
|
||||
}
|
||||
|
||||
private Stream<Vault> getMissingAutoUnlockVaults() {
|
||||
return vaults.stream()
|
||||
.filter(Vault::isMissing)
|
||||
|
||||
Reference in New Issue
Block a user