mirror of
https://github.com/cryptomator/cryptomator.git
synced 2024-11-23 12:09:45 +00:00
make quickAccessService togglable & selectable in UI
This commit is contained in:
parent
2fe5180721
commit
f1eb997804
@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.google.common.base.Suppliers;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.integrations.quickaccess.QuickAccessService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -26,6 +27,7 @@ import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@ -45,11 +47,13 @@ public class SettingsProvider implements Supplier<Settings> {
|
||||
private final Supplier<Settings> settings = Suppliers.memoize(this::load);
|
||||
private final Environment env;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private final Optional<QuickAccessService> quickAccessService;
|
||||
|
||||
@Inject
|
||||
public SettingsProvider(Environment env, ScheduledExecutorService scheduler) {
|
||||
public SettingsProvider(Environment env, ScheduledExecutorService scheduler, List<QuickAccessService> quickAccessServices) {
|
||||
this.env = env;
|
||||
this.scheduler = scheduler;
|
||||
this.quickAccessService = quickAccessServices.stream().findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,7 +62,13 @@ public class SettingsProvider implements Supplier<Settings> {
|
||||
}
|
||||
|
||||
private Settings load() {
|
||||
Settings settings = env.getSettingsPath().flatMap(this::tryLoad).findFirst().orElseGet(() -> Settings.create(env));
|
||||
Settings settings = env.getSettingsPath() //
|
||||
.flatMap(this::tryLoad) //
|
||||
.findFirst() //
|
||||
.orElseGet(() -> Settings.create(env));
|
||||
if (settings.quickAccessService.getValue() == null) {
|
||||
quickAccessService.ifPresent(s -> settings.quickAccessService.setValue(s.getClass().getName()));
|
||||
}
|
||||
settings.setSaveCmd(this::scheduleSave);
|
||||
return settings;
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.integrations.autostart.AutoStartProvider;
|
||||
import org.cryptomator.integrations.autostart.ToggleAutoStartFailedException;
|
||||
import org.cryptomator.integrations.common.NamedServiceProvider;
|
||||
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
|
||||
import org.cryptomator.integrations.quickaccess.QuickAccessService;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationWindows;
|
||||
import org.slf4j.Logger;
|
||||
@ -30,12 +32,15 @@ public class GeneralPreferencesController implements FxController {
|
||||
private final Stage window;
|
||||
private final Settings settings;
|
||||
private final Optional<AutoStartProvider> autoStartProvider;
|
||||
private final List<QuickAccessService> quickAccessServices;
|
||||
private final Application application;
|
||||
private final Environment environment;
|
||||
private final List<KeychainAccessProvider> keychainAccessProviders;
|
||||
private final FxApplicationWindows appWindows;
|
||||
public CheckBox useKeychainCheckbox;
|
||||
public ChoiceBox<KeychainAccessProvider> keychainBackendChoiceBox;
|
||||
public CheckBox useQuickAccessCheckbox;
|
||||
public ChoiceBox<QuickAccessService> quickAccessServiceChoiceBox;
|
||||
public CheckBox startHiddenCheckbox;
|
||||
public CheckBox autoCloseVaultsCheckbox;
|
||||
public CheckBox debugModeCheckbox;
|
||||
@ -43,11 +48,12 @@ public class GeneralPreferencesController implements FxController {
|
||||
public ToggleGroup nodeOrientation;
|
||||
|
||||
@Inject
|
||||
GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, Optional<AutoStartProvider> autoStartProvider, List<KeychainAccessProvider> keychainAccessProviders, Application application, Environment environment, FxApplicationWindows appWindows) {
|
||||
GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, Optional<AutoStartProvider> autoStartProvider, List<KeychainAccessProvider> keychainAccessProviders, List<QuickAccessService> quickAccessServices, Application application, Environment environment, FxApplicationWindows appWindows) {
|
||||
this.window = window;
|
||||
this.settings = settings;
|
||||
this.autoStartProvider = autoStartProvider;
|
||||
this.keychainAccessProviders = keychainAccessProviders;
|
||||
this.quickAccessServices = quickAccessServices;
|
||||
this.application = application;
|
||||
this.environment = environment;
|
||||
this.appWindows = appWindows;
|
||||
@ -60,13 +66,21 @@ public class GeneralPreferencesController implements FxController {
|
||||
debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode);
|
||||
autoStartProvider.ifPresent(autoStart -> autoStartCheckbox.setSelected(autoStart.isEnabled()));
|
||||
|
||||
var keychainSettingsConverter = new KeychainProviderClassNameConverter(keychainAccessProviders);
|
||||
var keychainSettingsConverter = new ServiceToSettingsConverter<>(keychainAccessProviders);
|
||||
keychainBackendChoiceBox.getItems().addAll(keychainAccessProviders);
|
||||
keychainBackendChoiceBox.setValue(keychainSettingsConverter.fromString(settings.keychainProvider.get()));
|
||||
keychainBackendChoiceBox.setConverter(new KeychainProviderDisplayNameConverter());
|
||||
Bindings.bindBidirectional(settings.keychainProvider, keychainBackendChoiceBox.valueProperty(), keychainSettingsConverter);
|
||||
useKeychainCheckbox.selectedProperty().bindBidirectional(settings.useKeychain);
|
||||
keychainBackendChoiceBox.disableProperty().bind(useKeychainCheckbox.selectedProperty().not());
|
||||
|
||||
useQuickAccessCheckbox.selectedProperty().bindBidirectional(settings.useQuickAccess);
|
||||
var quickAccessSettingsConverter = new ServiceToSettingsConverter<>(quickAccessServices);
|
||||
quickAccessServiceChoiceBox.getItems().addAll(quickAccessServices);
|
||||
quickAccessServiceChoiceBox.setValue(quickAccessSettingsConverter.fromString(settings.quickAccessService.get()));
|
||||
quickAccessServiceChoiceBox.setConverter(new NamedServiceConverter<>());
|
||||
Bindings.bindBidirectional(settings.quickAccessService, quickAccessServiceChoiceBox.valueProperty(), quickAccessSettingsConverter);
|
||||
quickAccessServiceChoiceBox.disableProperty().bind(useQuickAccessCheckbox.selectedProperty().not());
|
||||
}
|
||||
|
||||
public boolean isAutoStartSupported() {
|
||||
@ -116,29 +130,47 @@ public class GeneralPreferencesController implements FxController {
|
||||
|
||||
}
|
||||
|
||||
private static class KeychainProviderClassNameConverter extends StringConverter<KeychainAccessProvider> {
|
||||
|
||||
private final List<KeychainAccessProvider> keychainAccessProviders;
|
||||
|
||||
public KeychainProviderClassNameConverter(List<KeychainAccessProvider> keychainAccessProviders) {
|
||||
this.keychainAccessProviders = keychainAccessProviders;
|
||||
}
|
||||
private static class NamedServiceConverter<T extends NamedServiceProvider> extends StringConverter<T> {
|
||||
|
||||
@Override
|
||||
public String toString(KeychainAccessProvider provider) {
|
||||
if (provider == null) {
|
||||
public String toString(T namedService) {
|
||||
if (namedService == null) {
|
||||
return null;
|
||||
} else {
|
||||
return provider.getClass().getName();
|
||||
return namedService.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeychainAccessProvider fromString(String string) {
|
||||
public T fromString(String string) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ServiceToSettingsConverter<T> extends StringConverter<T> {
|
||||
|
||||
private final List<T> services;
|
||||
|
||||
public ServiceToSettingsConverter(List<T> services) {
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(T service) {
|
||||
if (service == null) {
|
||||
return null;
|
||||
} else {
|
||||
return service.getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromString(String string) {
|
||||
if (string == null) {
|
||||
return null;
|
||||
} else {
|
||||
return keychainAccessProviders.stream().filter(provider -> provider.getClass().getName().equals(string)).findAny().orElse(null);
|
||||
return services.stream().filter(provider -> provider.getClass().getName().equals(string)).findAny().orElse(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,10 @@
|
||||
<ChoiceBox fx:id="keychainBackendChoiceBox"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="12" alignment="CENTER_LEFT">
|
||||
<CheckBox fx:id="useQuickAccessCheckbox" text="TODO Quick access"/>
|
||||
<ChoiceBox fx:id="quickAccessServiceChoiceBox"/>
|
||||
</HBox>
|
||||
<Region VBox.vgrow="ALWAYS"/>
|
||||
|
||||
<HBox spacing="12" alignment="CENTER_LEFT">
|
||||
|
Loading…
Reference in New Issue
Block a user