From 1d0a77a2ffe98bbbbb71bea950e828b1b8d1e054 Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 2 Jun 2023 16:33:47 +0000 Subject: [PATCH] Add tabby support --- .../xpipe/app/prefs/ExternalTerminalType.java | 125 ++++++++++-------- .../resources/lang/preferences_en.properties | 2 + 2 files changed, 73 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java index 2ad2311b4..b2fa2c45f 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java @@ -34,19 +34,18 @@ public interface ExternalTerminalType extends PrefsChoiceValue { } }; - ExternalTerminalType POWERSHELL_WINDOWS = - new SimpleType("app.powershell", "powershell", "PowerShell") { + ExternalTerminalType POWERSHELL_WINDOWS = new SimpleType("app.powershell", "powershell", "PowerShell") { - @Override - protected String toCommand(String name, String file) { - return "-ExecutionPolicy Bypass -NoProfile -Command cmd /C '" + file + "'"; - } + @Override + protected String toCommand(String name, String file) { + return "-ExecutionPolicy Bypass -NoProfile -Command cmd /C '" + file + "'"; + } - @Override - public boolean isSelectable() { - return OsType.getLocal().equals(OsType.WINDOWS); - } - }; + @Override + public boolean isSelectable() { + return OsType.getLocal().equals(OsType.WINDOWS); + } + }; ExternalTerminalType PWSH_WINDOWS = new SimpleType("app.pwsh", "pwsh", "PowerShell Core") { @@ -63,24 +62,22 @@ public interface ExternalTerminalType extends PrefsChoiceValue { } }; - ExternalTerminalType WINDOWS_TERMINAL = - new SimpleType("app.windowsTerminal", "wt.exe", "Windows Terminal") { + ExternalTerminalType WINDOWS_TERMINAL = new SimpleType("app.windowsTerminal", "wt.exe", "Windows Terminal") { - @Override - protected String toCommand(String name, String file) { - // A weird behavior in Windows Terminal causes the trailing - // backslash of a filepath to escape the closing quote in the title argument - // So just remove that slash - var fixedName = FileNames.removeTrailingSlash(name); - return "-w 1 nt --title \"" + fixedName + "\" \"" + file + "\""; - } - - @Override - public boolean isSelectable() { - return OsType.getLocal().equals(OsType.WINDOWS); - } - }; + @Override + protected String toCommand(String name, String file) { + // A weird behavior in Windows Terminal causes the trailing + // backslash of a filepath to escape the closing quote in the title argument + // So just remove that slash + var fixedName = FileNames.removeTrailingSlash(name); + return "-w 1 nt --title \"" + fixedName + "\" \"" + file + "\""; + } + @Override + public boolean isSelectable() { + return OsType.getLocal().equals(OsType.WINDOWS); + } + }; public abstract static class WindowsFullPathType extends ExternalApplicationType.WindowsFullPathType implements ExternalTerminalType { @@ -107,45 +104,47 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override protected String createCommand(ShellControl shellControl, String name, String path, String file) { - return shellControl.getShellDialect().fileArgument(path) + " run " + shellControl.getShellDialect().fileArgument(file); + return shellControl.getShellDialect().fileArgument(path) + " run " + + shellControl.getShellDialect().fileArgument(file); } @Override protected Optional determinePath() { Optional launcherDir; - launcherDir = WindowsRegistry.readString(WindowsRegistry.HKEY_CURRENT_USER, "SOFTWARE\\71445fac-d6ef-5436-9da7-5a323762d7f5", "InstallLocation") + launcherDir = WindowsRegistry.readString( + WindowsRegistry.HKEY_CURRENT_USER, + "SOFTWARE\\71445fac-d6ef-5436-9da7-5a323762d7f5", + "InstallLocation") .map(p -> p + "\\Tabby.exe"); return launcherDir.map(Path::of); } }; - ExternalTerminalType GNOME_TERMINAL = - new SimpleType("app.gnomeTerminal", "gnome-terminal", "Gnome Terminal") { + ExternalTerminalType GNOME_TERMINAL = new SimpleType("app.gnomeTerminal", "gnome-terminal", "Gnome Terminal") { - @Override - public void launch(String name, String file, boolean elevated) throws Exception { - try (ShellControl pc = LocalStore.getShell()) { - ApplicationHelper.checkSupport(pc, executable, getDisplayName()); + @Override + public void launch(String name, String file, boolean elevated) throws Exception { + try (ShellControl pc = LocalStore.getShell()) { + ApplicationHelper.checkSupport(pc, executable, getDisplayName()); - var toExecute = executable + " " + toCommand(name, file); - // In order to fix this bug which also affects us: - // https://askubuntu.com/questions/1148475/launching-gnome-terminal-from-vscode - toExecute = - "GNOME_TERMINAL_SCREEN=\"\" nohup " + toExecute + " /dev/null & disown"; - pc.executeSimpleCommand(toExecute); - } - } + var toExecute = executable + " " + toCommand(name, file); + // In order to fix this bug which also affects us: + // https://askubuntu.com/questions/1148475/launching-gnome-terminal-from-vscode + toExecute = "GNOME_TERMINAL_SCREEN=\"\" nohup " + toExecute + " /dev/null & disown"; + pc.executeSimpleCommand(toExecute); + } + } - @Override - protected String toCommand(String name, String file) { - return "-v --title \"" + name + "\" -- \"" + file + "\""; - } + @Override + protected String toCommand(String name, String file) { + return "-v --title \"" + name + "\" -- \"" + file + "\""; + } - @Override - public boolean isSelectable() { - return OsType.getLocal().equals(OsType.LINUX); - } - }; + @Override + public boolean isSelectable() { + return OsType.getLocal().equals(OsType.LINUX); + } + }; ExternalTerminalType KONSOLE = new SimpleType("app.konsole", "konsole", "Konsole") { @@ -194,6 +193,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { XFCE, GNOME_TERMINAL, ITERM2, + TABBY_WINDOWS, WARP, MACOS_TERMINAL, CUSTOM) @@ -300,6 +300,24 @@ public interface ExternalTerminalType extends PrefsChoiceValue { } } + class TabbyType extends ExternalApplicationType.MacApplication implements ExternalTerminalType { + + public TabbyType() { + super("app.tabbyMacOs", "Tabby"); + } + + @Override + public void launch(String name, String file, boolean elevated) throws Exception { + try (ShellControl pc = LocalStore.getShell()) { + pc.osascriptCommand(String.format( + """ + %s/Contents/MacOS/Tabby run %s + """, getApplicationPath().orElseThrow(), pc.getShellDialect().fileArgument(file))) + .execute(); + } + } + } + class WarpType extends ExternalApplicationType.MacApplication implements ExternalTerminalType { public WarpType() { @@ -333,8 +351,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { } @Getter - abstract class SimpleType extends ExternalApplicationType.PathApplication - implements ExternalTerminalType { + abstract class SimpleType extends ExternalApplicationType.PathApplication implements ExternalTerminalType { private final String displayName; diff --git a/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties b/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties index 81ccfa949..c2f56466e 100644 --- a/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties +++ b/app/src/main/resources/io/xpipe/app/resources/lang/preferences_en.properties @@ -85,6 +85,8 @@ xfce=Xfce macosTerminal=Terminal.app iterm2=iTerm2 warp=Warp +tabbyWindows=Tabby +tabbyMacOs=Tabby terminal=Terminal terminalProgram=Default program terminalProgramDescription=The default terminal to use when opening any kind of shell connection. This application is only used for display purposes, the started shell program depends on the shell connection itself.