Rework session toggle visibility

This commit is contained in:
crschnick
2025-10-14 20:34:01 +00:00
parent c53f123782
commit afcfe21f8a
4 changed files with 34 additions and 16 deletions
@@ -8,6 +8,10 @@ public interface SingletonSessionStore<T extends Session>
stopSessionIfNeeded();
}
default boolean supportsSession() {
return true;
}
default boolean isSessionRunning() {
return getCache("sessionRunning", Boolean.class, false);
}
@@ -36,6 +40,10 @@ public interface SingletonSessionStore<T extends Session>
}
default T startSessionIfNeeded() throws Exception {
if (!supportsSession()) {
return null;
}
synchronized (this) {
var s = getSession();
if (s != null) {
@@ -5,6 +5,7 @@ import io.xpipe.app.hub.action.impl.ToggleActionProvider;
import io.xpipe.app.hub.comp.*;
import io.xpipe.app.platform.LabelGraphic;
import io.xpipe.app.storage.DataStorage;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue;
@@ -32,6 +33,10 @@ public interface SingletonSessionStoreProvider extends DataStoreProvider {
return new SystemStateComp(Bindings.createObjectBinding(
() -> {
SingletonSessionStore<?> s = w.getEntry().getStore().asNeeded();
if (!s.supportsSession()) {
return SystemStateComp.State.SUCCESS;
}
if (!s.isSessionEnabled() || (s.isSessionEnabled() && !s.isSessionRunning())) {
return SystemStateComp.State.OTHER;
}
@@ -71,7 +76,19 @@ public interface SingletonSessionStoreProvider extends DataStoreProvider {
action.executeAsync();
}
});
t.setCustomVisibility(Bindings.createBooleanBinding(
() -> {
SingletonSessionStore<?> s = sec.getWrapper().getEntry().getStore().asNeeded();
return s.supportsSession() && (showToggleWhenInactive(sec.getWrapper().getStore().getValue()) || s.isSessionEnabled());
},
sec.getWrapper().getCache()));
t.tooltipKey("enabled");
return t;
}
default boolean showToggleWhenInactive(DataStore store) {
return true;
}
}
@@ -31,6 +31,13 @@ public abstract class AbstractServiceStore implements SingletonSessionStore<Netw
return true;
}
@Override
public boolean supportsSession() {
return getHost() == null
|| !getHost().getStore().requiresTunnel()
|| !getHost().getStore().isLocallyTunnelable();
}
@Override
public void checkComplete() throws Throwable {
Validators.nonNull(getHost());
@@ -96,22 +96,8 @@ public abstract class AbstractServiceStoreProvider implements SingletonSessionSt
}
@Override
public StoreEntryComp customEntryComp(StoreSection sec, boolean preferLarge) {
var toggle = createToggleComp(sec);
toggle.setCustomVisibility(Bindings.createBooleanBinding(
() -> {
AbstractServiceStore s =
sec.getWrapper().getEntry().getStore().asNeeded();
if (s.getHost() == null
|| !s.getHost().getStore().requiresTunnel()
|| !s.getHost().getStore().isLocallyTunnelable()) {
return false;
}
return true;
},
sec.getWrapper().getCache()));
return new DenseStoreEntryComp(sec, toggle);
public boolean showToggleWhenInactive(DataStore store) {
return false;
}
@Override