mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-22 04:31:27 +00:00
reduce API to only consider vault events
This commit is contained in:
@@ -14,8 +14,8 @@ import org.cryptomator.common.settings.SettingsProvider;
|
||||
import org.cryptomator.common.vaults.VaultComponent;
|
||||
import org.cryptomator.common.vaults.VaultListModule;
|
||||
import org.cryptomator.cryptolib.common.MasterkeyFileAccess;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.integrations.revealpath.RevealPathService;
|
||||
import org.cryptomator.event.Event;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -133,7 +133,7 @@ public abstract class CommonsModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static ObservableList<Event> provideAppEventQueue() {
|
||||
static ObservableList<VaultEvent> provideVaultEventQueue() {
|
||||
return FXCollections.synchronizedObservableList(FXCollections.observableArrayList());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
import org.cryptomator.cryptolib.api.CryptoException;
|
||||
import org.cryptomator.cryptolib.api.MasterkeyLoader;
|
||||
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.integrations.mount.MountFailedException;
|
||||
import org.cryptomator.integrations.mount.Mountpoint;
|
||||
@@ -80,7 +79,7 @@ public class Vault {
|
||||
private final ObjectBinding<Mountpoint> mountPoint;
|
||||
private final Mounter mounter;
|
||||
private final Settings settings;
|
||||
private final ObservableList<Event> eventQueue;
|
||||
private final ObservableList<VaultEvent> eventList;
|
||||
private final BooleanProperty showingStats;
|
||||
|
||||
private final AtomicReference<Mounter.MountHandle> mountHandle = new AtomicReference<>(null);
|
||||
@@ -93,7 +92,7 @@ public class Vault {
|
||||
@Named("lastKnownException") ObjectProperty<Exception> lastKnownException, //
|
||||
VaultStats stats, //
|
||||
Mounter mounter, Settings settings, //
|
||||
ObservableList<Event> eventQueue) {
|
||||
ObservableList<VaultEvent> eventList) {
|
||||
this.vaultSettings = vaultSettings;
|
||||
this.configCache = configCache;
|
||||
this.cryptoFileSystem = cryptoFileSystem;
|
||||
@@ -110,7 +109,7 @@ public class Vault {
|
||||
this.mountPoint = Bindings.createObjectBinding(this::getMountPoint, state);
|
||||
this.mounter = mounter;
|
||||
this.settings = settings;
|
||||
this.eventQueue = eventQueue;
|
||||
this.eventList = eventList;
|
||||
this.showingStats = new SimpleBooleanProperty(false);
|
||||
this.quickAccessEntry = new AtomicReference<>(null);
|
||||
}
|
||||
@@ -262,8 +261,9 @@ public class Vault {
|
||||
}
|
||||
|
||||
private void consumeVaultEvent(FilesystemEvent e) {
|
||||
//TODO: here we could implement a buffer to prevent event spam (due to many filesystem requests)
|
||||
long timestamp = Instant.now().toEpochMilli();
|
||||
Platform.runLater(() -> eventQueue.addLast(new VaultEvent(timestamp, this, e)));
|
||||
Platform.runLater(() -> eventList.addLast(new VaultEvent(timestamp, this, e)));
|
||||
}
|
||||
|
||||
// ******************************************************************************
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.cryptomator.event;
|
||||
|
||||
public sealed interface Event extends Comparable<Event> permits UpdateEvent, VaultEvent {
|
||||
|
||||
long getTimestampMilli();
|
||||
|
||||
default int compareTo(Event other) {
|
||||
long timeDiff = this.getTimestampMilli() - other.getTimestampMilli();
|
||||
if (timeDiff != 0) {
|
||||
return (int) timeDiff;
|
||||
}
|
||||
return this.equals(other) ? 0 : this.getClass().getName().compareTo(other.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public interface NotificationHandler {
|
||||
|
||||
Answer handle(Event e);
|
||||
Answer handle(VaultEvent e);
|
||||
|
||||
static Stream<NotificationHandler> loadAll() {
|
||||
return IntegrationsLoader.loadAll(ServiceLoader.load(NotificationHandler.class), NotificationHandler.class);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.cryptomator.event;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record UpdateEvent(long timestamp, String newVersion) implements Event {
|
||||
|
||||
public UpdateEvent(String newVersion) {
|
||||
this(Instant.now().toEpochMilli(), newVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestampMilli() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,18 @@ import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record VaultEvent(long timestamp, Vault v, FilesystemEvent actualEvent) implements Event {
|
||||
public record VaultEvent(long timestamp, Vault v, FilesystemEvent actualEvent) implements Comparable<VaultEvent> {
|
||||
|
||||
public VaultEvent(Vault v, FilesystemEvent actualEvent) {
|
||||
this(Instant.now().toEpochMilli(), v, actualEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestampMilli() {
|
||||
return timestamp;
|
||||
public int compareTo(VaultEvent other) {
|
||||
long timeDiff = this.timestamp - other.timestamp;
|
||||
if (timeDiff != 0) {
|
||||
return (int) timeDiff;
|
||||
}
|
||||
return this.equals(other) ? 0 : this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.cryptomator.common.ObservableUtil;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.cryptofs.event.ConflictResolvedEvent;
|
||||
import org.cryptomator.cryptofs.event.FilesystemEvent;
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.event.UpdateEvent;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.integrations.revealpath.RevealFailedException;
|
||||
import org.cryptomator.integrations.revealpath.RevealPathService;
|
||||
@@ -32,10 +30,10 @@ public class EventListCellController implements FxController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EventListCellController.class);
|
||||
|
||||
private final ObservableList<Event> events;
|
||||
private final ObservableList<VaultEvent> events;
|
||||
private final Optional<RevealPathService> revealService;
|
||||
private final ResourceBundle resourceBundle;
|
||||
private final ObjectProperty<Event> event;
|
||||
private final ObjectProperty<VaultEvent> event;
|
||||
private final ObservableValue<String> message;
|
||||
private final ObservableValue<String> description;
|
||||
private final ObservableValue<FontAwesome5Icon> icon;
|
||||
@@ -48,7 +46,7 @@ public class EventListCellController implements FxController {
|
||||
Button eventActionsButton;
|
||||
|
||||
@Inject
|
||||
public EventListCellController(ObservableList<Event> events, Optional<RevealPathService> revealService, ResourceBundle resourceBundle) {
|
||||
public EventListCellController(ObservableList<VaultEvent> events, Optional<RevealPathService> revealService, ResourceBundle resourceBundle) {
|
||||
this.events = events;
|
||||
this.revealService = revealService;
|
||||
this.resourceBundle = resourceBundle;
|
||||
@@ -60,26 +58,23 @@ public class EventListCellController implements FxController {
|
||||
}
|
||||
|
||||
|
||||
private void hideContextMenus(Observable observable, Event oldValue, Event newValue) {
|
||||
private void hideContextMenus(Observable observable, VaultEvent oldValue, VaultEvent newValue) {
|
||||
basicEventActions.hide();
|
||||
conflictResoledEventActions.hide();
|
||||
}
|
||||
|
||||
public void setEvent(Event item) {
|
||||
public void setEvent(VaultEvent item) {
|
||||
event.set(item);
|
||||
}
|
||||
|
||||
private FontAwesome5Icon selectIcon(Event e) {
|
||||
return switch (e) {
|
||||
case UpdateEvent _ -> FontAwesome5Icon.BELL;
|
||||
case VaultEvent _ -> FontAwesome5Icon.FILE;
|
||||
};
|
||||
private FontAwesome5Icon selectIcon(VaultEvent e) {
|
||||
return FontAwesome5Icon.FILE;
|
||||
}
|
||||
|
||||
private String selectDescription(Event e) {
|
||||
return switch (e) {
|
||||
case UpdateEvent(_, String newVersion) -> resourceBundle.getString("preferences.updates.updateAvailable").formatted(newVersion);
|
||||
case VaultEvent _ -> "A vault is weird!";
|
||||
private String selectDescription(VaultEvent e) {
|
||||
return switch (e.actualEvent()) {
|
||||
case ConflictResolvedEvent _-> "A conflict is resolved!";
|
||||
default -> "Something happened";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -87,8 +82,8 @@ public class EventListCellController implements FxController {
|
||||
public void toggleEventActionsMenu() {
|
||||
var e = event.get();
|
||||
if (e != null) {
|
||||
var contextMenu = switch (e) {
|
||||
case VaultEvent _ -> conflictResoledEventActions;
|
||||
var contextMenu = switch (e.actualEvent()) {
|
||||
case ConflictResolvedEvent _ -> conflictResoledEventActions;
|
||||
default -> basicEventActions;
|
||||
};
|
||||
if (contextMenu.isShowing()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.cryptomator.ui.eventview;
|
||||
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.ui.common.FxmlLoaderFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
@EventViewScoped
|
||||
public class EventListCellFactory implements Callback<ListView<Event>, ListCell<Event>> {
|
||||
public class EventListCellFactory implements Callback<ListView<VaultEvent>, ListCell<VaultEvent>> {
|
||||
|
||||
private static final String FXML_PATH = "/fxml/eventview_cell.fxml";
|
||||
|
||||
@@ -27,7 +27,7 @@ public class EventListCellFactory implements Callback<ListView<Event>, ListCell<
|
||||
|
||||
|
||||
@Override
|
||||
public ListCell<Event> call(ListView<Event> eventListView) {
|
||||
public ListCell<VaultEvent> call(ListView<VaultEvent> eventListView) {
|
||||
try {
|
||||
FXMLLoader fxmlLoader = fxmlLoaders.load(FXML_PATH);
|
||||
return new Cell(fxmlLoader.getRoot(), fxmlLoader.getController());
|
||||
@@ -36,7 +36,7 @@ public class EventListCellFactory implements Callback<ListView<Event>, ListCell<
|
||||
}
|
||||
}
|
||||
|
||||
private static class Cell extends ListCell<Event> {
|
||||
private static class Cell extends ListCell<VaultEvent> {
|
||||
|
||||
private final Parent root;
|
||||
private final EventListCellController controller;
|
||||
@@ -47,7 +47,7 @@ public class EventListCellFactory implements Callback<ListView<Event>, ListCell<
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(Event item, boolean empty) {
|
||||
protected void updateItem(VaultEvent item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
|
||||
if (empty || item == null) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.cryptomator.ui.eventview;
|
||||
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.event.VaultEvent;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -13,15 +13,15 @@ import java.util.Comparator;
|
||||
@EventViewScoped
|
||||
public class EventViewController implements FxController {
|
||||
|
||||
private final SortedList<Event> reversedEventList;
|
||||
private final ObservableList<Event> eventList;
|
||||
private final SortedList<VaultEvent> reversedEventList;
|
||||
private final ObservableList<VaultEvent> eventList;
|
||||
private final EventListCellFactory cellFactory;
|
||||
|
||||
@FXML
|
||||
ListView<Event> eventListView;
|
||||
ListView<VaultEvent> eventListView;
|
||||
|
||||
@Inject
|
||||
public EventViewController(ObservableList<Event> eventList, EventListCellFactory cellFactory) {
|
||||
public EventViewController(ObservableList<VaultEvent> eventList, EventListCellFactory cellFactory) {
|
||||
reversedEventList = new SortedList<>(eventList, Comparator.reverseOrder());
|
||||
this.eventList = eventList;
|
||||
this.cellFactory = cellFactory;
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.cryptomator.ui.fxapp;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.common.SemVerComparator;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.event.Event;
|
||||
import org.cryptomator.event.UpdateEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -16,7 +14,6 @@ import javafx.beans.property.ReadOnlyStringProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Worker;
|
||||
import javafx.concurrent.WorkerStateEvent;
|
||||
@@ -36,7 +33,6 @@ public class UpdateChecker {
|
||||
private final ScheduledService<String> updateCheckerService;
|
||||
private final ObjectProperty<UpdateCheckState> state = new SimpleObjectProperty<>(UpdateCheckState.NOT_CHECKED);
|
||||
private final ObjectProperty<Instant> lastSuccessfulUpdateCheck;
|
||||
private final ObservableList<Event> eventQueue;
|
||||
private final Comparator<String> versionComparator = new SemVerComparator();
|
||||
private final BooleanBinding updateAvailable;
|
||||
private final BooleanBinding checkFailed;
|
||||
@@ -44,13 +40,11 @@ public class UpdateChecker {
|
||||
@Inject
|
||||
UpdateChecker(Settings settings, //
|
||||
Environment env, //
|
||||
ScheduledService<String> updateCheckerService, //
|
||||
ObservableList<Event> eventQueue) {
|
||||
ScheduledService<String> updateCheckerService) {
|
||||
this.env = env;
|
||||
this.settings = settings;
|
||||
this.updateCheckerService = updateCheckerService;
|
||||
this.lastSuccessfulUpdateCheck = settings.lastSuccessfulUpdateCheck;
|
||||
this.eventQueue = eventQueue;
|
||||
this.updateAvailable = Bindings.createBooleanBinding(this::isUpdateAvailable, latestVersion);
|
||||
this.checkFailed = Bindings.equal(UpdateCheckState.CHECK_FAILED, state);
|
||||
}
|
||||
@@ -86,9 +80,6 @@ public class UpdateChecker {
|
||||
lastSuccessfulUpdateCheck.set(Instant.now());
|
||||
latestVersion.set(latestVersionString);
|
||||
state.set(UpdateCheckState.CHECK_SUCCESSFUL);
|
||||
if( updateAvailable.get()) {
|
||||
eventQueue.addLast(new UpdateEvent(latestVersionString));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFailed(WorkerStateEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user