mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Rework state display
This commit is contained in:
parent
9413a167fb
commit
cd5d728950
4 changed files with 79 additions and 41 deletions
|
@ -17,45 +17,6 @@ public class DataStoreFormatter {
|
|||
return String.join(" ", Arrays.stream(elements).filter(s -> s != null).toList());
|
||||
}
|
||||
|
||||
public static String formattedOsName(String osName) {
|
||||
osName = osName.replaceAll("^Microsoft ", "");
|
||||
|
||||
var proRequired = !LicenseProvider.get().checkOsName(osName);
|
||||
if (!proRequired) {
|
||||
return osName;
|
||||
}
|
||||
|
||||
return "[Pro] " + osName;
|
||||
}
|
||||
|
||||
public static ObservableValue<String> shellInformation(StoreEntryWrapper w) {
|
||||
return BindingsHelper.map(w.getPersistentState(), o -> {
|
||||
if (o instanceof ShellStoreState s) {
|
||||
if (s.getRunning() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s.getShellDialect() != null
|
||||
&& !s.getShellDialect().getDumbMode().supportsAnyPossibleInteraction()) {
|
||||
if (s.getOsName() != null) {
|
||||
return formattedOsName(s.getOsName());
|
||||
}
|
||||
|
||||
if (s.getShellDialect().equals(ShellDialects.NO_INTERACTION)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return s.getShellDialect().getDisplayName();
|
||||
}
|
||||
|
||||
var prefix = s.getTtyState() != null && s.getTtyState() != ShellTtyState.NONE ? "[PTY] " : "";
|
||||
return s.isRunning() ? prefix + formattedOsName(s.getOsName()) : "Connection failed";
|
||||
}
|
||||
|
||||
return "?";
|
||||
});
|
||||
}
|
||||
|
||||
public static String capitalize(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
|
|
|
@ -24,7 +24,7 @@ public abstract class LicenseProvider {
|
|||
|
||||
public abstract LicensedFeature getFeature(String id);
|
||||
|
||||
public abstract boolean checkOsName(String name);
|
||||
public abstract LicensedFeature checkOsName(String name);
|
||||
|
||||
public abstract void checkOsNameOrThrow(String s);
|
||||
|
||||
|
|
76
app/src/main/java/io/xpipe/app/util/ShellStoreFormat.java
Normal file
76
app/src/main/java/io/xpipe/app/util/ShellStoreFormat.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.app.comp.store.StoreSection;
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.fxcomps.util.BindingsHelper;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
import io.xpipe.core.process.ShellEnvironmentStoreState;
|
||||
import io.xpipe.core.process.ShellStoreState;
|
||||
import io.xpipe.core.process.ShellTtyState;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Value
|
||||
public class ShellStoreFormat {
|
||||
|
||||
public static ObservableValue<String> shellEnvironment(StoreSection section, boolean includeOsName) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
var s = (ShellEnvironmentStoreState)
|
||||
section.getWrapper().getPersistentState().getValue();
|
||||
var def = Boolean.TRUE.equals(s.getSetDefault()) ? AppI18n.get("default") : null;
|
||||
var name = DataStoreFormatter.join((includeOsName ? s.getOsName() : null), s.getShellName());
|
||||
return new ShellStoreFormat(null,name, new String[]{def}).format();
|
||||
},
|
||||
AppPrefs.get().language(),
|
||||
section.getWrapper().getPersistentState());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends ShellStoreState>ObservableValue<String> shellStore(StoreSection section, Function<T, String> f) {
|
||||
return BindingsHelper.map(section.getWrapper().getPersistentState(), o -> {
|
||||
var s = (T) o;
|
||||
var info = f.apply(s);
|
||||
if (s.getShellDialect() != null
|
||||
&& !s.getShellDialect().getDumbMode().supportsAnyPossibleInteraction()) {
|
||||
if (s.getOsName() != null) {
|
||||
return new ShellStoreFormat(LicenseProvider.get().checkOsName(s.getOsName()), s.getOsName(), new String[]{info}).format();
|
||||
}
|
||||
|
||||
if (s.getShellDialect().equals(ShellDialects.NO_INTERACTION)) {
|
||||
return new ShellStoreFormat(null, null, new String[]{info}).format();
|
||||
}
|
||||
|
||||
return new ShellStoreFormat(LicenseProvider.get().getFeature(s.getShellDialect().getLicenseFeatureId()), s.getShellDialect().getDisplayName(), new String[]{info}).format();
|
||||
}
|
||||
|
||||
return new ShellStoreFormat(LicenseProvider.get().checkOsName(s.getOsName()), s.getOsName(),
|
||||
new String[]{s.getTtyState() != null && s.getTtyState() != ShellTtyState.NONE ? "TTY" : null, info}).format();
|
||||
});
|
||||
}
|
||||
|
||||
LicensedFeature licensedFeature;
|
||||
String name;
|
||||
String[] states;
|
||||
|
||||
public String format() {
|
||||
var lic = licensedFeature != null ? "[" + licensedFeature.getDescriptionSuffix().orElse(null) + "]" : null;
|
||||
var name = this.name;
|
||||
var state = getStates() != null ? Arrays.stream(getStates()).filter(s -> s != null).map(s -> "[" + s + "]").collect(Collectors.joining(" ")) : null;
|
||||
if (state != null && state.isEmpty()) {
|
||||
state = null;
|
||||
}
|
||||
return DataStoreFormatter.join(lic, state, name);
|
||||
}
|
||||
|
||||
public static String formattedOsName(String osName) {
|
||||
osName = osName.replaceAll("^Microsoft ", "");
|
||||
return osName;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import io.xpipe.app.resources.SystemIcons;
|
|||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import io.xpipe.app.util.DataStoreFormatter;
|
||||
import io.xpipe.app.util.ShellStoreFormat;
|
||||
import io.xpipe.app.util.TerminalLauncher;
|
||||
import io.xpipe.core.process.ShellStoreState;
|
||||
import io.xpipe.ext.base.script.ScriptStore;
|
||||
|
@ -72,6 +73,6 @@ public interface ShellStoreProvider extends DataStoreProvider {
|
|||
|
||||
@Override
|
||||
default ObservableValue<String> informationString(StoreSection section) {
|
||||
return DataStoreFormatter.shellInformation(section.getWrapper());
|
||||
return ShellStoreFormat.shellStore(section,state -> null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue