From 79bb4a52152d7a46180c16282da6a7618a84abc4 Mon Sep 17 00:00:00 2001 From: Ralph Plawetzki Date: Sat, 2 Aug 2025 11:32:07 +0200 Subject: [PATCH] Correlate with API as suggested in a separate PoC: UpdateMechanism and UpdateProcess --- .../common/updates/AppUpdateChecker.java | 35 ++++++++++--------- .../cryptomator/ui/fxapp/UpdateChecker.java | 10 +++--- .../UpdatesPreferencesController.java | 6 ++-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/cryptomator/common/updates/AppUpdateChecker.java b/src/main/java/org/cryptomator/common/updates/AppUpdateChecker.java index 238342e7d..f35d6d757 100644 --- a/src/main/java/org/cryptomator/common/updates/AppUpdateChecker.java +++ b/src/main/java/org/cryptomator/common/updates/AppUpdateChecker.java @@ -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 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 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 services, DistributionChannel.Value requiredChannel) { + private boolean doServicesContainChannel(List 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 services, DistributionChannel.Value requiredChannel) { + private UpdateService getServiceForChannel(List 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); } } diff --git a/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java b/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java index bcc9a24bf..28520d7a3 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java +++ b/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java @@ -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; } diff --git a/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java b/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java index c0e9a1489..4382c63ef 100644 --- a/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java +++ b/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java @@ -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()); }