终端模块初版

This commit is contained in:
zhongluofeng
2026-09-18 18:28:13 +08:00
parent f6c1cc250e
commit b018abd922
63 changed files with 26695 additions and 185 deletions
+169 -1
View File
@@ -16,6 +16,7 @@ mod secrets;
mod setup;
mod shortcut;
mod snap_fix;
mod terminal;
mod translate;
mod tray_menu;
mod updater;
@@ -103,6 +104,46 @@ use quickpanel::{
quickpanel_show_window, quickpanel_unregister_shortcut, quickpanel_focus_main_window,
};
use tray_menu::{tray_menu_action, tray_menu_hide, tray_menu_ready};
use terminal::commands::{
terminal_attach_session, terminal_clear_known_hosts, terminal_clear_session,
terminal_close_session, terminal_confirm_host_key, terminal_default_cwd, terminal_delete_host,
terminal_delete_key, terminal_delete_shell, terminal_detach_session,
terminal_export_known_hosts, terminal_forget_host, terminal_generate_key,
terminal_get_settings, terminal_import_key, terminal_import_known_hosts,
terminal_import_ssh_config, terminal_key_public, terminal_list_hosts,
terminal_list_known_hosts, terminal_list_keys, terminal_list_sessions,
terminal_list_shells, terminal_new_host_id, terminal_open_local,
terminal_open_ssh, terminal_open_local_path, terminal_reveal_local_path,
terminal_refresh_shells, terminal_rename_key, terminal_rename_session,
terminal_resize, terminal_save_appearance, terminal_save_host, terminal_save_layout,
terminal_save_security, terminal_save_selection, terminal_save_settings,
terminal_save_shell, terminal_save_shortcuts, terminal_send_key, terminal_session_alive,
terminal_session_cwd, terminal_session_cwd_value, terminal_set_host_password,
terminal_set_encoding,
terminal_set_key_passphrase,
terminal_set_last_shell, terminal_test_shell, terminal_write,
// SFTP 文件管理(P1
terminal_sftp_close, terminal_sftp_delete, terminal_sftp_download, terminal_sftp_is_open,
terminal_sftp_list, terminal_sftp_mkdir, terminal_sftp_open, terminal_sftp_parent,
terminal_sftp_read_link, terminal_sftp_rename, terminal_sftp_upload,
// 命令片段(P1
terminal_delete_snippet, terminal_list_snippets, terminal_render_snippet,
terminal_restore_default_snippets, terminal_run_snippet, terminal_save_snippet,
// 命令历史(P1
terminal_history_clear, terminal_history_delete, terminal_history_query,
terminal_history_run, terminal_history_sources, terminal_history_toggle_favorite,
// 端口转发(P2
terminal_add_forward, terminal_list_forwards, terminal_remove_forward,
// 会话日志(P2
terminal_log_path, terminal_toggle_logging,
// 主机配置同步(P2
terminal_export_hosts, terminal_import_hosts,
// 会话模板(P2
terminal_delete_template, terminal_save_template,
// AI 命令助手(P2
terminal_ai_engines, terminal_ai_suggest,
};
use terminal::TerminalManager;
use translate::{
translate_abort, translate_apply_shortcuts, translate_copy_text, translate_engine_delete,
translate_engine_models, translate_engine_save, translate_engine_test_config,
@@ -208,6 +249,34 @@ fn export_bindings() {
translate_history_list, translate_history_delete, translate_history_clear,
translate_history_set_favorited,
translate_stream_start, translate_abort, translate_paste_back,
// terminal4139 业务 + key_public / new_host_id 两个辅助)
terminal_get_settings, terminal_save_settings, terminal_save_appearance,
terminal_save_layout, terminal_save_selection, terminal_save_security,
terminal_save_shortcuts,
terminal_list_shells, terminal_refresh_shells, terminal_save_shell,
terminal_delete_shell, terminal_set_last_shell, terminal_test_shell,
terminal_default_cwd,
terminal_open_local, terminal_open_ssh, terminal_list_sessions,
terminal_close_session, terminal_write, terminal_resize, terminal_rename_session,
terminal_detach_session, terminal_attach_session, terminal_session_cwd,
terminal_send_key, terminal_clear_session, terminal_session_alive,
terminal_set_encoding,
terminal_list_hosts, terminal_save_host, terminal_delete_host,
terminal_set_host_password, terminal_import_ssh_config,
terminal_list_keys, terminal_generate_key, terminal_import_key,
terminal_delete_key, terminal_rename_key, terminal_set_key_passphrase,
terminal_key_public, terminal_new_host_id,
terminal_list_known_hosts, terminal_forget_host, terminal_clear_known_hosts,
terminal_export_known_hosts, terminal_import_known_hosts,
terminal_confirm_host_key,
// 命令历史(6 个)
//
// 注意:这 6 个命令**必须与 `run()` 里那份 `collect_commands!` 同时登记**。
// 只登记其中一处不会报错:漏了这里 = 运行时能调但 `bindings.ts` 里没有类型;
// 漏了那边 = 有类型但调用失败。两种都是「编译/启动全绿但功能静默不可用」。
terminal_history_query, terminal_history_sources,
terminal_history_toggle_favorite, terminal_history_delete,
terminal_history_clear, terminal_history_run,
])
.export(Typescript::default(), "../src/lib/bindings.ts")
.expect("failed to export bindings");
@@ -473,7 +542,100 @@ pub fn run() {
translate_history_set_favorited,
translate_stream_start,
translate_abort,
translate_paste_back
translate_paste_back,
terminal_get_settings,
terminal_save_settings,
terminal_save_appearance,
terminal_save_layout,
terminal_save_selection,
terminal_save_security,
terminal_save_shortcuts,
terminal_list_shells,
terminal_refresh_shells,
terminal_save_shell,
terminal_delete_shell,
terminal_set_last_shell,
terminal_test_shell,
terminal_default_cwd,
terminal_open_local,
terminal_open_ssh,
terminal_list_sessions,
terminal_close_session,
terminal_write,
terminal_resize,
terminal_rename_session,
terminal_detach_session,
terminal_attach_session,
terminal_session_cwd,
terminal_set_encoding,
terminal_send_key,
terminal_clear_session,
terminal_session_alive,
terminal_list_hosts,
terminal_save_host,
terminal_delete_host,
terminal_set_host_password,
terminal_import_ssh_config,
terminal_list_keys,
terminal_generate_key,
terminal_import_key,
terminal_delete_key,
terminal_rename_key,
terminal_set_key_passphrase,
terminal_key_public,
terminal_new_host_id,
terminal_list_known_hosts,
terminal_forget_host,
terminal_clear_known_hosts,
terminal_export_known_hosts,
terminal_import_known_hosts,
terminal_confirm_host_key,
// SFTP 文件管理(P1
terminal_sftp_is_open,
terminal_sftp_open,
terminal_sftp_close,
terminal_sftp_list,
terminal_sftp_parent,
terminal_sftp_read_link,
terminal_sftp_mkdir,
terminal_sftp_delete,
terminal_sftp_rename,
terminal_sftp_upload,
terminal_sftp_download,
terminal_session_cwd_value,
// 本地文件操作(SFTP 面板的「打开 / 在资源管理器中显示」)
terminal_open_local_path,
terminal_reveal_local_path,
// 命令片段(P1
terminal_list_snippets,
terminal_save_snippet,
terminal_delete_snippet,
terminal_render_snippet,
terminal_run_snippet,
terminal_restore_default_snippets,
// 命令历史(P1
terminal_history_query,
terminal_history_sources,
terminal_history_toggle_favorite,
terminal_history_delete,
terminal_history_clear,
terminal_history_run,
// 端口转发(P2
terminal_add_forward,
terminal_list_forwards,
terminal_remove_forward,
// 会话日志(P2
terminal_log_path,
terminal_toggle_logging,
// 主机配置同步(P2
terminal_export_hosts,
terminal_import_hosts,
// 会话模板(P2
terminal_delete_template,
terminal_save_template,
// AI 命令助手(P2
terminal_ai_engines,
terminal_ai_suggest
])
.setup(setup::init)
.on_window_event(|window, event| {
@@ -515,6 +677,12 @@ pub fn run() {
// 停止音乐桥接进程(kill 快速返回,wait 在后台线程完成)
music.cleanup_on_exit();
}
if let Some(term) = app.try_state::<TerminalManager>() {
// 关闭全部终端会话。**不等待**ConPTY 的 ClosePseudoConsole 会
// 阻塞到所有句柄关闭,退出路径上等待会卡死(会话侧已把关闭动作
// 放进后台线程,进程终止时 OS 回收剩余资源)。
term.cleanup_on_exit();
}
if let Some(clip) = app.try_state::<ClipboardManager>() {
clip.stop();
}