diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserComp.java index 39ad0a00a..7074ed28c 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserComp.java @@ -14,6 +14,7 @@ import io.xpipe.app.fxcomps.SimpleCompStructure; import io.xpipe.app.fxcomps.augment.GrowAugment; import io.xpipe.app.fxcomps.impl.FancyTooltipAugment; import io.xpipe.app.fxcomps.impl.PrettyImageComp; +import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.util.BusyProperty; import io.xpipe.app.util.ThreadHelper; @@ -138,9 +139,9 @@ public class BrowserComp extends SimpleComp { private Node createTabs() { var multi = new MultiContentComp(Map.of( Comp.of(() -> createTabPane()), - Bindings.isNotEmpty(model.getOpenFileSystems()), + BindingsHelper.persist(Bindings.isNotEmpty(model.getOpenFileSystems())), new BrowserWelcomeComp(model), - Bindings.isEmpty(model.getOpenFileSystems()))); + BindingsHelper.persist(Bindings.isEmpty(model.getOpenFileSystems())))); return multi.createRegion(); } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserModel.java b/app/src/main/java/io/xpipe/app/browser/BrowserModel.java index 0ea33550e..a30d74d95 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserModel.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserModel.java @@ -68,33 +68,33 @@ public class BrowserModel { private final ObservableList selection = FXCollections.observableArrayList(); public void restoreState(BrowserSavedState state) { - state.getLastSystems().forEach((uuid, s) -> { - var storageEntry = DataStorage.get().getStoreEntry(uuid); + state.getLastSystems().forEach(e -> { + var storageEntry = DataStorage.get().getStoreEntry(e.getUuid()); storageEntry.ifPresent(entry -> { - openFileSystemAsync(entry.getName(), entry.getStore().asNeeded(), s, new SimpleBooleanProperty()); + openFileSystemAsync(entry.getName(), entry.getStore().asNeeded(), e.getPath(), new SimpleBooleanProperty()); }); }); } public void reset() { - var map = new LinkedHashMap(); + var list = new ArrayList(); openFileSystems.forEach(model -> { var storageEntry = DataStorage.get().getStoreEntryIfPresent(model.getStore()); storageEntry.ifPresent( - entry -> map.put(entry.getUuid(), model.getCurrentPath().get())); + entry -> list.add(new BrowserSavedState.Entry(entry.getUuid(), model.getCurrentPath().get()))); }); // Don't override state if it is empty - if (map.size() == 0) { + if (list.size() == 0) { return; } - var meaningful = map.size() > 1 || map.values().stream().allMatch(s -> s != null); + var meaningful = list.size() > 1 || list.stream().allMatch(s -> s.getPath() != null); if (!meaningful) { return; } - var state = new BrowserSavedState(map); + var state = BrowserSavedState.builder().lastSystems(list).build(); state.save(); } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserSavedState.java b/app/src/main/java/io/xpipe/app/browser/BrowserSavedState.java index 0ad1961f0..b2b426119 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserSavedState.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserSavedState.java @@ -1,18 +1,18 @@ package io.xpipe.app.browser; import io.xpipe.app.core.AppCache; -import io.xpipe.app.storage.DataStorage; -import io.xpipe.core.store.FileSystemStore; import lombok.Builder; import lombok.Getter; import lombok.NonNull; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import java.time.Instant; -import java.util.LinkedHashMap; +import java.util.List; import java.util.UUID; +@Value +@Jacksonized +@Builder @Getter public class BrowserSavedState { @@ -26,29 +26,15 @@ public class BrowserSavedState { @Value @Jacksonized @Builder - public static class RecentEntry { + public static class Entry { - String directory; - Instant time; + UUID uuid; + String path; } - @NonNull - private final LinkedHashMap lastSystems; - - public BrowserSavedState() { - lastSystems = new LinkedHashMap<>(); - } - - public BrowserSavedState(@NonNull LinkedHashMap lastSystems) { - this.lastSystems = lastSystems; - } + @NonNull List lastSystems; public void save() { AppCache.update("browser-state", this); } - - public void open(FileSystemStore store) { - var storageEntry = DataStorage.get().getStoreEntryIfPresent(store); - storageEntry.ifPresent(entry -> lastSystems.put(entry.getUuid(), null)); - } } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java index 44e6cd768..7e0504247 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java @@ -45,8 +45,8 @@ public class BrowserWelcomeComp extends SimpleComp { var storeList = new VBox(); storeList.setPadding(new Insets(0, 0, 0, 10)); storeList.setSpacing(8); - state.getLastSystems().forEach((uuid, s) -> { - var entry = DataStorage.get().getStoreEntry(uuid); + state.getLastSystems().forEach(e-> { + var entry = DataStorage.get().getStoreEntry(e.getUuid()); if (entry.isEmpty()) { return; } @@ -54,7 +54,7 @@ public class BrowserWelcomeComp extends SimpleComp { var graphic = entry.get().getProvider().getDisplayIconFileName(entry.get().getStore()); var view = new PrettyImageComp(new SimpleStringProperty(graphic), 24, 24); - var l = new Label(entry.get().getName() + (s != null ? ": " + s : ""), view.createRegion()); + var l = new Label(entry.get().getName() + (e.getPath() != null ? ": " + e.getPath() : ""), view.createRegion()); l.setGraphicTextGap(10); storeList.getChildren().add(l); });