mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 10:22:58 +08:00
feat: detecting SFTP program (#241)
This commit is contained in:
@@ -26,6 +26,18 @@ class SFTPPtyTerminalTab(windowScope: WindowScope, host: Host) : PtyHostTerminal
|
||||
private var sshSession: ClientSession? = null
|
||||
private var lastPasswordReporterDataListener: PasswordReporterDataListener? = null
|
||||
|
||||
companion object {
|
||||
val canSupports by lazy {
|
||||
val process = if (SystemInfo.isWindows) {
|
||||
ProcessBuilder("cmd.exe", "/c", "where", "sftp1").start()
|
||||
} else {
|
||||
ProcessBuilder("which", "sftp1").start()
|
||||
}
|
||||
process.waitFor()
|
||||
return@lazy process.exitValue() == 0
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun openPtyConnector(): PtyConnector {
|
||||
|
||||
|
||||
|
||||
@@ -18,11 +18,8 @@ import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
import java.beans.PropertyChangeListener
|
||||
import java.util.*
|
||||
import javax.swing.Icon
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.*
|
||||
import javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT
|
||||
import javax.swing.SwingUtilities
|
||||
import kotlin.math.min
|
||||
|
||||
class TerminalTabbed(
|
||||
@@ -243,8 +240,17 @@ class TerminalTabbed(
|
||||
popupMenu.addSeparator()
|
||||
val sftpCommand = popupMenu.add(I18n.getString("termora.tabbed.contextmenu.sftp-command"))
|
||||
sftpCommand.addActionListener {
|
||||
actionManager.getAction(OpenHostAction.OPEN_HOST)
|
||||
?.actionPerformed(OpenHostActionEvent(this, tab.host.copy(protocol = Protocol.SFTPPty), it))
|
||||
if (SFTPPtyTerminalTab.canSupports) {
|
||||
actionManager.getAction(OpenHostAction.OPEN_HOST)
|
||||
?.actionPerformed(OpenHostActionEvent(this, tab.host.copy(protocol = Protocol.SFTPPty), it))
|
||||
} else {
|
||||
OptionPane.showMessageDialog(
|
||||
SwingUtilities.getWindowAncestor(this),
|
||||
I18n.getString("termora.tabbed.contextmenu.sftp-not-install"),
|
||||
messageType = JOptionPane.ERROR_MESSAGE
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,13 @@ class OpenHostAction : AnAction() {
|
||||
val terminalTabbedManager = evt.getData(DataProviders.TerminalTabbedManager) ?: return
|
||||
val windowScope = evt.getData(DataProviders.WindowScope) ?: return
|
||||
|
||||
// 如果不支持 SFTP 那么不处理这个响应
|
||||
if (evt.host.protocol == Protocol.SFTPPty) {
|
||||
if (!SFTPPtyTerminalTab.canSupports) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val tab = when (evt.host.protocol) {
|
||||
Protocol.SSH -> SSHTerminalTab(windowScope, evt.host)
|
||||
Protocol.Serial -> SerialTerminalTab(windowScope, evt.host)
|
||||
|
||||
Reference in New Issue
Block a user