impl draft

This commit is contained in:
Armin Schrenk
2025-02-11 15:38:18 +01:00
parent dcd7077b08
commit ca2f80024a
10 changed files with 72 additions and 2 deletions

View File

@@ -33,7 +33,7 @@
<nonModularGroupIds>org.ow2.asm,org.apache.jackrabbit,org.apache.httpcomponents</nonModularGroupIds>
<!-- cryptomator dependencies -->
<cryptomator.cryptofs.version>2.8.0</cryptomator.cryptofs.version>
<cryptomator.cryptofs.version>2.9.0-SNAPSHOT</cryptomator.cryptofs.version>
<cryptomator.integrations.version>1.5.0</cryptomator.integrations.version>
<cryptomator.integrations.win.version>1.3.0</cryptomator.integrations.win.version>
<cryptomator.integrations.mac.version>1.2.4</cryptomator.integrations.mac.version>

View File

@@ -59,6 +59,7 @@ open module org.cryptomator.desktop {
uses org.cryptomator.common.locationpresets.LocationPresetsProvider;
uses SSLContextProvider;
uses org.cryptomator.notify.NotificationHandler;
provides TrayMenuController with AwtTrayMenuController;
provides Configurator with LogbackConfiguratorFactory;

View File

@@ -15,11 +15,14 @@ import org.cryptomator.common.vaults.VaultComponent;
import org.cryptomator.common.vaults.VaultListModule;
import org.cryptomator.cryptolib.common.MasterkeyFileAccess;
import org.cryptomator.integrations.revealpath.RevealPathService;
import org.cryptomator.notify.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Named;
import javax.inject.Singleton;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Comparator;
@@ -128,6 +131,12 @@ public abstract class CommonsModule {
return executorService;
}
@Provides
@Singleton
static ObservableList<Event> provideAppEventQueue() {
return FXCollections.observableArrayList();
}
private static void handleUncaughtExceptionInBackgroundThread(Thread thread, Throwable throwable) {
LOG.error("Uncaught exception in " + thread.getName(), throwable);
}

View File

@@ -18,6 +18,7 @@ import org.cryptomator.cryptofs.CryptoFileSystemProperties;
import org.cryptomator.cryptofs.CryptoFileSystemProperties.FileSystemFlags;
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
import org.cryptomator.cryptofs.common.FileSystemCapabilityChecker;
import org.cryptomator.cryptofs.event.FilesystemEvent;
import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.MasterkeyLoader;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
@@ -26,6 +27,8 @@ import org.cryptomator.integrations.mount.Mountpoint;
import org.cryptomator.integrations.mount.UnmountFailedException;
import org.cryptomator.integrations.quickaccess.QuickAccessService;
import org.cryptomator.integrations.quickaccess.QuickAccessServiceException;
import org.cryptomator.notify.Event;
import org.cryptomator.notify.VaultEvent;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,6 +44,7 @@ import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ObservableList;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -74,6 +78,7 @@ public class Vault {
private final ObjectBinding<Mountpoint> mountPoint;
private final Mounter mounter;
private final Settings settings;
private final ObservableList<Event> eventQueue;
private final BooleanProperty showingStats;
private final AtomicReference<Mounter.MountHandle> mountHandle = new AtomicReference<>(null);
@@ -85,7 +90,9 @@ public class Vault {
VaultState state, //
@Named("lastKnownException") ObjectProperty<Exception> lastKnownException, //
VaultStats stats, //
Mounter mounter, Settings settings) {
Mounter mounter, Settings settings, //
ObservableList<Event> eventQueue
) {
this.vaultSettings = vaultSettings;
this.configCache = configCache;
this.cryptoFileSystem = cryptoFileSystem;
@@ -102,6 +109,7 @@ public class Vault {
this.mountPoint = Bindings.createObjectBinding(this::getMountPoint, state);
this.mounter = mounter;
this.settings = settings;
this.eventQueue = eventQueue;
this.showingStats = new SimpleBooleanProperty(false);
this.quickAccessEntry = new AtomicReference<>(null);
}
@@ -143,6 +151,7 @@ public class Vault {
.withFlags(flags) //
.withMaxCleartextNameLength(vaultSettings.maxCleartextFilenameLength.get()) //
.withVaultConfigFilename(Constants.VAULTCONFIG_FILENAME) //
.withFilesystemEventConsumer(this::consumeVaultEvent)
.build();
return CryptoFileSystemProvider.newFileSystem(getPath(), fsProps);
}
@@ -251,6 +260,10 @@ public class Vault {
}
}
private void consumeVaultEvent(FilesystemEvent e) {
eventQueue.addLast(new VaultEvent(vaultSettings.id, vaultSettings.path.get().toString(), e));
}
// ******************************************************************************
// Observable Properties
// *******************************************************************************

View File

@@ -0,0 +1,14 @@
package org.cryptomator.notify;
public sealed interface Answer permits Answer.DoNothing, Answer.DoSomething {
record DoNothing() implements Answer {}
record DoSomething(Runnable action) implements Answer {
void run() {
action.run();
}
}
}

View File

@@ -0,0 +1,3 @@
package org.cryptomator.notify;
public record AppEvent() implements Event {}

View File

@@ -0,0 +1,5 @@
package org.cryptomator.notify;
public sealed interface Event permits AppEvent, VaultEvent {
}

View File

@@ -0,0 +1,15 @@
package org.cryptomator.notify;
import org.cryptomator.integrations.common.IntegrationsLoader;
import java.util.ServiceLoader;
import java.util.stream.Stream;
public interface NotificationHandler {
Answer handle(Event e);
static Stream<NotificationHandler> loadAll() {
return IntegrationsLoader.loadAll(ServiceLoader.load(NotificationHandler.class), NotificationHandler.class);
}
}

View File

@@ -0,0 +1,7 @@
package org.cryptomator.notify;
import org.cryptomator.cryptofs.event.FilesystemEvent;
public record VaultEvent(String vaultId, String path, FilesystemEvent actualEvent) implements Event {
}

View File

@@ -0,0 +1,3 @@
package org.cryptomator.ui.eventviewer;
public interface EventViewerComponent {}