UI/细节调整

This commit is contained in:
zhongluofeng committed 2026-09-22 19:10:16 +08:00
1 parent b018abd922
commit bccd21fde5
135 files changed
+11393 -5104

No files matched your search

+73 -10
View File
@@ -23,7 +23,11 @@ use specta::Type;
pub struct ShellProfile {
/// 唯一标识(同时是新建会话时的 shellKey)
pub id: String,
/// 展示名称,如 "PowerShell 7"
/// 展示名称,如 "PowerShell 7" / "Windows PowerShell"。
///
/// **设置页里的描述名,不是标签上显示的名字** —— 后者取
/// [`super::shell::session_label`](按可执行文件名归一的短名)。
/// 两者刻意分开:描述名可编辑、可很长,而标签要能一行放下多个会话。
pub name: String,
/// 可执行文件绝对路径
pub path: String,
@@ -147,6 +151,20 @@ pub struct SshHost {
pub jump_ids: Vec<String>,
/// 终端的字符编码("utf-8" 默认 | "gbk" 等)。老服务器常见 GBK,中文环境刚需。
pub encoding: String,
/// 是否在远端注入 shell 集成 hook(命令历史 + cwd 跟踪)。
///
/// # 为什么默认必须是 true
///
/// 本结构是容器级 `#[serde(default)]`:老配置里缺这个字段时,serde 不是填
/// 「零值」而是取 [`SshHost::default()`] 的值。因此**默认值决定老主机是否自动
/// 开启注入** —— 填 `false` 会让所有既有主机静默不注入(表现为历史永远为空,
/// 而开关在界面上看着是关的,用户根本不会去动它)。填 `true` 则无需改
/// `heal()`、无需升 `version`。
///
/// 关掉它的场景:远端 shell 集成会与 `startup_command` 里 `exec` 换 shell 的
/// 配置冲突,或服务器对会话环境有洁癖要求(注入会改本次会话的 `PROMPT_COMMAND`/
/// `precmd`,但不落盘、不影响其它会话)。
pub inject_shell_integration: bool,
}
impl Default for SshHost {
@@ -170,6 +188,8 @@ impl Default for SshHost {
use_proxy: false,
jump_ids: Vec::new(),
encoding: "utf-8".to_string(),
// 必须 true,理由见字段文档(容器级 serde(default) 会用这里的值兜老配置)
inject_shell_integration: true,
}
}
}
@@ -206,7 +226,8 @@ pub struct AppearanceSettings {
impl Default for AppearanceSettings {
fn default() -> Self {
Self {
theme: "thing-dark".to_string(),
// 「跟随主应用」:配合默认开启的 follow_app_theme,开箱即随应用深浅切换
theme: "system".to_string(),
follow_app_theme: true,
font_family: "Cascadia Mono, Consolas, Microsoft YaHei Mono, monospace".to_string(),
font_size: 14,
@@ -296,10 +317,6 @@ pub struct LayoutSettings {
pub confirm_close_running: bool,
/// 新建标签页时是否继承当前会话的工作目录
pub inherit_cwd: bool,
/// 侧栏默认是否展开
pub sidebar_open: bool,
/// 侧栏宽度(像素)
pub sidebar_width: u32,
/// 是否显示底部状态栏
pub show_status_bar: bool,
/// 分屏上限(1 = 不分屏,2 = 2×1,4 = 2×2)。
@@ -312,8 +329,6 @@ impl Default for LayoutSettings {
Self {
confirm_close_running: true,
inherit_cwd: true,
sidebar_open: true,
sidebar_width: 220,
show_status_bar: true,
max_panes: 4,
}
@@ -510,11 +525,25 @@ pub struct SecuritySettings {
///
/// **不提供 "auto-accept" 选项**:TOFU 静默接受是 MITM 的入口,
/// 属于代码层不该给用户的开关。
///
/// 读取方(`ssh::SshHandler::check_server_key`)**显式读取本字段而不是写死**:
/// 唯一支持的取值是 `"ask"`,其它取值(配置文件被手工改过)一律按 `"ask"`
/// 处理 —— 安全开关的失败方向必须朝更严的一侧,绝不能因为出现了一个
/// 没见过的字符串就放宽。
pub host_key_policy: String,
/// 指纹变更时是否阻断(**默认 true**)。关掉会让中间人攻击无声通过,
/// 因此前端需以红色风险提示呈现该开关。
///
/// 关闭时的行为不是「照旧弹窗」而是「自动接受并记入变更历史」:
/// 开关的语义是「不再拦截」,若关掉后仍弹阻断弹窗,用户会以为没生效。
pub block_on_fingerprint_change: bool,
/// 是否记录连接审计日志(P2,默认关;开启后输入输出落盘,含脱敏)
/// 是否把**安全事件**写入日志(默认开)。
///
/// 记录对象是主机密钥相关的事件:指纹已信任 / 首次见到被接受 / 指纹变更
/// 被接受或拒绝 / 自动接受(阻断关闭时)。与「会话日志」(输出字节流落盘,
/// 由工具栏的 `terminal_toggle_logging` 按会话显式开启,见 `audit` 模块的
/// 取舍说明)**是两件事**:这里只写事件行,不含屏幕内容,因此没有隐私代价,
/// 默认开启才能保证「发生过什么」事后可查。
pub audit_log: bool,
}
@@ -523,7 +552,7 @@ impl Default for SecuritySettings {
Self {
host_key_policy: "ask".to_string(),
block_on_fingerprint_change: true,
audit_log: false,
audit_log: true,
}
}
}
@@ -633,6 +662,9 @@ impl Default for TemplateEntry {
/// - 新建/关闭标签用 `Ctrl+Shift+T/W`,与浏览器习惯一致。
/// - 跳转标签用 `Alt+1..9`:`Ctrl+数字` 已被翻译模块的 `Ctrl+2`(翻译面板)占用,
/// 而 `Alt+数字` 在终端里通常不产生控制字符,冲突面最小。
/// - `newDetachedWindow`(`Ctrl+3`)是这张表里唯一**全局**生效的一条:它由前端
/// `TerminalQuickLaunch` 注册成系统级热键(任意应用前台可触发),放在这里只为
/// 跟着终端设置一起存与改。`Ctrl+2` 已被翻译面板占用,`Ctrl+3` 是空闲的相邻键位。
pub fn default_shortcuts() -> Vec<ShortcutBinding> {
let pairs: &[(&str, &str)] = &[
("copy", "Ctrl+Shift+C"),
@@ -656,6 +688,11 @@ pub fn default_shortcuts() -> Vec<ShortcutBinding> {
("history", "Ctrl+Shift+H"),
("renameTab", "F2"),
("sessionSwitcher", "Ctrl+Shift+O"),
// 把当前会话放到独立窗口。**必须列在这里**:`heal()` 只保留默认表里出现过的
// action(未知 action 会被剔除),前端设置表里有而这里没有 = 用户改完下次启动就被清掉。
("detachWindow", "Ctrl+Shift+N"),
// 全局生效的一条(见上方说明):新建独立窗口 + 选择会话
("newDetachedWindow", "Ctrl+3"),
];
pairs
.iter()
@@ -685,6 +722,24 @@ impl TerminalSettings {
pub fn heal(&mut self) -> bool {
let mut changed = false;
// 配色主题:只认前端 `terminalThemes.ts` 里存在的 key。
// 早期默认值是 `thing-dark`(一套从未实现的主题),解析时会静默回落到
// vscode-dark,用户看到的是「选了主题不生效」。未知 key 一律收敛到
// 「system」(跟随主应用)—— 它至少是用户能预期的行为。
const THEMES: &[&str] = &[
"vscode-dark",
"vscode-light",
"solarized-dark",
"solarized-light",
"dracula",
"one-dark",
"system",
];
if !THEMES.contains(&self.appearance.theme.as_str()) {
self.appearance.theme = "system".to_string();
changed = true;
}
// 快捷键表:补齐新增动作、剔除已废弃动作。用户改过的键位保留。
let defaults = default_shortcuts();
for d in &defaults {
@@ -747,6 +802,14 @@ impl TerminalSettings {
changed = true;
}
// 安全:主机密钥策略只有一个合法取值(见 SecuritySettings 的字段说明)。
// 手工改过的配置在这里收敛回 "ask",与 `check_server_key` 里
// 「未知取值按 ask 处理」构成两道保险:这道修数据,那道防空。
if self.security.host_key_policy != "ask" {
self.security.host_key_policy = "ask".to_string();
changed = true;
}
// last_shell_id 指向已删除的 Shell → 清空,由前端选第一个可用
if !self.last_shell_id.is_empty() && self.shell(&self.last_shell_id).is_none() {
self.last_shell_id.clear();