chore: 保存工作副本——客户端授权新契约(双端点/验签/令牌/周检)与桌面会话可靠性改进

This commit is contained in:
Logan.Li committed 2026-09-14 22:10:22 +08:00
1 parent f71eef0eba
commit ae6093c9b3
163 files changed
+4911 -2494

No files matched your search

+13 -11
View File
@@ -96,7 +96,12 @@ impl SshService {
app: &AppHandle,
connection_id: &str,
retain_forwards: bool,
reason: Option<String>,
) -> Result<(), String> {
let reason = reason
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty())
.unwrap_or_else(|| "connection closed".to_string());
// Dedicated tunnel sessions keep listening across terminal flaps when
// retain_forwards is true. Explicit teardown (tab close / panel disconnect)
// must still close real Listeners.
@@ -123,7 +128,7 @@ impl SshService {
for shell_id in shell_ids {
if let Some(mut shell) = self.shells.lock().map_err(lock_error)?.remove(&shell_id) {
let _ = shell.channel.close();
let _ = shell.session.disconnect(None, "closed by user", None);
let _ = shell.session.disconnect(None, &reason, None);
}
}
let sftp_ids = {
@@ -148,13 +153,13 @@ impl SshService {
.map_err(lock_error)?
.remove(connection_id)
{
let _ = connection.session.disconnect(None, "closed by user", None);
let _ = connection.session.disconnect(None, &reason, None);
}
let _ = app.emit(
"ssh:connection-closed",
ConnectionClosedEvent {
connection_id: connection_id.to_string(),
reason: "closed by user".to_string(),
reason,
},
);
Ok(())
@@ -657,15 +662,12 @@ fn classify_shell_close(output_tail: &[u8], read_error: Option<&str>) -> (String
|| output.contains("auto-logout")
|| output.contains("auto logout");
if idle_timeout {
return ("远端 Shell 因空闲策略(TMOUT)自动退出".to_string(), true);
return ("shell.idleTimeout".to_string(), true);
}
if let Some(error) = read_error {
return (format!("远端 Shell 读取失败: {error}"), false);
return (format!("shell.readFailed: {error}"), false);
}
(
"远端 Shell 已退出(可能执行了 exit、Ctrl+D,或被服务器策略关闭)".to_string(),
false,
)
("shell.exited".to_string(), false)
}
fn write_nonblocking(channel: &mut ssh2::Channel, data: &[u8]) -> io::Result<()> {
@@ -814,7 +816,7 @@ mod tests {
classify_shell_close(b"timed out waiting for input: auto-logout\r\n", None);
assert!(idle_timeout);
assert!(reason.contains("TMOUT"));
assert_eq!(reason, "shell.idleTimeout");
}
#[test]
@@ -831,7 +833,7 @@ mod tests {
let (reason, idle_timeout) = classify_shell_close(b"logout\r\n", None);
assert!(!idle_timeout);
assert!(reason.contains("Shell 已退出"));
assert_eq!(reason, "shell.exited");
}
#[test]