mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-19 22:01:12 +00:00
Various shell connection optimizations
This commit is contained in:
parent
d3046933c1
commit
464e04a6bb
|
@ -8,7 +8,6 @@ import io.xpipe.app.core.AppI18n;
|
|||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.extension.I18n;
|
||||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import io.xpipe.extension.fxcomps.Comp;
|
||||
import io.xpipe.extension.fxcomps.SimpleComp;
|
||||
import io.xpipe.extension.fxcomps.SimpleCompStructure;
|
||||
|
@ -21,6 +20,7 @@ import io.xpipe.extension.fxcomps.impl.PrettyImageComp;
|
|||
import io.xpipe.extension.fxcomps.util.PlatformThread;
|
||||
import io.xpipe.extension.fxcomps.util.SimpleChangeListener;
|
||||
import io.xpipe.extension.util.OsHelper;
|
||||
import io.xpipe.extension.util.ThreadHelper;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.css.PseudoClass;
|
||||
|
@ -103,7 +103,9 @@ public class StoreEntryComp extends SimpleComp {
|
|||
var storeIcon = imageComp.createRegion();
|
||||
storeIcon.getStyleClass().add("icon");
|
||||
if (entry.getState().getValue().isUsable()) {
|
||||
new FancyTooltipAugment<>(new SimpleStringProperty(entry.getEntry().getProvider().getDisplayName())).augment(storeIcon);
|
||||
new FancyTooltipAugment<>(new SimpleStringProperty(
|
||||
entry.getEntry().getProvider().getDisplayName()))
|
||||
.augment(storeIcon);
|
||||
}
|
||||
return storeIcon;
|
||||
}
|
||||
|
@ -122,7 +124,6 @@ public class StoreEntryComp extends SimpleComp {
|
|||
|
||||
var storeIcon = createIcon();
|
||||
|
||||
|
||||
grid.getColumnConstraints()
|
||||
.addAll(
|
||||
createShareConstraint(grid, STORE_TYPE_WIDTH), createShareConstraint(grid, NAME_WIDTH),
|
||||
|
@ -167,11 +168,9 @@ public class StoreEntryComp extends SimpleComp {
|
|||
|
||||
var button = new IconButtonComp(
|
||||
actionProvider.getIcon(entry.getEntry().getStore().asNeeded()), () -> {
|
||||
try {
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
actionProvider.execute(entry.getEntry().getStore().asNeeded());
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
}
|
||||
});
|
||||
});
|
||||
button.apply(new FancyTooltipAugment<>(
|
||||
actionProvider.getName(entry.getEntry().getStore().asNeeded())));
|
||||
|
@ -224,11 +223,9 @@ public class StoreEntryComp extends SimpleComp {
|
|||
var icon = actionProvider.getIcon(entry.getEntry().getStore().asNeeded());
|
||||
var item = new MenuItem(null, new FontIcon(icon));
|
||||
item.setOnAction(event -> {
|
||||
try {
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
actionProvider.execute(entry.getEntry().getStore().asNeeded());
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
}
|
||||
});
|
||||
});
|
||||
item.textProperty().bind(name);
|
||||
item.disableProperty().bind(Bindings.not(p.getValue()));
|
||||
|
|
|
@ -11,7 +11,6 @@ import io.xpipe.core.process.ShellProcessControl;
|
|||
import io.xpipe.core.process.ShellTypes;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
import io.xpipe.core.util.XPipeInstallation;
|
||||
import io.xpipe.core.util.XPipeTempDirectory;
|
||||
import io.xpipe.extension.util.ScriptHelper;
|
||||
import lombok.Getter;
|
||||
|
||||
|
@ -38,8 +37,7 @@ public class AppInstaller {
|
|||
if (s.isLocal()) {
|
||||
targetFile = localFile.toString();
|
||||
} else {
|
||||
targetFile = FileNames.join(
|
||||
XPipeTempDirectory.get(s), localFile.getFileName().toString());
|
||||
targetFile = FileNames.join(s.getTemporaryDirectory(), localFile.getFileName().toString());
|
||||
try (CommandProcessControl c = s.command(s.getShellType().getStreamFileWriteCommand(targetFile))
|
||||
.start()) {
|
||||
c.discardOut();
|
||||
|
|
|
@ -19,8 +19,6 @@ def getArchName() {
|
|||
return arch
|
||||
}
|
||||
|
||||
println(System.getenv('RELEASE'))
|
||||
|
||||
project.ext {
|
||||
ci = System.getenv('CI') != null
|
||||
os = org.gradle.internal.os.OperatingSystem.current()
|
||||
|
|
|
@ -15,6 +15,11 @@ public interface ShellProcessControl extends ProcessControl {
|
|||
|
||||
String prepareIntermediateTerminalOpen(String content) throws Exception;
|
||||
|
||||
String getTemporaryDirectory() throws Exception;
|
||||
|
||||
public void checkRunning() throws Exception;
|
||||
|
||||
|
||||
default String executeStringSimpleCommand(String command) throws Exception {
|
||||
try (CommandProcessControl c = command(command).start()) {
|
||||
return c.readOrThrow();
|
||||
|
|
|
@ -6,7 +6,6 @@ import io.xpipe.core.process.ShellProcessControl;
|
|||
import io.xpipe.core.process.ShellType;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
import io.xpipe.core.util.SecretValue;
|
||||
import io.xpipe.core.util.XPipeTempDirectory;
|
||||
import io.xpipe.extension.event.TrackEvent;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
|
@ -15,10 +14,10 @@ import java.util.Random;
|
|||
|
||||
public class ScriptHelper {
|
||||
|
||||
public static int getConnectionHash(String command) {
|
||||
// This deterministic approach can cause permission problems when two different users execute the same command on a system
|
||||
public static int getScriptId() {
|
||||
// A deterministic approach can cause permission problems when two different users execute the same command on a system
|
||||
// Therefore, use a random approach
|
||||
return new Random().nextInt(Integer.MAX_VALUE);
|
||||
//return Math.abs(Objects.hash(command, XPipeSession.get().getSystemSessionId()));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
@ -44,7 +43,8 @@ public class ScriptHelper {
|
|||
}
|
||||
|
||||
if (toExecuteInShell != null) {
|
||||
content += toExecuteInShell + nl;
|
||||
// Normalize line endings
|
||||
content += String.join(nl, toExecuteInShell.lines().toList()) + nl;
|
||||
content += t.getExitCommand() + nl;
|
||||
}
|
||||
|
||||
|
@ -52,19 +52,11 @@ public class ScriptHelper {
|
|||
return t.getInitFileOpenCommand(initFile);
|
||||
}
|
||||
|
||||
public static String prepend(ShellProcessControl processControl, List<String> init, String commands) {
|
||||
var prefix = init != null && init.size() > 0
|
||||
? String.join(processControl.getShellType().getNewLine().getNewLineString(), init)
|
||||
+ processControl.getShellType().getNewLine().getNewLineString()
|
||||
: "";
|
||||
return prefix + commands;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String createExecScript(ShellProcessControl processControl, String content, boolean restart) {
|
||||
var fileName = "exec-" + getConnectionHash(content);
|
||||
var fileName = "exec-" + getScriptId();
|
||||
ShellType type = processControl.getShellType();
|
||||
var temp = XPipeTempDirectory.get(processControl);
|
||||
var temp = processControl.getTemporaryDirectory();
|
||||
var file = FileNames.join(temp, fileName + "." + type.getScriptFileEnding());
|
||||
return createExecScript(processControl, file, content, restart);
|
||||
}
|
||||
|
@ -75,20 +67,15 @@ public class ScriptHelper {
|
|||
ShellType type = processControl.getShellType();
|
||||
content = type.prepareScriptContent(content);
|
||||
|
||||
if (processControl.executeBooleanSimpleCommand(type.getFileExistsCommand(file))) {
|
||||
return file;
|
||||
}
|
||||
|
||||
TrackEvent.withTrace("proc", "Writing exec script")
|
||||
.tag("file", file)
|
||||
.tag("content", content)
|
||||
.handle();
|
||||
|
||||
processControl.executeSimpleCommand(type.getFileTouchCommand(file), "Failed to create script " + file);
|
||||
// processControl.executeSimpleCommand(type.getFileTouchCommand(file), "Failed to create script " + file);
|
||||
processControl.executeSimpleCommand(type.getTextFileWriteCommand(content, file));
|
||||
processControl.executeSimpleCommand(
|
||||
type.getMakeExecutableCommand(file), "Failed to make script " + file + " executable");
|
||||
|
||||
processControl.executeSimpleCommand(type.getTextFileWriteCommand(content, file));
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@ -96,8 +83,8 @@ public class ScriptHelper {
|
|||
public static String createAskPassScript(
|
||||
SecretValue pass, ShellProcessControl parent, ShellType type, boolean restart) {
|
||||
var content = type.getScriptEchoCommand(pass.getSecretValue());
|
||||
var temp = XPipeTempDirectory.get(parent);
|
||||
var file = FileNames.join(temp, "askpass-" + getConnectionHash(content) + "." + type.getScriptFileEnding());
|
||||
var temp = parent.getTemporaryDirectory();
|
||||
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
|
||||
return createExecScript(parent, file, content, restart);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue