From 1aadbc3a7684318a0098d11445c9f38ad3666398 Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 24 Nov 2023 07:24:02 +0000 Subject: [PATCH] Fix browser script integration --- .../app/browser/OpenFileSystemModel.java | 31 ++++++++++++------- .../io/xpipe/core/process/ShellControl.java | 4 ++- dist/changelogs/1.7.8.md | 16 ++++++++++ .../ext/base/browser/OpenTerminalAction.java | 10 +----- .../io/xpipe/ext/base/script/ScriptStore.java | 4 +-- 5 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 dist/changelogs/1.7.8.md diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index b68a3712..9f5ea4fd 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -160,7 +160,7 @@ public final class OpenFileSystemModel { .getShell() .get() .subShell(adjustedPath) - .initWith(new SimpleScriptSnippet( + .withInitSnippet(new SimpleScriptSnippet( fileSystem .getShell() .get() @@ -363,6 +363,9 @@ public final class OpenFileSystemModel { public void initFileSystem() throws Exception { BooleanScope.execute(busy, () -> { var fs = entry.getStore().createFileSystem(); + if (fs.getShell().isPresent()) { + ProcessControlProvider.get().withDefaultScripts(fs.getShell().get()); + } fs.open(); this.fileSystem = fs; this.local = fs.getShell() @@ -392,17 +395,23 @@ public final class OpenFileSystemModel { } BooleanScope.execute(busy, () -> { - if (entry.getStore() instanceof ShellStore s) { - var connection = ((ConnectionFileSystem) fileSystem).getShellControl(); - var name = directory + " - " + entry.get().getName(); - var toOpen = ProcessControlProvider.get().withDefaultScripts(connection); - TerminalHelper.open( - entry.getEntry(), - name, - toOpen.initWith(new SimpleScriptSnippet(connection.getShellDialect().getCdCommand(directory), ScriptSnippet.ExecutionType.BOTH))); + if (fileSystem.getShell().isPresent()) { + var connection = fileSystem.getShell().get(); + var snippet = directory != null ? new SimpleScriptSnippet(connection.getShellDialect().getCdCommand(directory), + ScriptSnippet.ExecutionType.BOTH) : null; + if (snippet != null) { + connection.withInitSnippet(snippet); + } - // Restart connection as we will have to start it anyway, so we speed it up by doing it preemptively - connection.start(); + try { + var name = (directory != null ? directory + " - " : "") + entry.get().getName(); + TerminalHelper.open(entry.getEntry(), name, connection); + + // Restart connection as we will have to start it anyway, so we speed it up by doing it preemptively + connection.start(); + } finally { + connection.removeInitSnippet(snippet); + } } }); }); diff --git a/core/src/main/java/io/xpipe/core/process/ShellControl.java b/core/src/main/java/io/xpipe/core/process/ShellControl.java index df3e0e35..c43fbbf5 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -155,7 +155,9 @@ public interface ShellControl extends ProcessControl { } ShellControl elevationPassword(FailableSupplier value); - ShellControl initWith(ScriptSnippet snippet); + ShellControl withInitSnippet(ScriptSnippet snippet); + + ShellControl removeInitSnippet(ScriptSnippet snippet); ShellControl additionalTimeout(int ms); diff --git a/dist/changelogs/1.7.8.md b/dist/changelogs/1.7.8.md new file mode 100644 index 00000000..77c465a3 --- /dev/null +++ b/dist/changelogs/1.7.8.md @@ -0,0 +1,16 @@ +## Changes in 1.7.8 + +- Make created scripts fully apply to file browser sessions as well +- More startup performance improvements +- Fix dialog window order sometimes being wrong and shown behind main window +- Fix macOS Terminal.app sometimes not launching connection due to a race condition + +## Previous changes in 1.7 + +- [1.7.7](https://github.com/xpipe-io/xpipe/releases/tag/1.7.7) +- [1.7.6](https://github.com/xpipe-io/xpipe/releases/tag/1.7.6) +- [1.7.5](https://github.com/xpipe-io/xpipe/releases/tag/1.7.5) +- [1.7.4](https://github.com/xpipe-io/xpipe/releases/tag/1.7.4) +- [1.7.3](https://github.com/xpipe-io/xpipe/releases/tag/1.7.3) +- [1.7.2](https://github.com/xpipe-io/xpipe/releases/tag/1.7.2) +- [1.7.1](https://github.com/xpipe-io/xpipe/releases/tag/1.7.1) diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/OpenTerminalAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/OpenTerminalAction.java index 71ee2b0e..a5f773cd 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/OpenTerminalAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/OpenTerminalAction.java @@ -4,7 +4,6 @@ import io.xpipe.app.browser.BrowserEntry; import io.xpipe.app.browser.OpenFileSystemModel; import io.xpipe.app.browser.action.LeafAction; import io.xpipe.app.prefs.AppPrefs; -import io.xpipe.app.util.TerminalHelper; import io.xpipe.core.store.FileKind; import javafx.scene.Node; import javafx.scene.input.KeyCode; @@ -22,15 +21,8 @@ public class OpenTerminalAction implements LeafAction { @Override public void execute(OpenFileSystemModel model, List entries) throws Exception { - if (model.getInOverview().get()) { - TerminalHelper.open( - model.getName(), - model.getFileSystem().getShell().orElseThrow()); - return; - } - if (entries.size() == 0) { - model.openTerminalAsync(model.getCurrentDirectory().getPath()); + model.openTerminalAsync(model.getCurrentDirectory() != null ? model.getCurrentDirectory().getPath() : null); return; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptStore.java b/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptStore.java index f19943a8..15418ecf 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptStore.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/script/ScriptStore.java @@ -39,7 +39,7 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore, var dir = initScriptsDirectory(shellControl, bringFlattened); if (dir != null) { - shellControl.initWith(new SimpleScriptSnippet(shellControl.getShellDialect().appendToPathVariableCommand(dir), ScriptSnippet.ExecutionType.TERMINAL_ONLY)); + shellControl.withInitSnippet(new SimpleScriptSnippet(shellControl.getShellDialect().appendToPathVariableCommand(dir), ScriptSnippet.ExecutionType.TERMINAL_ONLY)); } }); return pc; @@ -55,7 +55,7 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore, return; } - pc.initWith(simpleScriptStore); + pc.withInitSnippet(simpleScriptStore); }); }