Fix ssh bridge issues

This commit is contained in:
crschnick 2024-08-28 23:09:28 +00:00
parent 6cb9e1e553
commit 2831e8372a
6 changed files with 72 additions and 22 deletions

View file

@ -6,6 +6,7 @@ import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.UserReportComp; import io.xpipe.app.issue.UserReportComp;
import io.xpipe.app.terminal.ExternalTerminalType;
import io.xpipe.app.util.DesktopHelper; import io.xpipe.app.util.DesktopHelper;
import io.xpipe.app.util.FileOpener; import io.xpipe.app.util.FileOpener;
import io.xpipe.app.util.OptionsBuilder; import io.xpipe.app.util.OptionsBuilder;
@ -45,8 +46,10 @@ public class TroubleshootCategory extends AppPrefsCategory {
XPipeInstallation.getCurrentInstallationBasePath() XPipeInstallation.getCurrentInstallationBasePath()
.toString(), .toString(),
XPipeInstallation.getDaemonDebugScriptPath(OsType.getLocal())); XPipeInstallation.getDaemonDebugScriptPath(OsType.getLocal()));
// We can't use the SSH bridge
var type = ExternalTerminalType.determineNonSshBridgeFallback(AppPrefs.get().terminalType().getValue());
TerminalLauncher.openDirect("XPipe Debug", sc -> sc.getShellDialect() TerminalLauncher.openDirect("XPipe Debug", sc -> sc.getShellDialect()
.runScriptCommand(sc, script)); .runScriptCommand(sc, script), type);
}); });
e.consume(); e.consume();
}) })

View file

@ -70,6 +70,31 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
// } // }
// }; // };
static ExternalTerminalType determineNonSshBridgeFallback(ExternalTerminalType type) {
if (type == XSHELL || type == MOBAXTERM || type == SECURECRT) {
return CMD;
}
if (type != TERMIUS) {
return type;
}
switch (OsType.getLocal()) {
case OsType.Linux linux -> {
// This should not be termius as all others take precedence
var def = determineDefault(type);
// If there's no other terminal available, use a fallback which won't work
return def != TERMIUS ? def : XTERM;
}
case OsType.MacOs macOs -> {
return MACOS_TERMINAL;
}
case OsType.Windows windows -> {
return CMD;
}
}
}
ExternalTerminalType XSHELL = new WindowsType("app.xShell", "Xshell") { ExternalTerminalType XSHELL = new WindowsType("app.xShell", "Xshell") {
@Override @Override
@ -319,21 +344,21 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
+ user + "&os=undefined"); + user + "&os=undefined");
} }
private boolean showInfo() { private boolean showInfo() throws IOException {
boolean set = AppCache.get("termiusSetup", Boolean.class, () -> false); boolean set = AppCache.get("termiusSetupa", Boolean.class, () -> false);
if (set) { if (set) {
return true; return true;
} }
var b = SshLocalBridge.get(); var b = SshLocalBridge.get();
var keyName = b.getIdentityKey().getFileName().toString(); var keyContent = Files.readString(b.getIdentityKey());
var r = AppWindowHelper.showBlockingAlert(alert -> { var r = AppWindowHelper.showBlockingAlert(alert -> {
alert.setTitle(AppI18n.get("termiusSetup")); alert.setTitle(AppI18n.get("termiusSetup"));
alert.setAlertType(Alert.AlertType.NONE); alert.setAlertType(Alert.AlertType.NONE);
var activated = AppI18n.get() var activated = AppI18n.get()
.getMarkdownDocumentation("app:termiusSetup") .getMarkdownDocumentation("app:termiusSetup")
.formatted(b.getIdentityKey(), keyName); .formatted(b.getIdentityKey(), keyContent);
var markdown = new MarkdownComp(activated, s -> s) var markdown = new MarkdownComp(activated, s -> s)
.prefWidth(450) .prefWidth(450)
.prefHeight(400) .prefHeight(400)
@ -471,7 +496,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
@Override @Override
public boolean supportsColoredTitle() { public boolean supportsColoredTitle() {
return true; return false;
} }
@Override @Override
@ -979,13 +1004,13 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
TabbyTerminalType.TABBY_WINDOWS, TabbyTerminalType.TABBY_WINDOWS,
AlacrittyTerminalType.ALACRITTY_WINDOWS, AlacrittyTerminalType.ALACRITTY_WINDOWS,
WezTerminalType.WEZTERM_WINDOWS, WezTerminalType.WEZTERM_WINDOWS,
CMD,
PWSH,
POWERSHELL,
MOBAXTERM, MOBAXTERM,
SECURECRT, SECURECRT,
TERMIUS, TERMIUS,
XSHELL, XSHELL);
CMD,
PWSH,
POWERSHELL);
List<ExternalTerminalType> LINUX_TERMINALS = List.of( List<ExternalTerminalType> LINUX_TERMINALS = List.of(
KittyTerminalType.KITTY_LINUX, KittyTerminalType.KITTY_LINUX,
AlacrittyTerminalType.ALACRITTY_LINUX, AlacrittyTerminalType.ALACRITTY_LINUX,
@ -1002,7 +1027,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
XTERM, XTERM,
DEEPIN_TERMINAL, DEEPIN_TERMINAL,
FOOT, FOOT,
Q_TERMINAL); Q_TERMINAL,
TERMIUS);
List<ExternalTerminalType> MACOS_TERMINALS = List.of( List<ExternalTerminalType> MACOS_TERMINALS = List.of(
KittyTerminalType.KITTY_MACOS, KittyTerminalType.KITTY_MACOS,
WARP, WARP,
@ -1010,7 +1036,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
TabbyTerminalType.TABBY_MAC_OS, TabbyTerminalType.TABBY_MAC_OS,
AlacrittyTerminalType.ALACRITTY_MAC_OS, AlacrittyTerminalType.ALACRITTY_MAC_OS,
WezTerminalType.WEZTERM_MAC_OS, WezTerminalType.WEZTERM_MAC_OS,
MACOS_TERMINAL); MACOS_TERMINAL,
TERMIUS);
List<ExternalTerminalType> ALL = getTypes(OsType.getLocal(), false, true); List<ExternalTerminalType> ALL = getTypes(OsType.getLocal(), false, true);

View file

@ -4,6 +4,7 @@ import io.xpipe.app.core.AppLogs;
import io.xpipe.app.core.AppProperties; import io.xpipe.app.core.AppProperties;
import io.xpipe.app.core.mode.OperationMode; import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.terminal.ExternalTerminalType;
import io.xpipe.app.util.LocalShell; import io.xpipe.app.util.LocalShell;
import io.xpipe.app.util.ScriptHelper; import io.xpipe.app.util.ScriptHelper;
import io.xpipe.app.util.TerminalLauncher; import io.xpipe.app.util.TerminalLauncher;
@ -163,7 +164,9 @@ public class AppInstaller {
file, file, name); file, file, name);
runAndClose(() -> { runAndClose(() -> {
TerminalLauncher.openDirect("XPipe Updater", sc -> command); // We can't use the SSH bridge
var type = ExternalTerminalType.determineNonSshBridgeFallback(AppPrefs.get().terminalType().getValue());
TerminalLauncher.openDirect("XPipe Updater", sc -> command, type);
}); });
} }
@ -201,7 +204,9 @@ public class AppInstaller {
file, file, name); file, file, name);
runAndClose(() -> { runAndClose(() -> {
TerminalLauncher.openDirect("XPipe Updater", sc -> command); // We can't use the SSH bridge
var type = ExternalTerminalType.determineNonSshBridgeFallback(AppPrefs.get().terminalType().getValue());
TerminalLauncher.openDirect("XPipe Updater", sc -> command, type);
}); });
} }
@ -239,7 +244,9 @@ public class AppInstaller {
file, file, name); file, file, name);
runAndClose(() -> { runAndClose(() -> {
TerminalLauncher.openDirect("XPipe Updater", sc -> command); // We can't use the SSH bridge
var type = ExternalTerminalType.determineNonSshBridgeFallback(AppPrefs.get().terminalType().getValue());
TerminalLauncher.openDirect("XPipe Updater", sc -> command, type);
}); });
} }

