From 6cf5b8ad45bed2e80bb4402cfd946ce30562930a Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 12 Nov 2024 09:57:06 +0000 Subject: [PATCH] Various fixes --- .../beacon/impl/TerminalWaitExchangeImpl.java | 2 +- .../io/xpipe/app/comp/base/AppLayoutComp.java | 4 +--- .../xpipe/app/comp/base/TileButtonComp.java | 2 +- .../xpipe/app/terminal/TabbyTerminalType.java | 20 +++++++++++-------- .../app/terminal/TerminalLaunchRequest.java | 4 ++++ .../app/terminal/TerminalLauncherManager.java | 11 ++++++++-- .../xpipe/app/resources/style/dialog-comp.css | 2 +- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java index 18398fe3e..131450996 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalWaitExchangeImpl.java @@ -12,7 +12,7 @@ public class TerminalWaitExchangeImpl extends TerminalWaitExchange { @Override public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException { TerminalView.get().open(msg.getRequest(), msg.getPid()); - TerminalLauncherManager.waitExchange(msg.getRequest()); + TerminalLauncherManager.waitExchange(msg.getRequest(), msg.getPid()); return Response.builder().build(); } diff --git a/app/src/main/java/io/xpipe/app/comp/base/AppLayoutComp.java b/app/src/main/java/io/xpipe/app/comp/base/AppLayoutComp.java index 626bfce50..6a350f010 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/AppLayoutComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/AppLayoutComp.java @@ -47,7 +47,7 @@ public class AppLayoutComp extends Comp> { var sidebarR = sidebar.createRegion(); pane.setRight(sidebarR); model.getSelected().addListener((c, o, n) -> { - if (o != null && o.equals(model.getEntries().get(3))) { + if (o != null && o.equals(model.getEntries().get(2))) { AppPrefs.get().save(); DataStorage.get().saveAsync(); } @@ -55,8 +55,6 @@ public class AppLayoutComp extends Comp> { if (o != null && o.equals(model.getEntries().get(0))) { StoreViewState.get().updateDisplay(); } - - // TerminalView.get().toggleView(model.getEntries().get(2).equals(n)); }); pane.addEventHandler(KeyEvent.KEY_PRESSED, event -> { sidebarR.getChildrenUnmodifiable().forEach(node -> { diff --git a/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java b/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java index b97d94cd3..804d40623 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java @@ -52,7 +52,7 @@ public class TileButtonComp extends Comp { var desc = new Label(); desc.textProperty().bind(PlatformThread.sync(description)); AppFont.small(desc); - desc.setOpacity(0.65); + desc.setOpacity(0.8); var text = new VBox(header, desc); text.setSpacing(2); diff --git a/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java b/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java index 6f3990acb..4923b8c1a 100644 --- a/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java +++ b/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java @@ -56,6 +56,11 @@ public interface TabbyTerminalType extends ExternalTerminalType, TrackableTermin super("app.tabby", "Tabby.exe"); } + @Override + public int getProcessHierarchyOffset() { + return 1; + } + @Override public boolean isRecommended() { return false; @@ -72,15 +77,14 @@ public interface TabbyTerminalType extends ExternalTerminalType, TrackableTermin .add("run") .addFile(configuration.getScriptFile()) .discardOutput()); + } else { + // This is probably not going to work as it does not launch a bat file + LocalShell.getShell().executeSimpleCommand(CommandBuilder.of() + .addFile(file.toString()) + .add("run") + .add(configuration.getDialectLaunchCommand()) + .discardOutput()); } - - // This is probably not going to work as it does not launch a bat file - LocalShell.getShell() - .executeSimpleCommand(CommandBuilder.of() - .addFile(file.toString()) - .add("run") - .add(configuration.getDialectLaunchCommand()) - .discardOutput()); } @Override diff --git a/app/src/main/java/io/xpipe/app/terminal/TerminalLaunchRequest.java b/app/src/main/java/io/xpipe/app/terminal/TerminalLaunchRequest.java index be89ca65c..7b294fe3a 100644 --- a/app/src/main/java/io/xpipe/app/terminal/TerminalLaunchRequest.java +++ b/app/src/main/java/io/xpipe/app/terminal/TerminalLaunchRequest.java @@ -22,6 +22,10 @@ public class TerminalLaunchRequest { TerminalInitScriptConfig config; String workingDirectory; + @Setter + @NonFinal + long pid; + @Setter @NonFinal TerminalLaunchResult result; diff --git a/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java b/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java index 6a0774567..5aa61e46b 100644 --- a/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java +++ b/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java @@ -51,7 +51,7 @@ public class TerminalLauncherManager { synchronized (entries) { var req = entries.get(request); if (req == null) { - req = new TerminalLaunchRequest(request, processControl, config, directory, null, false, null); + req = new TerminalLaunchRequest(request, processControl, config, directory, -1, null, false, null); entries.put(request, req); } else { req.setResult(null); @@ -74,7 +74,7 @@ public class TerminalLauncherManager { return last.waitForCompletion(); } - public static Path waitExchange(UUID request) throws BeaconClientException, BeaconServerException { + public static Path waitExchange(UUID request, long pid) throws BeaconClientException, BeaconServerException { TerminalLaunchRequest req; synchronized (entries) { req = entries.get(request); @@ -85,6 +85,13 @@ public class TerminalLauncherManager { if (req.isSetupCompleted() && AppPrefs.get().dontAllowTerminalRestart().get()) { throw new BeaconClientException("Terminal session restarts have been disabled in the security settings"); } + + var shell = ProcessHandle.of(pid).orElseThrow().parent().orElseThrow(); + if (req.getPid() != -1 && shell.pid() != req.getPid()) { + throw new BeaconClientException("Wrong launch context"); + } + req.setPid(shell.pid()); + if (req.isSetupCompleted()) { submitAsync(req.getRequest(), req.getProcessControl(), req.getConfig(), req.getWorkingDirectory()); } diff --git a/app/src/main/resources/io/xpipe/app/resources/style/dialog-comp.css b/app/src/main/resources/io/xpipe/app/resources/style/dialog-comp.css index 0c8299744..8701d665a 100644 --- a/app/src/main/resources/io/xpipe/app/resources/style/dialog-comp.css +++ b/app/src/main/resources/io/xpipe/app/resources/style/dialog-comp.css @@ -16,6 +16,6 @@ .dialog-comp .buttons { -fx-padding: 10; -fx-border-color: -color-border-default; - -fx-background-color: -color-bg-subtle; + -fx-background-color: -color-bg-inset; -fx-border-width: 1 0 0 0; }