Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f12efdbb08 | ||
|
|
69f51e5fd8 | ||
|
|
b1355aacff | ||
|
|
0bb7616ed2 | ||
|
|
b446478265 | ||
|
|
7c09aae659 | ||
|
|
9bf76bfed7 |
@@ -142,8 +142,8 @@ fun ConnectTabScreen(viewModel: MainViewModel) {
|
||||
remember(isConnected, remoteAddress, setupResolvedEndpoint, manualResolvedEndpoint, inputMode) {
|
||||
when {
|
||||
isConnected && !remoteAddress.isNullOrBlank() -> remoteAddress!!
|
||||
inputMode == ConnectInputMode.SetupCode -> setupResolvedEndpoint ?: stringResource(R.string.connect_not_set)
|
||||
else -> manualResolvedEndpoint ?: stringResource(R.string.connect_not_set)
|
||||
inputMode == ConnectInputMode.SetupCode -> setupResolvedEndpoint ?: "(not set)"
|
||||
else -> manualResolvedEndpoint ?: "(not set)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ fun ConnectTabScreen(viewModel: MainViewModel) {
|
||||
)
|
||||
if (config == null) {
|
||||
validationText = if (inputMode == ConnectInputMode.SetupCode)
|
||||
stringResource(R.string.connect_validation_setup_code) else stringResource(R.string.connect_validation_address)
|
||||
"Enter a valid Setup Code" else "Enter a valid address"
|
||||
return@Button
|
||||
}
|
||||
validationText = null
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package ai.openclaw.app.ui
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
||||
import ai.openclaw.app.BuildConfig
|
||||
import ai.openclaw.app.R
|
||||
|
||||
@@ -65,6 +65,12 @@ fun SshHost(modifier: Modifier = Modifier) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
fun openSession(config: SshConfig) {
|
||||
// Bug 3: 如果密码为空,弹出连接对话框让用户输入密码
|
||||
if (config.password.isBlank() && config.authMode != "key") {
|
||||
pendingConfig = config
|
||||
showConnectDialog = true
|
||||
return
|
||||
}
|
||||
// 立即创建 tab 显示"连接中"
|
||||
val mgr = SshTerminalManager(sessionId = "${config.host}:${config.port}")
|
||||
activeSessions.add(mgr)
|
||||
@@ -242,12 +248,25 @@ fun SshHost(modifier: Modifier = Modifier) {
|
||||
}
|
||||
|
||||
if (showConnectDialog) {
|
||||
SshConnectDialog(
|
||||
onDismiss = { showConnectDialog = false },
|
||||
onConnectPassword = { config -> showConnectDialog = false; pendingConfig = config },
|
||||
onConnectKey = { config, passphrase -> showConnectDialog = false; pendingKeyConnect = KeyAuthConnect(config, passphrase) },
|
||||
savedConfigs = savedConfigs
|
||||
)
|
||||
// Bug 3: 如果是从空密码连接触发的,预填配置给用户输入密码
|
||||
val prefillConfig = pendingConfig
|
||||
if (prefillConfig != null && prefillConfig.password.isBlank()) {
|
||||
// 预填配置到 dialog 后清除 pending 标记
|
||||
SshConnectDialog(
|
||||
onDismiss = { showConnectDialog = false; pendingConfig = null },
|
||||
onConnectPassword = { config -> showConnectDialog = false; pendingConfig = config },
|
||||
onConnectKey = { config, passphrase -> showConnectDialog = false; pendingKeyConnect = KeyAuthConnect(config, passphrase) },
|
||||
savedConfigs = savedConfigs,
|
||||
initialConfig = prefillConfig
|
||||
)
|
||||
} else {
|
||||
SshConnectDialog(
|
||||
onDismiss = { showConnectDialog = false },
|
||||
onConnectPassword = { config -> showConnectDialog = false; pendingConfig = config },
|
||||
onConnectKey = { config, passphrase -> showConnectDialog = false; pendingKeyConnect = KeyAuthConnect(config, passphrase) },
|
||||
savedConfigs = savedConfigs
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,17 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import android.text.TextWatcher
|
||||
import android.widget.EditText
|
||||
import android.view.KeyEvent as AndroidKeyEvent
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
@@ -69,16 +73,17 @@ fun SshConnectDialog(
|
||||
onConnectPassword: (SshConfig) -> Unit,
|
||||
onConnectKey: (config: SshConfig, passphrase: String?) -> Unit,
|
||||
savedConfigs: List<SshConfig> = emptyList(),
|
||||
onFillConfig: (SshConfig) -> Unit = {}
|
||||
onFillConfig: (SshConfig) -> Unit = {},
|
||||
initialConfig: SshConfig? = null
|
||||
) {
|
||||
var host by remember { mutableStateOf("") }
|
||||
var port by remember { mutableStateOf("22") }
|
||||
var username by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var displayName by remember { mutableStateOf("") }
|
||||
var authMethod by remember { mutableStateOf("password") }
|
||||
var host by remember { mutableStateOf(initialConfig?.host ?: "") }
|
||||
var port by remember { mutableStateOf((initialConfig?.port ?: 22).toString()) }
|
||||
var username by remember { mutableStateOf(initialConfig?.username ?: "") }
|
||||
var password by remember { mutableStateOf(initialConfig?.password ?: "") }
|
||||
var displayName by remember { mutableStateOf(initialConfig?.displayName ?: "") }
|
||||
var authMethod by remember { mutableStateOf(initialConfig?.authMode ?: "password") }
|
||||
var keyPassphrase by remember { mutableStateOf("") }
|
||||
var selectedKeyPath by remember { mutableStateOf("") }
|
||||
var selectedKeyPath by remember { mutableStateOf(initialConfig?.savedKeyPath ?: "") }
|
||||
var passwordVisible by remember { mutableStateOf(false) }
|
||||
var keyPassVisible by remember { mutableStateOf(false) }
|
||||
|
||||
@@ -417,14 +422,14 @@ fun SshTerminalScreen(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val state by manager.connectionState.collectAsState()
|
||||
val inputState = remember { mutableStateOf(TextFieldValue("")) }
|
||||
var currentInput by inputState
|
||||
var currentInput by remember { mutableStateOf("") }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val listState = rememberLazyListState()
|
||||
var showFontPicker by remember { mutableStateOf(false) }
|
||||
var showForwardDialog by remember { mutableStateOf(false) }
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
val currentFontSize = remember { mutableStateOf(SshConfigStorage.loadFontSize(context)) }
|
||||
val editTextRef = remember { mutableStateOf<EditText?>(null) }
|
||||
|
||||
val terminalFontSize = fontMap[currentFontSize.value] ?: 12
|
||||
val terminalFontSizeSp = terminalFontSize.sp
|
||||
@@ -437,7 +442,7 @@ fun SshTerminalScreen(
|
||||
}
|
||||
|
||||
// 获取当前输入的纯文本(用于显示)
|
||||
val currentInputText = currentInput.text
|
||||
val currentInputText = currentInput
|
||||
|
||||
// 硬件键盘处理
|
||||
fun handleKeyEvent(event: KeyEvent): Boolean {
|
||||
@@ -452,13 +457,13 @@ fun SshTerminalScreen(
|
||||
manager.sendCommand(cmd)
|
||||
}
|
||||
}
|
||||
currentInput = TextFieldValue("")
|
||||
currentInput = ""
|
||||
true
|
||||
}
|
||||
Key.Backspace -> {
|
||||
val t = currentInputText
|
||||
if (t.isNotEmpty()) {
|
||||
currentInput = TextFieldValue(t.substring(0, t.length - 1))
|
||||
currentInput = t.substring(0, t.length - 1)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -469,54 +474,110 @@ fun SshTerminalScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val focusModifier = remember { FocusRequester() }
|
||||
|
||||
// 连接后自动获取焦点
|
||||
// 连接后自动让 EditText 获取焦点(弹出软键盘)
|
||||
LaunchedEffect(state.connected) {
|
||||
if (state.connected) {
|
||||
focusModifier.requestFocus()
|
||||
// 延迟一点确保 EditText 已创建
|
||||
kotlinx.coroutines.delay(200)
|
||||
editTextRef.value?.let { et ->
|
||||
et.requestFocus()
|
||||
val imm = context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager
|
||||
imm?.showSoftInput(et, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
// 点击终端区域让 EditText 重新获取焦点
|
||||
val requestEditTextFocus: () -> Unit = {
|
||||
editTextRef.value?.let { et ->
|
||||
et.requestFocus()
|
||||
val imm = context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager
|
||||
imm?.showSoftInput(et, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.background(bg)
|
||||
.onKeyEvent { handleKeyEvent(it) }
|
||||
.focusRequester(focusModifier)
|
||||
.clickable { focusModifier.requestFocus() }
|
||||
.clickable { requestEditTextFocus() }
|
||||
) {
|
||||
// 透明输入框 — 极小的 1x30 dp,仅用来弹出软键盘
|
||||
BasicTextField(
|
||||
value = currentInput,
|
||||
onValueChange = { newVal ->
|
||||
val t = newVal.text
|
||||
if (t.endsWith('\n')) {
|
||||
val cmd = t.dropLast(1).trim()
|
||||
if (cmd.isNotEmpty()) {
|
||||
coroutineScope.launch {
|
||||
manager.sendCommand(cmd)
|
||||
}
|
||||
}
|
||||
currentInput = TextFieldValue("")
|
||||
} else {
|
||||
currentInput = newVal
|
||||
}
|
||||
},
|
||||
// EditText 输入桥——在 Column 顶部,0高度不占空间
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(1.dp)
|
||||
.height(30.dp)
|
||||
.focusRequester(focusModifier),
|
||||
singleLine = true,
|
||||
textStyle = TextStyle(color = Color.Transparent, fontSize = 1.sp)
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.height(40.dp)
|
||||
.background(Color(0xFF0D1117))
|
||||
.padding(horizontal = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// $ 提示符已移除——终端输出本身就是带提示符的
|
||||
AndroidView(
|
||||
factory = { ctx ->
|
||||
EditText(ctx).apply {
|
||||
setBackgroundColor(android.graphics.Color.TRANSPARENT)
|
||||
setTextColor(android.graphics.Color.parseColor("#E6EDF3"))
|
||||
textSize = 14f
|
||||
hint = if (state.connected) "type command..." else ""
|
||||
setHintTextColor(android.graphics.Color.parseColor("#6E7681"))
|
||||
imeOptions = EditorInfo.IME_ACTION_SEND
|
||||
setSingleLine()
|
||||
setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
val cmd = text.toString().trim()
|
||||
if (cmd.isNotEmpty()) {
|
||||
coroutineScope.launch {
|
||||
manager.sendCommand(cmd)
|
||||
}
|
||||
}
|
||||
setText("")
|
||||
currentInput = ""
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
addTextChangedListener(object : android.text.TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||
override fun afterTextChanged(s: android.text.Editable?) {}
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
currentInput = s?.toString() ?: ""
|
||||
}
|
||||
})
|
||||
setOnKeyListener { _, keyCode, event ->
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && keyCode == AndroidKeyEvent.KEYCODE_ENTER) {
|
||||
val cmd = text.toString().trim()
|
||||
if (cmd.isNotEmpty()) {
|
||||
coroutineScope.launch {
|
||||
manager.sendCommand(cmd)
|
||||
}
|
||||
}
|
||||
setText("")
|
||||
currentInput = ""
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
tag = "terminal_input"
|
||||
editTextRef.value = this
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxHeight()
|
||||
)
|
||||
}
|
||||
|
||||
// ── 终端内容(顶栏 + 输出 + 输入行)──
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.systemBarsPadding()
|
||||
.imePadding()
|
||||
.navigationBarsPadding()
|
||||
.clickable { requestEditTextFocus() }
|
||||
) {
|
||||
// ── 终端顶栏 ──
|
||||
Surface(
|
||||
|
||||
|
Before Width: | Height: | Size: 366 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 366 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 366 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 277 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 158 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 277 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 277 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 502 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 254 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 502 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 502 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 864 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 435 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 864 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 864 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 593 B After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 19 KiB |