Improve store toggles [stage]

This commit is contained in:
crschnick
2023-08-04 00:02:26 +00:00
parent 245ba1a238
commit 03b5b67a42
4 changed files with 51 additions and 5 deletions
@@ -0,0 +1,46 @@
package io.xpipe.app.comp.base;
import io.xpipe.app.comp.storage.store.StoreSection;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.fxcomps.util.BindingsHelper;
import io.xpipe.app.storage.DataStoreEntry;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.layout.Region;
import java.util.function.Consumer;
public class StoreToggleComp extends SimpleComp {
private final String nameKey;
private final StoreSection section;
private final BooleanProperty value;
private final Consumer<Boolean> onChange;
public StoreToggleComp(String nameKey, StoreSection section, boolean initial, Consumer<Boolean> onChange) {
this.nameKey = nameKey;
this.section = section;
this.value = new SimpleBooleanProperty(initial);
this.onChange = onChange;
}
@Override
protected Region createSimple() {
var disable = section.getWrapper().getState().map(state -> state != DataStoreEntry.State.COMPLETE_AND_VALID);
var visible = BindingsHelper.persist(Bindings.createBooleanBinding(
() -> {
return (section.getWrapper().getState().getValue() == DataStoreEntry.State.COMPLETE_AND_VALID
|| section.getWrapper().getState().getValue() == DataStoreEntry.State.VALIDATING)
&& section.getShowDetails().get();
},
section.getWrapper().getState(),
section.getShowDetails()));
var t = new NamedToggleComp(value, AppI18n.observable(nameKey))
.visible(visible)
.disable(disable);
value.addListener((observable, oldValue, newValue) -> onChange.accept(newValue));
return t.createRegion();
}
}
@@ -8,7 +8,7 @@ import java.nio.channels.FileLock;
import java.nio.file.Files;
import java.nio.file.Path;
public class AppLock {
public class AppDataLock {
private static FileChannel channel;
private static FileLock lock;
@@ -10,7 +10,7 @@ public class OpenExchangeImpl extends OpenExchange
@Override
public Response handleRequest(BeaconHandler handler, Request msg) {
if (msg.getArguments().size() == 0) {
if (msg.getArguments().isEmpty()) {
OperationMode.switchToAsync(OperationMode.GUI);
}
@@ -1,6 +1,6 @@
package io.xpipe.app.launcher;
import io.xpipe.app.core.AppLock;
import io.xpipe.app.core.AppDataLock;
import io.xpipe.app.core.AppLogs;
import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.issue.ErrorEvent;
@@ -74,7 +74,7 @@ public class LauncherCommand implements Callable<Integer> {
con.constructSocket();
con.performSimpleExchange(
FocusExchange.Request.builder().mode(getEffectiveMode()).build());
if (inputs.size() > 0) {
if (!inputs.isEmpty()) {
con.performSimpleExchange(
OpenExchange.Request.builder().arguments(inputs).build());
}
@@ -95,7 +95,7 @@ public class LauncherCommand implements Callable<Integer> {
// Even in case we are unable to reach another beacon server
// there might be another instance running, for example
// starting up or listening on another port
if (!AppLock.lock()) {
if (!AppDataLock.lock()) {
TrackEvent.info("Data directory is already locked. Quitting ...");
OperationMode.halt(0);
}