mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-22 07:30:24 +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 BrowserTransferModel localTransfersStage = new BrowserTransferModel();
|
||||||
private final ObservableList<BrowserEntry> selection = FXCollections.observableArrayList();
|
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() {
|
public void reset() {
|
||||||
var map = new LinkedHashMap<UUID, String>();
|
var map = new LinkedHashMap<UUID, String>();
|
||||||
openFileSystems.forEach(model -> {
|
openFileSystems.forEach(model -> {
|
||||||
var storageEntry = DataStorage.get().getStoreEntryIfPresent(model.getStore());
|
var storageEntry = DataStorage.get().getStoreEntryIfPresent(model.getStore());
|
||||||
storageEntry.ifPresent(entry -> map.put(entry.getUuid(), model.getCurrentPath().get()));
|
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);
|
var state = new BrowserSavedState(map);
|
||||||
state.save();
|
state.save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ import java.util.UUID;
|
||||||
public class BrowserSavedState {
|
public class BrowserSavedState {
|
||||||
|
|
||||||
static BrowserSavedState load() {
|
static BrowserSavedState load() {
|
||||||
var state = AppCache.get("browser-state", BrowserSavedState.class, () -> {
|
BrowserSavedState state = AppCache.get("browser-state", BrowserSavedState.class, () -> {
|
||||||
return new BrowserSavedState();
|
return null;
|
||||||
});
|
});
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class BrowserWelcomeComp extends SimpleComp {
|
public class BrowserWelcomeComp extends SimpleComp {
|
||||||
|
|
||||||
private final BrowserModel model;
|
private final BrowserModel model;
|
||||||
|
@ -23,16 +25,16 @@ public class BrowserWelcomeComp extends SimpleComp {
|
||||||
@Override
|
@Override
|
||||||
protected Region createSimple() {
|
protected Region createSimple() {
|
||||||
var state = BrowserSavedState.load();
|
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 welcome = new BrowserGreetingComp().createSimple();
|
||||||
|
|
||||||
var vbox = new VBox(welcome);
|
var vbox = new VBox(welcome);
|
||||||
vbox.setPadding(new Insets(40, 40, 40, 50));
|
vbox.setPadding(new Insets(40, 40, 40, 50));
|
||||||
vbox.setSpacing(18);
|
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;
|
return vbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +67,16 @@ public class BrowserWelcomeComp extends SimpleComp {
|
||||||
vbox.getChildren().add(restoreLabel);
|
vbox.getChildren().add(restoreLabel);
|
||||||
|
|
||||||
var restoreButton = new Button("Restore sessions");
|
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);
|
vbox.getChildren().add(restoreButton);
|
||||||
|
|
||||||
return vbox;
|
return vbox;
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
package io.xpipe.app.prefs;
|
|
||||||
|
|
||||||
public class UsageNotificationBehaviour {}
|
|
Loading…
Reference in a new issue