mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 17:10:27 +00:00
Make browser restore functionality work
This commit is contained in:
parent
26c3c16872
commit
6af56c451a
4 changed files with 38 additions and 9 deletions
|
@ -67,12 +67,32 @@ public class BrowserModel {
|
|||
private final BrowserTransferModel localTransfersStage = new BrowserTransferModel();
|
||||
private final ObservableList<BrowserEntry> selection = FXCollections.observableArrayList();
|
||||
|
||||
public void restoreState(BrowserSavedState state) {
|
||||
state.getLastSystems().forEach((uuid, s) -> {
|
||||
var storageEntry = DataStorage.get().getStoreEntry(uuid);
|
||||
storageEntry.ifPresent(entry -> {
|
||||
openFileSystemAsync(entry.getName(), entry.getStore().asNeeded(), s, new SimpleBooleanProperty());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
var map = new LinkedHashMap<UUID, String>();
|
||||
openFileSystems.forEach(model -> {
|
||||
var storageEntry = DataStorage.get().getStoreEntryIfPresent(model.getStore());
|
||||
storageEntry.ifPresent(entry -> map.put(entry.getUuid(), model.getCurrentPath().get()));
|
||||
});
|
||||
|
||||
// Don't override state if it is empty
|
||||
if (map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var meaningful = map.size() > 1 || map.values().stream().allMatch(s -> s != null);
|
||||
if (!meaningful) {
|
||||
return;
|
||||
}
|
||||
|
||||
var state = new BrowserSavedState(map);
|
||||
state.save();
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.UUID;
|
|||
public class BrowserSavedState {
|
||||
|
||||
static BrowserSavedState load() {
|
||||
var state = AppCache.get("browser-state", BrowserSavedState.class, () -> {
|
||||
return new BrowserSavedState();
|
||||
BrowserSavedState state = AppCache.get("browser-state", BrowserSavedState.class, () -> {
|
||||
return null;
|
||||
});
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import javafx.scene.control.Label;
|
|||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class BrowserWelcomeComp extends SimpleComp {
|
||||
|
||||
private final BrowserModel model;
|
||||
|
@ -23,16 +25,16 @@ public class BrowserWelcomeComp extends SimpleComp {
|
|||
@Override
|
||||
protected Region createSimple() {
|
||||
var state = BrowserSavedState.load();
|
||||
var showList = state.getLastSystems().size() > 1
|
||||
|| (state.getLastSystems().size() == 1
|
||||
&& state.getLastSystems().values().stream().allMatch(s -> s != null));
|
||||
|
||||
var welcome = new BrowserGreetingComp().createSimple();
|
||||
|
||||
var vbox = new VBox(welcome);
|
||||
vbox.setPadding(new Insets(40, 40, 40, 50));
|
||||
vbox.setSpacing(18);
|
||||
if (!showList) {
|
||||
if (state == null) {
|
||||
var header = new Label("Have fun with the file browser!");
|
||||
AppFont.header(header);
|
||||
vbox.getChildren().add(header);
|
||||
return vbox;
|
||||
}
|
||||
|
||||
|
@ -65,6 +67,16 @@ public class BrowserWelcomeComp extends SimpleComp {
|
|||
vbox.getChildren().add(restoreLabel);
|
||||
|
||||
var restoreButton = new Button("Restore sessions");
|
||||
var done = new AtomicBoolean();
|
||||
restoreButton.setOnAction(event -> {
|
||||
if (done.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
done.set(true);
|
||||
model.restoreState(state);
|
||||
event.consume();
|
||||
});
|
||||
vbox.getChildren().add(restoreButton);
|
||||
|
||||
return vbox;
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
package io.xpipe.app.prefs;
|
||||
|
||||
public class UsageNotificationBehaviour {}
|
Loading…
Reference in a new issue