mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 08:41:28 +00:00
use VaultEvent for notification to also show affected vault
Signed-off-by: Armin Schrenk <armin.schrenk@skymatic.de>
This commit is contained in:
@@ -266,7 +266,7 @@ public class Vault {
|
||||
|
||||
private void consumeVaultEvent(FilesystemEvent e) {
|
||||
fileSystemEventAggregator.put(this, e);
|
||||
notificationManager.tryAddEvent(e);
|
||||
notificationManager.tryAddEvent(this, e);
|
||||
}
|
||||
|
||||
// ******************************************************************************
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.cryptomator.event;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.cryptofs.event.BrokenFileNodeEvent;
|
||||
import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
|
||||
@@ -16,12 +17,12 @@ import java.util.Queue;
|
||||
/**
|
||||
* Manager for notifications.
|
||||
* <p>
|
||||
* To add (filesystem) events, use method {@link #tryAddEvent(FilesystemEvent)}. If the input event is eligible, it is added to an internal queue.
|
||||
* An event is eligible, if
|
||||
* <li>
|
||||
* <ul>the event should trigger a notification and</ul>
|
||||
* <ul>it is not added within the last {@value DEBOUNCE_THRESHOLD_SECONDS} seconds</ul>
|
||||
* </li>
|
||||
* To add (filesystem) events, use method {@link #tryAddEvent(Vault, FilesystemEvent)}. If the input event is eligible, it is added to an internal queue.
|
||||
* An event is eligible, if
|
||||
* <li>
|
||||
* <ul>the event should trigger a notification and</ul>
|
||||
* <ul>it is not added within the last {@value DEBOUNCE_THRESHOLD_SECONDS} seconds</ul>
|
||||
* </li>
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
@@ -30,7 +31,7 @@ public class NotificationManager {
|
||||
private static final int DEBOUNCE_THRESHOLD_SECONDS = 5;
|
||||
|
||||
Cache<Path, FilesystemEvent> eventCache;
|
||||
Queue<FilesystemEvent> eventsRequiringNotification;
|
||||
Queue<VaultEvent> eventsRequiringNotification;
|
||||
|
||||
@Inject
|
||||
public NotificationManager() {
|
||||
@@ -38,30 +39,31 @@ public class NotificationManager {
|
||||
eventsRequiringNotification = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public boolean tryAddEvent(FilesystemEvent e) {
|
||||
public boolean tryAddEvent(Vault v, FilesystemEvent e) {
|
||||
var notRecentlyAdded = switch (e) {
|
||||
case BrokenFileNodeEvent bfne -> isRecent(bfne.ciphertextPath(), bfne);
|
||||
default -> false;
|
||||
};
|
||||
if(notRecentlyAdded) {
|
||||
if (notRecentlyAdded) {
|
||||
synchronized (this) {
|
||||
eventsRequiringNotification.add(e);
|
||||
eventsRequiringNotification.add(new VaultEvent(v, e));
|
||||
}
|
||||
}
|
||||
return notRecentlyAdded;
|
||||
}
|
||||
|
||||
boolean isRecent(Path key, FilesystemEvent e) {
|
||||
var cacheElement = eventCache.get(key, _ -> e);
|
||||
var cacheElement = eventCache.get(key, _ -> e);
|
||||
return cacheElement == e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones all events requiring a notification to the target list and clears afterward the notification manager queue
|
||||
*
|
||||
* @param target list the queue is cloned to
|
||||
* @return {@code true}, if elements were copied
|
||||
*/
|
||||
public boolean cloneTo(List<FilesystemEvent> target) {
|
||||
public boolean cloneTo(List<VaultEvent> target) {
|
||||
synchronized (this) {
|
||||
var result = target.addAll(eventsRequiringNotification);
|
||||
eventsRequiringNotification.clear();
|
||||
|
||||
@@ -3,25 +3,6 @@ package org.cryptomator.event;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
|
||||
import java.time.Instant;
|
||||
public record VaultEvent(Vault v, FilesystemEvent actualEvent) {
|
||||
|
||||
public record VaultEvent(Vault v, FilesystemEvent actualEvent, int count) implements Comparable<VaultEvent> {
|
||||
|
||||
public VaultEvent(Vault v, FilesystemEvent actualEvent) {
|
||||
this(v, actualEvent, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VaultEvent other) {
|
||||
var timeResult = actualEvent.getTimestamp().compareTo(other.actualEvent().getTimestamp());
|
||||
if(timeResult != 0) {
|
||||
return timeResult;
|
||||
} else {
|
||||
return this.equals(other) ? 0 : this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public VaultEvent incrementCount(FilesystemEvent update) {
|
||||
return new VaultEvent(v, update, count+1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.cryptomator.ui.fxapp;
|
||||
|
||||
import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
import org.cryptomator.event.NotificationManager;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.application.Platform;
|
||||
@@ -19,7 +19,7 @@ public class FxNotificationRadar {
|
||||
private final NotificationManager notificationManager;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private final FxApplicationWindows applicationWindows;
|
||||
private final ObservableList<FilesystemEvent> eventsRequiringNotification;
|
||||
private final ObservableList<VaultEvent> eventsRequiringNotification;
|
||||
|
||||
@Inject
|
||||
public FxNotificationRadar(NotificationManager notificationManager, ScheduledExecutorService scheduler, FxApplicationWindows applicationWindows) {
|
||||
@@ -45,7 +45,7 @@ public class FxNotificationRadar {
|
||||
|
||||
}
|
||||
|
||||
public ObservableList<FilesystemEvent> getEventsRequiringNotification() {
|
||||
public ObservableList<VaultEvent> getEventsRequiringNotification() {
|
||||
return eventsRequiringNotification;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.cryptomator.ui.notification;
|
||||
|
||||
import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.fxapp.FxNotificationRadar;
|
||||
|
||||
@@ -25,10 +26,10 @@ import java.util.concurrent.ExecutorService;
|
||||
public class NotificationController implements FxController {
|
||||
|
||||
private final Stage window;
|
||||
private final SimpleListProperty<FilesystemEvent> notificationsProp;
|
||||
private final SimpleListProperty<VaultEvent> notificationsProp;
|
||||
private final IntegerProperty selectionIndex;
|
||||
private final ObservableStringValue paging;
|
||||
private final ObjectProperty<FilesystemEvent> selectedEvent;
|
||||
private final ObjectProperty<VaultEvent> selectedEvent;
|
||||
private final StringProperty message;
|
||||
private final StringProperty description;
|
||||
private final StringProperty actionText;
|
||||
@@ -55,8 +56,8 @@ public class NotificationController implements FxController {
|
||||
}
|
||||
|
||||
//TODO: Translations!
|
||||
private void adjustTexts(ObservableValue<? extends FilesystemEvent> observable, FilesystemEvent oldEvent, FilesystemEvent newEvent) {
|
||||
switch (newEvent) {
|
||||
private void adjustTexts(ObservableValue<? extends VaultEvent> observable, VaultEvent oldEvent, VaultEvent newEvent) {
|
||||
switch (newEvent.actualEvent()) {
|
||||
default -> {
|
||||
message.set("NO CONTENT");
|
||||
description.set("IF YOU SEE THIS MESSAGE, PLEASE CONTACT THE DEVELOPERS OF CRYPTOMATOR ABOUT A BUG IN THE NOTIFICATION DISPLAY");
|
||||
@@ -69,7 +70,7 @@ public class NotificationController implements FxController {
|
||||
public void handleButtonAction() {
|
||||
try {
|
||||
var ev = selectedEvent.get();
|
||||
switch (ev) {
|
||||
switch (ev.actualEvent()) {
|
||||
//TODO: executorService.submit(callback.action());
|
||||
default -> {
|
||||
} //normally nothing
|
||||
|
||||
Reference in New Issue
Block a user