mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-19 00:56:52 -04:00
detect failed update attempt via new setting
This commit is contained in:
@@ -77,6 +77,7 @@ public class Settings {
|
||||
public final ObjectProperty<Instant> lastUpdateCheckReminder;
|
||||
public final ObjectProperty<Instant> lastSuccessfulUpdateCheck;
|
||||
public final ObjectProperty<Path> previouslyUsedVaultDirectory;
|
||||
public final StringProperty lastUpdateAttemptedByVersion;
|
||||
|
||||
public static Settings create(SettingsProvider provider, Environment env) {
|
||||
var defaults = new SettingsJson();
|
||||
@@ -116,6 +117,7 @@ public class Settings {
|
||||
this.lastUpdateCheckReminder = new SimpleObjectProperty<>(this, "lastUpdateCheckReminder", json.lastReminderForUpdateCheck);
|
||||
this.lastSuccessfulUpdateCheck = new SimpleObjectProperty<>(this, "lastSuccessfulUpdateCheck", json.lastSuccessfulUpdateCheck);
|
||||
this.previouslyUsedVaultDirectory = new SimpleObjectProperty<>(this, "previouslyUsedVaultDirectory", json.previouslyUsedVaultDirectory);
|
||||
this.lastUpdateAttemptedByVersion = new SimpleStringProperty(this, "lastUpdateAttemptedByVersion", json.lastUpdateAttemptedByVersion);
|
||||
|
||||
this.directories.addAll(json.directories.stream().map(VaultSettings::new).toList());
|
||||
|
||||
@@ -146,6 +148,7 @@ public class Settings {
|
||||
lastUpdateCheckReminder.addListener(this::somethingChanged);
|
||||
lastSuccessfulUpdateCheck.addListener(this::somethingChanged);
|
||||
previouslyUsedVaultDirectory.addListener(this::somethingChanged);
|
||||
lastUpdateAttemptedByVersion.addListener(this::somethingChanged);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -208,6 +211,7 @@ public class Settings {
|
||||
json.lastReminderForUpdateCheck = lastUpdateCheckReminder.get();
|
||||
json.lastSuccessfulUpdateCheck = lastSuccessfulUpdateCheck.get();
|
||||
json.previouslyUsedVaultDirectory = previouslyUsedVaultDirectory.get();
|
||||
json.lastUpdateAttemptedByVersion = lastUpdateAttemptedByVersion.get();
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,4 +96,7 @@ class SettingsJson {
|
||||
|
||||
@JsonProperty("previouslyUsedVaultDirectory")
|
||||
Path previouslyUsedVaultDirectory;
|
||||
|
||||
@JsonProperty("lastUpdateAttemptedByVersion")
|
||||
String lastUpdateAttemptedByVersion;
|
||||
}
|
||||
|
||||
@@ -57,9 +57,17 @@ public class UpdateChecker extends ScheduledService<UpdateInfo<?>> {
|
||||
this.settings = settings;
|
||||
this.lastSuccessfulUpdateCheck = settings.lastSuccessfulUpdateCheck;
|
||||
this.httpClient = httpClient;
|
||||
this.primaryUpdateMechanism = UpdateMechanism.get().orElse(fallbackUpdateMechanism);
|
||||
this.fallbackUpdateMechanism = fallbackUpdateMechanism;
|
||||
|
||||
// Prefer the safer fallback mechanism if the last update attempt was already made by this app version
|
||||
var currentVersion = env.getAppVersionWithBuildNumber();
|
||||
var lastAttemptedBy = settings.lastUpdateAttemptedByVersion.get();
|
||||
if (currentVersion != null && currentVersion.equals(lastAttemptedBy)) {
|
||||
this.primaryUpdateMechanism = fallbackUpdateMechanism; // immediately use fallback mechanism
|
||||
} else {
|
||||
this.primaryUpdateMechanism = UpdateMechanism.get().orElse(fallbackUpdateMechanism);
|
||||
}
|
||||
|
||||
setExecutor(Executors.newVirtualThreadPerTaskExecutor());
|
||||
periodProperty().bind(Bindings.when(settings.checkForUpdates).then(UPDATE_CHECK_INTERVAL).otherwise(DISABLED_UPDATE_CHECK_INTERVAL));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.integrations.update.UpdateStep;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.fxapp.UpdateChecker;
|
||||
import org.cryptomator.updater.FallbackUpdateMechanism;
|
||||
import org.cryptomator.updater.UpdateService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -99,6 +98,7 @@ public class UpdatesPreferencesController implements FxController {
|
||||
if (worker.get().equals(updateChecker)) {
|
||||
updateChecker.checkForUpdatesNow();
|
||||
} else if (worker.get().equals(updateService)) {
|
||||
// TODO: only allow starting if all vaults are locked; show info label beneath button otherwise
|
||||
updateService.start();
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,9 @@ public class UpdatesPreferencesController implements FxController {
|
||||
assert workerStateEvent.getSource() == updateService;
|
||||
var lastStep = updateService.getValue();
|
||||
if (lastStep == UpdateStep.EXIT) {
|
||||
// Record that this version attempted an update, so next launch can choose fallback if needed
|
||||
settings.lastUpdateAttemptedByVersion.set(environment.getAppVersionWithBuildNumber());
|
||||
settings.saveNow();
|
||||
LOG.info("Exiting app to update...");
|
||||
Platform.exit();
|
||||
} else if (lastStep == UpdateStep.RETRY) {
|
||||
|
||||
Reference in New Issue
Block a user