|
@@ -2,50 +2,60 @@ package org.cryptomator.common.mount;
|
|
|
|
|
|
import dagger.Module;
|
|
|
import dagger.Provides;
|
|
|
+import org.cryptomator.common.ObservableUtil;
|
|
|
import org.cryptomator.common.settings.Settings;
|
|
|
import org.cryptomator.integrations.mount.MountService;
|
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
-import javafx.beans.property.SimpleObjectProperty;
|
|
|
import javafx.beans.value.ObservableValue;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
@Module
|
|
|
public class MountModule {
|
|
|
|
|
|
+ private static final AtomicReference<MountService> formerSelectedMountService = new AtomicReference<>(null);
|
|
|
+
|
|
|
@Provides
|
|
|
@Singleton
|
|
|
static List<MountService> provideSupportedMountServices() {
|
|
|
return MountService.get().toList();
|
|
|
}
|
|
|
|
|
|
- //currently not used, because macFUSE and FUSE-T cannot be used in the same JVM
|
|
|
- /*
|
|
|
@Provides
|
|
|
@Singleton
|
|
|
static ObservableValue<ActualMountService> provideMountService(Settings settings, List<MountService> serviceImpls) {
|
|
|
var fallbackProvider = serviceImpls.stream().findFirst().orElse(null);
|
|
|
- return ObservableUtil.mapWithDefault(settings.mountService(), //
|
|
|
+
|
|
|
+ var observableMountService = ObservableUtil.mapWithDefault(settings.mountService(), //
|
|
|
desiredServiceImpl -> { //
|
|
|
- var desiredService = serviceImpls.stream().filter(serviceImpl -> serviceImpl.getClass().getName().equals(desiredServiceImpl)).findAny(); //
|
|
|
- return new ActualMountService(desiredService.orElse(fallbackProvider), desiredService.isPresent()); //
|
|
|
+ var serviceFromSettings = serviceImpls.stream().filter(serviceImpl -> serviceImpl.getClass().getName().equals(desiredServiceImpl)).findAny(); //
|
|
|
+ var targetedService = serviceFromSettings.orElse(fallbackProvider);
|
|
|
+ return applyWorkaroundForFuseTMacFuse(targetedService, serviceFromSettings.isPresent());
|
|
|
}, //
|
|
|
- new ActualMountService(fallbackProvider, true));
|
|
|
+ () -> { //
|
|
|
+ return applyWorkaroundForFuseTMacFuse(fallbackProvider, true);
|
|
|
+ });
|
|
|
+ return observableMountService;
|
|
|
}
|
|
|
- */
|
|
|
|
|
|
- @Provides
|
|
|
- @Singleton
|
|
|
- static ActualMountService provideActualMountService(Settings settings, List<MountService> serviceImpls) {
|
|
|
- var fallbackProvider = serviceImpls.stream().findFirst().orElse(null);
|
|
|
- var desiredService = serviceImpls.stream().filter(serviceImpl -> serviceImpl.getClass().getName().equals(settings.mountService().getValue())).findFirst(); //
|
|
|
- return new ActualMountService(desiredService.orElse(fallbackProvider), desiredService.isPresent()); //
|
|
|
+
|
|
|
+ //see https://github.com/cryptomator/cryptomator/issues/2786
|
|
|
+ private static ActualMountService applyWorkaroundForFuseTMacFuse(MountService targetedService, boolean isDesired) {
|
|
|
+ if (isFUSETOrMacFUSE(targetedService) && isFUSETOrMacFUSE(formerSelectedMountService.get()) && !targetedService.equals(formerSelectedMountService.get())) {
|
|
|
+ return new ActualMountService(formerSelectedMountService.get(), false); //
|
|
|
+ } else {
|
|
|
+ formerSelectedMountService.set(targetedService);
|
|
|
+ return new ActualMountService(targetedService, isDesired); //
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @Provides
|
|
|
- @Singleton
|
|
|
- static ObservableValue<ActualMountService> provideMountService(ActualMountService service) {
|
|
|
- return new SimpleObjectProperty<>(service);
|
|
|
+ private static boolean isFUSETOrMacFUSE(MountService service) {
|
|
|
+ if (service == null) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return List.of("org.cryptomator.frontend.fuse.mount.MacFuseMountProvider", "org.cryptomator.frontend.fuse.mount.FuseTMountProvider").contains(service.getClass().getName());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|