mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 08:41:28 +00:00
adjust to type-safe api
This commit is contained in:
@@ -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...");
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user