mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-22 04:31:27 +00:00
Invent UpdatesModule
This commit is contained in:
@@ -11,6 +11,7 @@ import org.cryptomator.common.keychain.KeychainModule;
|
||||
import org.cryptomator.common.mount.MountModule;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.SettingsProvider;
|
||||
import org.cryptomator.common.updates.UpdatesModule;
|
||||
import org.cryptomator.common.vaults.VaultComponent;
|
||||
import org.cryptomator.common.vaults.VaultListModule;
|
||||
import org.cryptomator.cryptolib.common.MasterkeyFileAccess;
|
||||
@@ -30,7 +31,7 @@ import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Module(subcomponents = {VaultComponent.class}, includes = {VaultListModule.class, KeychainModule.class, MountModule.class})
|
||||
@Module(subcomponents = {VaultComponent.class}, includes = {VaultListModule.class, KeychainModule.class, MountModule.class, UpdatesModule.class})
|
||||
public abstract class CommonsModule {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CommonsModule.class);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.cryptomator.common.updates;
|
||||
|
||||
import org.cryptomator.integrations.update.UpdateFailedException;
|
||||
import org.cryptomator.integrations.update.UpdateService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -18,13 +17,20 @@ public class AppUpdateChecker {
|
||||
this.updateService = updateService;
|
||||
}
|
||||
|
||||
public void checkForUpdates() {
|
||||
updateService.ifPresent(service -> {
|
||||
try {
|
||||
service.triggerUpdate();
|
||||
} catch (UpdateFailedException e) {
|
||||
LOG.error(e.toString(), e.getCause());
|
||||
public boolean isUpdateServiceAvailable() {
|
||||
return updateService.isPresent();
|
||||
}
|
||||
|
||||
public String checkForUpdates(UpdateService.DistributionChannel channel) {
|
||||
if (!updateService.isPresent()) {
|
||||
LOG.error("No UpdateService found");
|
||||
return null;
|
||||
}
|
||||
switch (channel) {
|
||||
case LINUX_FLATPAK -> {
|
||||
return updateService.map(service -> service.isUpdateAvailable(UpdateService.DistributionChannel.LINUX_FLATPAK)).orElse(null);
|
||||
}
|
||||
});
|
||||
default -> throw new IllegalStateException("Unexpected value: " + channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.cryptomator.common.updates;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.cryptomator.integrations.update.UpdateService;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Module
|
||||
public class UpdatesModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static List<UpdateService> provideSupportedUpdateServices() {
|
||||
return UpdateService.get().toList();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Optional<UpdateService> provideUpdateService(List<UpdateService> updateServices) {
|
||||
return updateServices.stream().findFirst();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
import org.cryptomator.common.CommonsModule;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationComponent;
|
||||
import org.cryptomator.common.updates.AppUpdateChecker;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
@@ -15,8 +14,6 @@ public interface CryptomatorComponent {
|
||||
|
||||
Cryptomator application();
|
||||
|
||||
AppUpdateChecker appUpdateChecker();
|
||||
|
||||
FxApplicationComponent.Builder fxAppComponentBuilder();
|
||||
|
||||
@Component.Factory
|
||||
|
||||
@@ -5,7 +5,6 @@ import dagger.Provides;
|
||||
import org.cryptomator.integrations.autostart.AutoStartProvider;
|
||||
import org.cryptomator.integrations.tray.TrayIntegrationProvider;
|
||||
import org.cryptomator.integrations.uiappearance.UiAppearanceProvider;
|
||||
import org.cryptomator.integrations.update.UpdateService;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationComponent;
|
||||
|
||||
import javax.inject.Named;
|
||||
@@ -49,9 +48,4 @@ class CryptomatorModule {
|
||||
return TrayIntegrationProvider.get();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Optional<UpdateService> provideUpdateService() {
|
||||
return UpdateService.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.update.UpdateService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -55,12 +56,18 @@ public class UpdateChecker {
|
||||
|
||||
public void automaticallyCheckForUpdatesIfEnabled() {
|
||||
if (!env.disableUpdateCheck() && settings.checkForUpdates.get()) {
|
||||
startCheckingForUpdates(AUTO_CHECK_DELAY);
|
||||
if (updateChecker.isUpdateServiceAvailable()) { // prefer AppUpdateChecker
|
||||
var x = updateChecker.checkForUpdates(UpdateService.DistributionChannel.LINUX_FLATPAK);
|
||||
LOG.info("Retrieved version from Update Service {}", x);
|
||||
} else { // fallback is the "redirect user to website" approach
|
||||
LOG.info("Common \"redirect user to website\" approach");
|
||||
startCheckingForUpdates(AUTO_CHECK_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForUpdatesNow() {
|
||||
updateChecker.checkForUpdates();
|
||||
startCheckingForUpdates(Duration.ZERO);
|
||||
}
|
||||
|
||||
private void startCheckingForUpdates(Duration initialDelay) {
|
||||
|
||||
Reference in New Issue
Block a user