adjust to type-safe api

This commit is contained in:
Sebastian Stenzel
2025-11-04 21:42:24 +01:00
parent c3931d9d29
commit 0bdcb2b3be
4 changed files with 17 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ import java.time.Instant;
import java.util.concurrent.Executors;
@FxApplicationScoped
public class UpdateChecker extends ScheduledService<UpdateInfo> {
public class UpdateChecker extends ScheduledService<UpdateInfo<?>> {
private static final Logger LOG = LoggerFactory.getLogger(UpdateChecker.class);
private static final Duration AUTO_CHECK_DELAY = Duration.seconds(5);
@@ -45,8 +45,8 @@ public class UpdateChecker extends ScheduledService<UpdateInfo> {
private final ObjectBinding<UpdateCheckState> updateState = Bindings.createObjectBinding(this::getUpdateCheckState, stateProperty());
private final BooleanBinding checkFailed = Bindings.equal(UpdateCheckState.CHECK_FAILED, updateState);
private final HttpClient httpClient;
private final UpdateMechanism primaryUpdateMechanism;
private final UpdateMechanism fallbackUpdateMechanism;
private final UpdateMechanism<?> primaryUpdateMechanism;
private final UpdateMechanism<?> fallbackUpdateMechanism;
@Inject
UpdateChecker(Settings settings, //
@@ -92,7 +92,7 @@ public class UpdateChecker extends ScheduledService<UpdateInfo> {
}
@Override
protected Task<UpdateInfo> createTask() {
protected Task<UpdateInfo<?>> createTask() {
return new UpdateCheckTask();
}
@@ -154,10 +154,10 @@ public class UpdateChecker extends ScheduledService<UpdateInfo> {
return env.getAppVersion();
}
private class UpdateCheckTask extends Task<UpdateInfo> {
private class UpdateCheckTask extends Task<UpdateInfo<?>> {
@Override
protected UpdateInfo call() throws UpdateFailedException, InterruptedException {
protected UpdateInfo<?> call() throws UpdateFailedException {
var result = primaryUpdateMechanism.checkForUpdate(env.getAppVersion(), httpClient);
if (result == null && primaryUpdateMechanism != fallbackUpdateMechanism) {
LOG.debug("Primary update mechanism did not find an update. Try fallback update mechanism...");

View File

@@ -28,7 +28,7 @@ public abstract class DownloadUpdateMechanism implements UpdateMechanism<Downloa
DownloadUpdateMechanism updateMechanism,
String version,
Asset asset
) implements UpdateInfo {}
) implements UpdateInfo<DownloadUpdateInfo> {}
@Override
public DownloadUpdateInfo checkForUpdate(String currentVersion, HttpClient httpClient) {

View File

@@ -7,6 +7,7 @@ import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.Environment;
import org.cryptomator.integrations.common.DisplayName;
import org.cryptomator.integrations.common.Priority;
import org.cryptomator.integrations.update.BasicUpdateInfo;
import org.cryptomator.integrations.update.UpdateInfo;
import org.cryptomator.integrations.update.UpdateMechanism;
import org.cryptomator.integrations.update.UpdateStep;
@@ -32,7 +33,7 @@ import java.util.concurrent.TimeUnit;
@FxApplicationScoped
@Priority(Priority.FALLBACK)
@DisplayName("Show Download Page") // TODO localize
public class FallbackUpdateMechanism implements UpdateMechanism<UpdateInfo> {
public class FallbackUpdateMechanism implements UpdateMechanism<BasicUpdateInfo> {
private static final Logger LOG = LoggerFactory.getLogger(FallbackUpdateMechanism.class);
private static final String LATEST_VERSION_API_URL = "https://api.cryptomator.org/connect/apps/desktop/latest-version";
@@ -52,7 +53,7 @@ public class FallbackUpdateMechanism implements UpdateMechanism<UpdateInfo> {
}
@Override
public UpdateInfo checkForUpdate(String currentVersion, HttpClient httpClient) {
public BasicUpdateInfo checkForUpdate(String currentVersion, HttpClient httpClient) {
try {
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(LATEST_VERSION_API_URL)).build();
HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
@@ -62,7 +63,7 @@ public class FallbackUpdateMechanism implements UpdateMechanism<UpdateInfo> {
var release = MAPPER.readValue(response.body(), LatestVersion.class);
var updateVersion = release.versionForCurrentOS();
if (UpdateMechanism.isUpdateAvailable(updateVersion, currentVersion)) {
return UpdateInfo.of(updateVersion, this);
return new BasicUpdateInfo(updateVersion, this);
} else {
return null;
}
@@ -77,7 +78,7 @@ public class FallbackUpdateMechanism implements UpdateMechanism<UpdateInfo> {
}
@Override
public UpdateStep firstStep(UpdateInfo updateInfo) {
public UpdateStep firstStep(BasicUpdateInfo updateInfo) {
return UpdateStep.of("Go to download page", this::openDownloadPage); // TODO localize
}

View File

@@ -18,9 +18,9 @@ import java.util.concurrent.TimeUnit;
*/
public class UpdateService extends Service<UpdateStep> {
private ObservableValue<UpdateInfo> updateInfo;
private ObservableValue<UpdateInfo<?>> updateInfo;
public UpdateService(ObservableValue<UpdateInfo> updateInfo) {
public UpdateService(ObservableValue<UpdateInfo<?>> updateInfo) {
setExecutor(Executors.newVirtualThreadPerTaskExecutor());
this.updateInfo = updateInfo;
}
@@ -32,16 +32,17 @@ public class UpdateService extends Service<UpdateStep> {
private static class RunAllStepsTask extends Task<UpdateStep> {
@SuppressWarnings("rawtypes")
private final UpdateInfo updateInfo;
public RunAllStepsTask(UpdateInfo updateInfo) {
public RunAllStepsTask(UpdateInfo<?> updateInfo) {
this.updateInfo = Objects.requireNonNull(updateInfo);
}
@Override
protected UpdateStep call() throws IOException {
try {
UpdateStep step = updateInfo.updateMechanism().firstStep(updateInfo);
UpdateStep step = updateInfo.useToPrepareFirstStep();
UpdateStep lastStep;
do {
step.start();