View file

@ -67,11 +67,16 @@ public class SshLocalBridge {
return; return;
} }
var server = AppBeaconServer.get();
if (server == null) {
return;
}
// Add a gap to not interfere with PTB or dev ports
var port = server.getPort() + 10;
try (var sc = LocalShell.getShell().start()) { try (var sc = LocalShell.getShell().start()) {
var bridgeDir = AppProperties.get().getDataDir().resolve("ssh_bridge"); var bridgeDir = AppProperties.get().getDataDir().resolve("ssh_bridge");
Files.createDirectories(bridgeDir); Files.createDirectories(bridgeDir);
// Add a gap to not interfere with PTB or dev ports
var port = AppBeaconServer.get().getPort() + 10;
var user = sc.getShellDialect().printUsernameCommand(sc).readStdoutOrThrow(); var user = sc.getShellDialect().printUsernameCommand(sc).readStdoutOrThrow();
INSTANCE = new SshLocalBridge(bridgeDir, port, user); INSTANCE = new SshLocalBridge(bridgeDir, port, user);

View file

@ -17,11 +17,15 @@ public class TerminalLauncher {
public static void openDirect(String title, FailableFunction<ShellControl, String, Exception> command) public static void openDirect(String title, FailableFunction<ShellControl, String, Exception> command)
throws Exception { throws Exception {
var type = AppPrefs.get().terminalType().getValue();
if (type == null) {
throw ErrorEvent.expected(new IllegalStateException(AppI18n.get("noTerminalSet")));
}
openDirect(title, command, type);
}
public static void openDirect(String title, FailableFunction<ShellControl, String, Exception> command, ExternalTerminalType type)
throws Exception {
try (var sc = LocalShell.getShell().start()) { try (var sc = LocalShell.getShell().start()) {
var type = AppPrefs.get().terminalType().getValue();
if (type == null) {
throw ErrorEvent.expected(new IllegalStateException(AppI18n.get("noTerminalSet")));
}
var script = ScriptHelper.constructTerminalInitFile( var script = ScriptHelper.constructTerminalInitFile(
sc.getShellDialect(), sc.getShellDialect(),
sc, sc,

View file

@ -2,4 +2,8 @@
To use Termius as your terminal, you can connect it to the XPipe SSH bridge. This can work automatically once the local bridge ssh key has been added to Termius. To use Termius as your terminal, you can connect it to the XPipe SSH bridge. This can work automatically once the local bridge ssh key has been added to Termius.
The only thing you have to do manually is to add the private key file `%s` to Termius first. The only thing you have to do manually is to add the private key file `%s` to Termius first:
```
%s
```