mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-19 13:46:04 +00:00
only check for updates automatically if set so in preferences
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.Optional;
|
||||
public class UpdateChecker {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UpdateChecker.class);
|
||||
private static final Duration AUTOCHECK_DELAY = Duration.seconds(5);
|
||||
|
||||
private final Settings settings;
|
||||
private final Optional<String> applicationVersion;
|
||||
@@ -36,7 +37,17 @@ public class UpdateChecker {
|
||||
this.updateCheckerService = updateCheckerService;
|
||||
}
|
||||
|
||||
public void startCheckingForUpdates(Duration initialDelay) {
|
||||
public void automaticallyCheckForUpdatesIfEnabled() {
|
||||
if (settings.checkForUpdates().get()) {
|
||||
startCheckingForUpdates(AUTOCHECK_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForUpdatesNow() {
|
||||
startCheckingForUpdates(Duration.ZERO);
|
||||
}
|
||||
|
||||
private void startCheckingForUpdates(Duration initialDelay) {
|
||||
updateCheckerService.setDelay(initialDelay);
|
||||
updateCheckerService.setOnRunning(this::checkStarted);
|
||||
updateCheckerService.setOnSucceeded(this::checkSucceeded);
|
||||
|
||||
@@ -2,17 +2,15 @@ package org.cryptomator.ui.fxapp;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.ObjectBinding;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.concurrent.Worker;
|
||||
import javafx.util.Duration;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
|
||||
import javax.inject.Named;
|
||||
import java.net.URI;
|
||||
@@ -36,22 +34,34 @@ public abstract class UpdateCheckerModule {
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
static HttpClient providesHttpClient() {
|
||||
static HttpClient provideHttpClient() {
|
||||
return HttpClient.newHttpClient();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
static HttpRequest providesCheckForUpdatesRequest(@Named("applicationVersion") Optional<String> applicationVersion) {
|
||||
String userAgent = String.format("Cryptomator VersionChecker/%s %s %s (%s)", applicationVersion.orElse("SNAPSHOT"), SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH);
|
||||
static HttpRequest provideCheckForUpdatesRequest(@Named("applicationVersion") Optional<String> applicationVersion) {
|
||||
String userAgent = String.format("Cryptomator VersionChecker/%s %s %s (%s)", //
|
||||
applicationVersion.orElse("SNAPSHOT"), //
|
||||
SystemUtils.OS_NAME, //
|
||||
SystemUtils.OS_VERSION, //
|
||||
SystemUtils.OS_ARCH); //
|
||||
return HttpRequest.newBuilder() //
|
||||
.uri(LATEST_VERSION_URI) //
|
||||
.header("User-Agent", userAgent).build();
|
||||
.header("User-Agent", userAgent) //
|
||||
.build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("checkForUpdatesInterval")
|
||||
@FxApplicationScoped
|
||||
static ObjectBinding<Duration> provideCheckForUpdateInterval(Settings settings) {
|
||||
return Bindings.when(settings.checkForUpdates()).then(UPDATE_CHECK_INTERVAL).otherwise(Duration.INDEFINITE);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
static ScheduledService<String> provideCheckForUpdatesService(ExecutorService executor, HttpClient httpClient, HttpRequest checkForUpdatesRequest) {
|
||||
static ScheduledService<String> provideCheckForUpdatesService(ExecutorService executor, HttpClient httpClient, HttpRequest checkForUpdatesRequest, @Named("checkForUpdatesInterval") ObjectBinding<Duration> period) {
|
||||
ScheduledService<String> service = new ScheduledService<>() {
|
||||
@Override
|
||||
protected Task<String> createTask() {
|
||||
@@ -59,7 +69,7 @@ public abstract class UpdateCheckerModule {
|
||||
}
|
||||
};
|
||||
service.setExecutor(executor);
|
||||
service.setPeriod(UPDATE_CHECK_INTERVAL);
|
||||
service.periodProperty().bind(period);
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.concurrent.CountDownLatch;
|
||||
public class MainWindowController implements FxController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MainWindowController.class);
|
||||
private static final Duration CHECK_FOR_UPDATES_DELAY = Duration.seconds(5);
|
||||
|
||||
private final Stage window;
|
||||
private final FxApplication application;
|
||||
@@ -57,7 +56,7 @@ public class MainWindowController implements FxController {
|
||||
window.setWidth(event.getSceneX());
|
||||
window.setHeight(event.getSceneY());
|
||||
});
|
||||
updateChecker.startCheckingForUpdates(CHECK_FOR_UPDATES_DELAY);
|
||||
updateChecker.automaticallyCheckForUpdatesIfEnabled();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class UpdatesPreferencesController implements FxController {
|
||||
|
||||
@FXML
|
||||
public void checkNow() {
|
||||
updateChecker.startCheckingForUpdates(Duration.ZERO);
|
||||
updateChecker.checkForUpdatesNow();
|
||||
}
|
||||
|
||||
/* Observable Properties */
|
||||
|
||||
Reference in New Issue
Block a user