mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 08:41:28 +00:00
Correlate with API as suggested in a separate PoC: UpdateMechanism and UpdateProcess
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.cryptomator.common.updates;
|
||||
|
||||
import org.cryptomator.integrations.common.DistributionChannel;
|
||||
import org.cryptomator.integrations.common.DisplayName;
|
||||
import org.cryptomator.integrations.update.UpdateService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -12,6 +12,7 @@ import java.util.Optional;
|
||||
public class AppUpdateChecker {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppUpdateChecker.class);
|
||||
private static final String DISPLAY_NAME_FLATPAK = "Update via Flatpak update";
|
||||
private final List<UpdateService> updateServices;
|
||||
|
||||
@Inject
|
||||
@@ -25,7 +26,7 @@ public class AppUpdateChecker {
|
||||
}
|
||||
switch (buildNumber.get()) {
|
||||
case "flatpak-1" -> {
|
||||
return !updateServices.isEmpty() && doServicesContainChannel(updateServices, DistributionChannel.Value.LINUX_FLATPAK);
|
||||
return !updateServices.isEmpty() && doServicesContainChannel(updateServices, DISPLAY_NAME_FLATPAK);
|
||||
}
|
||||
|
||||
default -> {
|
||||
@@ -35,43 +36,43 @@ public class AppUpdateChecker {
|
||||
}
|
||||
}
|
||||
|
||||
public Object getUpdater(DistributionChannel.Value channel) {
|
||||
public Object getUpdater(Optional<String> buildNumber) {
|
||||
if (updateServices.isEmpty()) {
|
||||
LOG.error("No UpdateService found");
|
||||
return null;
|
||||
}
|
||||
switch (channel) {
|
||||
case LINUX_FLATPAK -> {
|
||||
var flatpakService = getServiceForChannel(updateServices, DistributionChannel.Value.LINUX_FLATPAK);
|
||||
switch (buildNumber.get()) {
|
||||
case "flatpak-1" -> {
|
||||
var flatpakService = getServiceForChannel(updateServices, DISPLAY_NAME_FLATPAK);
|
||||
if(null == flatpakService) {
|
||||
LOG.error("Required service for channel LINUX_FLATPAK not available");
|
||||
return null;
|
||||
} else {
|
||||
return flatpakService.getLatestReleaseChecker(DistributionChannel.Value.LINUX_FLATPAK);
|
||||
return flatpakService.getLatestReleaseChecker();
|
||||
}
|
||||
}
|
||||
default -> throw new IllegalStateException("Unexpected value 'channel': " + channel);
|
||||
default -> throw new IllegalStateException("Unexpected value 'buildNumber': " + buildNumber.get());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doServicesContainChannel(List<UpdateService> services, DistributionChannel.Value requiredChannel) {
|
||||
private boolean doServicesContainChannel(List<UpdateService> services, String displayName) {
|
||||
return services.stream().anyMatch(service -> {
|
||||
DistributionChannel annotation = service.getClass().getAnnotation(DistributionChannel.class);
|
||||
return annotation != null && annotation.value() == requiredChannel;
|
||||
DisplayName annotation = service.getClass().getAnnotation(DisplayName.class);
|
||||
return annotation != null && annotation.value().equals(displayName);
|
||||
});
|
||||
}
|
||||
|
||||
private UpdateService getServiceForChannel(List<UpdateService> services, DistributionChannel.Value requiredChannel) {
|
||||
private UpdateService getServiceForChannel(List<UpdateService> services, String displayName) {
|
||||
return services.stream().filter(service -> {
|
||||
DistributionChannel annotation = service.getClass().getAnnotation(DistributionChannel.class);
|
||||
return annotation != null && annotation.value() == requiredChannel;
|
||||
DisplayName annotation = service.getClass().getAnnotation(DisplayName.class);
|
||||
return annotation != null && annotation.value().equals(displayName);
|
||||
}).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public UpdateService getServiceForChannel(DistributionChannel.Value requiredChannel) {
|
||||
public UpdateService getServiceForChannel(String displayName) {
|
||||
return updateServices.stream().filter(service -> {
|
||||
DistributionChannel annotation = service.getClass().getAnnotation(DistributionChannel.class);
|
||||
return annotation != null && annotation.value() == requiredChannel;
|
||||
DisplayName annotation = service.getClass().getAnnotation(DisplayName.class);
|
||||
return annotation != null && annotation.value().equals(displayName);
|
||||
}).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.common.SemVerComparator;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.updates.AppUpdateChecker;
|
||||
import org.cryptomator.integrations.common.DistributionChannel;
|
||||
import org.cryptomator.integrations.update.Progress;
|
||||
import org.cryptomator.integrations.update.ProgressListener;
|
||||
import org.cryptomator.integrations.update.UpdateFailedException;
|
||||
@@ -35,6 +34,7 @@ public class UpdateChecker {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UpdateChecker.class);
|
||||
private static final Duration AUTO_CHECK_DELAY = Duration.seconds(5);
|
||||
private static final String DISPLAY_NAME_FLATPAK = "Update via Flatpak update";
|
||||
|
||||
private final Environment env;
|
||||
private final Settings settings;
|
||||
@@ -80,7 +80,7 @@ public class UpdateChecker {
|
||||
private void decideOnUpdateChecker() {
|
||||
if (updateChecker.isUpdateServiceAvailable(env.getBuildNumber())) { // prefer AppUpdateChecker
|
||||
switch (env.getBuildNumber().get()) {
|
||||
case "flatpak-1" -> startCheckingWithFlatpakUpdater((UpdateCheckerTask) updateChecker.getUpdater(DistributionChannel.Value.LINUX_FLATPAK), Duration.ZERO);
|
||||
case "flatpak-1" -> startCheckingWithFlatpakUpdater((UpdateCheckerTask) updateChecker.getUpdater(env.getBuildNumber()), Duration.ZERO);
|
||||
default -> LOG.error("Unexpected value 'buildNumber': {}", env.getBuildNumber().get());
|
||||
}
|
||||
} else { // fallback is the "redirect user to website" approach
|
||||
@@ -89,12 +89,12 @@ public class UpdateChecker {
|
||||
}
|
||||
|
||||
public void updateAppNow() throws UpdateFailedException {
|
||||
var service = updateChecker.getServiceForChannel(DistributionChannel.Value.LINUX_FLATPAK);
|
||||
var service = updateChecker.getServiceForChannel(DISPLAY_NAME_FLATPAK);
|
||||
service.triggerUpdate();
|
||||
}
|
||||
|
||||
public void terminateFlatpakOnUpdateCompleted(Runnable onComplete, UpdatesPreferencesController controller) {
|
||||
var service = updateChecker.getServiceForChannel(DistributionChannel.Value.LINUX_FLATPAK);
|
||||
var service = updateChecker.getServiceForChannel(DISPLAY_NAME_FLATPAK);
|
||||
service.addProgressListener(new ProgressListener() {
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
@@ -105,7 +105,7 @@ public class UpdateChecker {
|
||||
}
|
||||
|
||||
if (progress.getStatus() == 3) {
|
||||
LOG.info("Update failed: {} / {}", progress.getError(), progress.getErrorMessage());
|
||||
LOG.info("Update failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.cryptomator.ui.preferences;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.updates.AppUpdateChecker;
|
||||
import org.cryptomator.integrations.common.DistributionChannel;
|
||||
import org.cryptomator.integrations.common.DisplayName;
|
||||
import org.cryptomator.integrations.update.UpdateFailedException;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.fxapp.UpdateChecker;
|
||||
@@ -24,7 +24,6 @@ import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ContentDisplay;
|
||||
import javafx.scene.control.Label;
|
||||
@@ -49,6 +48,7 @@ public class UpdatesPreferencesController implements FxController {
|
||||
+ "?utm_source=cryptomator-desktop" //
|
||||
+ "&utm_medium=update-notification&" //
|
||||
+ "utm_campaign=app-update-%s";
|
||||
private static final String DISPLAY_NAME_FLATPAK = "Update via Flatpak update";
|
||||
|
||||
private final Application application;
|
||||
private final Environment environment;
|
||||
@@ -103,7 +103,7 @@ public class UpdatesPreferencesController implements FxController {
|
||||
public void initialize() {
|
||||
checkForUpdatesCheckbox.selectedProperty().bindBidirectional(settings.checkForUpdates);
|
||||
switch (env.getBuildNumber().get()) {
|
||||
case "flatpak-1" -> flatpakButtonLabel.setText(appUpdateChecker.getServiceForChannel(DistributionChannel.Value.LINUX_FLATPAK).getDisplayName());
|
||||
case "flatpak-1" -> flatpakButtonLabel.setText(appUpdateChecker.getServiceForChannel(DISPLAY_NAME_FLATPAK).getClass().getAnnotation(DisplayName.class).value());
|
||||
default -> LOG.error("Unexpected value 'buildNumber': {}", env.getBuildNumber().get());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user