This commit is contained in:
crschnick 2024-06-09 18:45:49 +00:00
parent ecb8a68937
commit b4800bdecd
8 changed files with 101 additions and 10 deletions

View file

@ -89,7 +89,17 @@ public interface OsType {
@Override
public String getTempDirectory(ShellControl pc) throws Exception {
return pc.executeSimpleStringCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP"));
var def = pc.executeSimpleStringCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP"));
if (!def.isBlank() && pc.getShellDialect().directoryExists(pc, def).executeAndCheck()) {
return def;
}
var fallback = pc.executeSimpleStringCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("LOCALAPPDATA"));
if (!fallback.isBlank() && pc.getShellDialect().directoryExists(pc, fallback).executeAndCheck()) {
return fallback;
}
return def;
}
@Override
@ -116,7 +126,7 @@ public interface OsType {
.trim();
} catch (Throwable t) {
// Just in case this fails somehow
return "Windows ?";
return "Windows";
}
}
}

View file

@ -112,7 +112,7 @@ public interface NetworkTunnelStore extends DataStore {
@Override
public int getLocalPort() {
return local;
return remotePort;
}
@Override

View file

@ -34,6 +34,8 @@ If you have existing scripts, they will have to be manually adjusted by setting
The docker integration has been updated to support docker contexts. The UI has also been streamlined to make common actions more easily accessible.
There's also now support for Windows containers running on HyperV.
Note that old docker container connections will be removed as they are incompatible with the new version.
## Better connection organization

View file

@ -24,6 +24,10 @@ public abstract class AbstractServiceStore extends JacksonizedValue implements S
Validators.nonNull(remotePort);
}
public boolean requiresTunnel() {
return getHost().getStore().requiresTunnel();
}
@Override
public NetworkTunnelSession newSession() throws Exception {
var l = localPort != null ? localPort : HostHelper.findRandomOpenPortOnAllLocalInterfaces();

View file

@ -1,10 +1,12 @@
package io.xpipe.ext.base.service;
import io.xpipe.app.comp.base.SystemStateComp;
import io.xpipe.app.comp.store.StoreEntryComp;
import io.xpipe.app.comp.store.StoreEntryWrapper;
import io.xpipe.app.comp.store.StoreSection;
import io.xpipe.app.ext.DataStoreProvider;
import io.xpipe.app.ext.SingletonSessionStoreProvider;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.app.util.DataStoreFormatter;
@ -23,6 +25,24 @@ public abstract class AbstractServiceStoreProvider implements SingletonSessionSt
return DataStorage.get().getOrCreateNewSyntheticEntry(s.getHost().get(), "Services", ServiceGroupStore.builder().parent(s.getHost()).build());
}
@Override
public Comp<?> stateDisplay(StoreEntryWrapper w) {
return new SystemStateComp(Bindings.createObjectBinding(
() -> {
AbstractServiceStore s = w.getEntry().getStore().asNeeded();
if (!s.requiresTunnel()) {
return SystemStateComp.State.SUCCESS;
}
if (!s.isSessionEnabled()) {
return SystemStateComp.State.OTHER;
}
return s.isSessionRunning() ? SystemStateComp.State.SUCCESS : SystemStateComp.State.FAILURE;
},
w.getCache()));
}
@Override
public StoreEntryComp customEntryComp(StoreSection sec, boolean preferLarge) {
var toggle = createToggleComp(sec);

View file

@ -0,0 +1,60 @@
package io.xpipe.ext.base.service;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.ClipboardHelper;
import javafx.beans.value.ObservableValue;
import lombok.Value;
public class ServiceCopyUrlAction implements ActionProvider {
@Override
public LeafDataStoreCallSite<?> getLeafDataStoreCallSite() {
return new LeafDataStoreCallSite<AbstractServiceStore>() {
@Override
public boolean isMajor(DataStoreEntryRef<AbstractServiceStore> o) {
return true;
}
@Override
public boolean canLinkTo() {
return true;
}
@Override
public ActionProvider.Action createAction(DataStoreEntryRef<AbstractServiceStore> store) {
return new Action(store.getStore());
}
@Override
public Class<AbstractServiceStore> getApplicableClass() {
return AbstractServiceStore.class;
}
@Override
public ObservableValue<String> getName(DataStoreEntryRef<AbstractServiceStore> store) {
return AppI18n.observable("copyUrl");
}
@Override
public String getIcon(DataStoreEntryRef<AbstractServiceStore> store) {
return "mdi2c-content-copy";
}
};
}
@Value
static class Action implements ActionProvider.Action {
AbstractServiceStore serviceStore;
@Override
public void execute() throws Exception {
serviceStore.startSessionIfNeeded();
var l = serviceStore.getSession().getLocalPort();
ClipboardHelper.copyUrl("localhost:" + l);
}
}
}

View file

@ -9,11 +9,6 @@ import lombok.Value;
public class ServiceOpenAction implements ActionProvider {
@Override
public String getId() {
return "openWebsite";
}
@Override
public LeafDataStoreCallSite<?> getLeafDataStoreCallSite() {
return new LeafDataStoreCallSite<AbstractServiceStore>() {
@ -45,7 +40,7 @@ public class ServiceOpenAction implements ActionProvider {
@Override
public String getIcon(DataStoreEntryRef<AbstractServiceStore> store) {
return "mdi2w-web";
return "mdi2s-search-web";
}
};
}

View file

@ -58,7 +58,7 @@ open module io.xpipe.ext.base {
UnzipAction,
JavapAction,
JarAction;
provides ActionProvider with ServiceOpenAction,
provides ActionProvider with ServiceOpenAction, ServiceCopyUrlAction,
CloneStoreAction, RefreshChildrenStoreAction, ScanStoreAction, LaunchStoreAction,
XPipeUrlAction,
EditStoreAction, DeleteChildrenStoreAction,