mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a433b0ff7 | |||
| 1555dbc55e | |||
| 3551e3c496 | |||
| 08014f99e6 | |||
| 3006c6a23d | |||
| 9b14721d4c | |||
| 65c96db0d1 | |||
| e5867ca2d1 | |||
| 854f19d0e1 | |||
| 905f7ccbfe | |||
| 3e4c87278f | |||
| f4e960253e | |||
| 324a1da8e6 | |||
| 49f66bcc9a | |||
| 4084b53834 | |||
| 2c2c72271a | |||
| 6a1ba46f2a |
@@ -1,14 +0,0 @@
|
|||||||
#[tauri::command]
|
|
||||||
pub fn enter_lightweight_mode(app: tauri::AppHandle) -> Result<(), String> {
|
|
||||||
crate::lightweight::enter_lightweight_mode(&app)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn exit_lightweight_mode(app: tauri::AppHandle) -> Result<(), String> {
|
|
||||||
crate::lightweight::exit_lightweight_mode(&app)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn is_lightweight_mode() -> bool {
|
|
||||||
crate::lightweight::is_lightweight_mode()
|
|
||||||
}
|
|
||||||
@@ -888,7 +888,6 @@ exec bash --norc --noprofile
|
|||||||
"kitty" => launch_macos_open_app("kitty", &script_file, false),
|
"kitty" => launch_macos_open_app("kitty", &script_file, false),
|
||||||
"ghostty" => launch_macos_open_app("Ghostty", &script_file, true),
|
"ghostty" => launch_macos_open_app("Ghostty", &script_file, true),
|
||||||
"wezterm" => launch_macos_open_app("WezTerm", &script_file, true),
|
"wezterm" => launch_macos_open_app("WezTerm", &script_file, true),
|
||||||
"tabby" => launch_macos_tabby(&script_file),
|
|
||||||
_ => launch_macos_terminal_app(&script_file), // "terminal" or default
|
_ => launch_macos_terminal_app(&script_file), // "terminal" or default
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1006,39 +1005,6 @@ fn launch_macos_open_app(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// macOS: Tabby
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
fn launch_macos_tabby(script_file: &std::path::Path) -> Result<(), String> {
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
let output = Command::new("open")
|
|
||||||
.args(build_macos_tabby_args(script_file))
|
|
||||||
.output()
|
|
||||||
.map_err(|e| format!("启动 Tabby 失败: {e}"))?;
|
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
||||||
return Err(format!(
|
|
||||||
"Tabby 启动失败 (exit code: {:?}): {}",
|
|
||||||
output.status.code(),
|
|
||||||
stderr
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_macos_tabby_args(script_file: &std::path::Path) -> Vec<String> {
|
|
||||||
vec![
|
|
||||||
"-na".to_string(),
|
|
||||||
"Tabby".to_string(),
|
|
||||||
"--args".to_string(),
|
|
||||||
"run".to_string(),
|
|
||||||
"bash".to_string(),
|
|
||||||
script_file.to_string_lossy().into_owned(),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Linux: 根据用户首选终端启动
|
/// Linux: 根据用户首选终端启动
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn launch_linux_terminal(config_file: &std::path::Path) -> Result<(), String> {
|
fn launch_linux_terminal(config_file: &std::path::Path) -> Result<(), String> {
|
||||||
@@ -1057,8 +1023,6 @@ fn launch_linux_terminal(config_file: &std::path::Path) -> Result<(), String> {
|
|||||||
("alacritty", vec!["-e"]),
|
("alacritty", vec!["-e"]),
|
||||||
("kitty", vec!["-e"]),
|
("kitty", vec!["-e"]),
|
||||||
("ghostty", vec!["-e"]),
|
("ghostty", vec!["-e"]),
|
||||||
("tabby", vec!["run"]),
|
|
||||||
("tabby-terminal", vec!["run"]),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Create temp script file
|
// Create temp script file
|
||||||
@@ -1184,7 +1148,6 @@ del \"%~f0\" >nul 2>&1
|
|||||||
"PowerShell",
|
"PowerShell",
|
||||||
),
|
),
|
||||||
"wt" => run_windows_start_command(&["wt", "cmd", "/K", &bat_path], "Windows Terminal"),
|
"wt" => run_windows_start_command(&["wt", "cmd", "/K", &bat_path], "Windows Terminal"),
|
||||||
"tabby" => run_windows_tabby_command(&bat_path),
|
|
||||||
_ => run_windows_start_command(&["cmd", "/K", &bat_path], "cmd"), // "cmd" or default
|
_ => run_windows_start_command(&["cmd", "/K", &bat_path], "cmd"), // "cmd" or default
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1201,56 +1164,6 @@ del \"%~f0\" >nul 2>&1
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn run_windows_tabby_command(bat_path: &str) -> Result<(), String> {
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
let mut last_error = String::from("未找到可用的 Tabby 可执行文件");
|
|
||||||
|
|
||||||
for candidate in windows_tabby_executable_candidates() {
|
|
||||||
let result = Command::new(&candidate)
|
|
||||||
.args(["run", "cmd", "/K", bat_path])
|
|
||||||
.creation_flags(CREATE_NO_WINDOW)
|
|
||||||
.spawn();
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(_) => return Ok(()),
|
|
||||||
Err(e) => {
|
|
||||||
last_error = format!("执行 {} 失败: {}", candidate.display(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(last_error)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn windows_tabby_executable_candidates() -> Vec<std::path::PathBuf> {
|
|
||||||
let mut candidates = Vec::new();
|
|
||||||
|
|
||||||
for candidate in ["tabby", "tabby.exe", "Tabby", "Tabby.exe"] {
|
|
||||||
push_unique_path(&mut candidates, std::path::PathBuf::from(candidate));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(local_app_data) = std::env::var_os("LOCALAPPDATA") {
|
|
||||||
let tabby_dir = std::path::PathBuf::from(local_app_data)
|
|
||||||
.join("Programs")
|
|
||||||
.join("Tabby");
|
|
||||||
push_unique_path(&mut candidates, tabby_dir.join("Tabby.exe"));
|
|
||||||
push_unique_path(&mut candidates, tabby_dir.join("tabby.exe"));
|
|
||||||
}
|
|
||||||
|
|
||||||
for env_key in ["ProgramFiles", "ProgramFiles(x86)"] {
|
|
||||||
if let Some(base_dir) = std::env::var_os(env_key) {
|
|
||||||
let tabby_dir = std::path::PathBuf::from(base_dir).join("Tabby");
|
|
||||||
push_unique_path(&mut candidates, tabby_dir.join("Tabby.exe"));
|
|
||||||
push_unique_path(&mut candidates, tabby_dir.join("tabby.exe"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
candidates
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Windows: Run a start command with common error handling
|
/// Windows: Run a start command with common error handling
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
fn run_windows_start_command(args: &[&str], terminal_name: &str) -> Result<(), String> {
|
fn run_windows_start_command(args: &[&str], terminal_name: &str) -> Result<(), String> {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ pub mod skill;
|
|||||||
mod stream_check;
|
mod stream_check;
|
||||||
mod sync_support;
|
mod sync_support;
|
||||||
|
|
||||||
mod lightweight;
|
|
||||||
mod usage;
|
mod usage;
|
||||||
mod webdav_sync;
|
mod webdav_sync;
|
||||||
mod workspace;
|
mod workspace;
|
||||||
@@ -48,7 +47,6 @@ pub use settings::*;
|
|||||||
pub use skill::*;
|
pub use skill::*;
|
||||||
pub use stream_check::*;
|
pub use stream_check::*;
|
||||||
|
|
||||||
pub use lightweight::*;
|
|
||||||
pub use usage::*;
|
pub use usage::*;
|
||||||
pub use webdav_sync::*;
|
pub use webdav_sync::*;
|
||||||
pub use workspace::*;
|
pub use workspace::*;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ mod error;
|
|||||||
mod gemini_config;
|
mod gemini_config;
|
||||||
mod gemini_mcp;
|
mod gemini_mcp;
|
||||||
mod init_status;
|
mod init_status;
|
||||||
mod lightweight;
|
|
||||||
mod mcp;
|
mod mcp;
|
||||||
mod openclaw_config;
|
mod openclaw_config;
|
||||||
mod opencode_config;
|
mod opencode_config;
|
||||||
@@ -205,12 +204,6 @@ pub fn run() {
|
|||||||
log::debug!(" arg[{i}]: {}", redact_url_for_log(arg));
|
log::debug!(" arg[{i}]: {}", redact_url_for_log(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
if crate::lightweight::is_lightweight_mode() {
|
|
||||||
if let Err(e) = crate::lightweight::exit_lightweight_mode(app) {
|
|
||||||
log::error!("退出轻量模式重建窗口失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for deep link URL in args (mainly for Windows/Linux command line)
|
// Check for deep link URL in args (mainly for Windows/Linux command line)
|
||||||
let mut found_deeplink = false;
|
let mut found_deeplink = false;
|
||||||
for arg in &args {
|
for arg in &args {
|
||||||
@@ -622,12 +615,6 @@ pub fn run() {
|
|||||||
let urls = event.urls();
|
let urls = event.urls();
|
||||||
log::info!("Received {} URL(s)", urls.len());
|
log::info!("Received {} URL(s)", urls.len());
|
||||||
|
|
||||||
if crate::lightweight::is_lightweight_mode() {
|
|
||||||
if let Err(e) = crate::lightweight::exit_lightweight_mode(&app_handle) {
|
|
||||||
log::error!("退出轻量模式重建窗口失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i, url) in urls.iter().enumerate() {
|
for (i, url) in urls.iter().enumerate() {
|
||||||
let url_str = url.as_str();
|
let url_str = url.as_str();
|
||||||
log::debug!(" URL[{i}]: {}", redact_url_for_log(url_str));
|
log::debug!(" URL[{i}]: {}", redact_url_for_log(url_str));
|
||||||
@@ -1098,10 +1085,6 @@ pub fn run() {
|
|||||||
commands::delete_daily_memory_file,
|
commands::delete_daily_memory_file,
|
||||||
commands::search_daily_memory_files,
|
commands::search_daily_memory_files,
|
||||||
commands::open_workspace_directory,
|
commands::open_workspace_directory,
|
||||||
// lightweight mode (for testing or low-resource environments)
|
|
||||||
commands::enter_lightweight_mode,
|
|
||||||
commands::exit_lightweight_mode,
|
|
||||||
commands::is_lightweight_mode,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let app = builder
|
let app = builder
|
||||||
@@ -1152,10 +1135,6 @@ pub fn run() {
|
|||||||
let _ = window.show();
|
let _ = window.show();
|
||||||
let _ = window.set_focus();
|
let _ = window.set_focus();
|
||||||
tray::apply_tray_policy(app_handle, true);
|
tray::apply_tray_policy(app_handle, true);
|
||||||
} else if crate::lightweight::is_lightweight_mode() {
|
|
||||||
if let Err(e) = crate::lightweight::exit_lightweight_mode(app_handle) {
|
|
||||||
log::error!("退出轻量模式重建窗口失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 处理通过自定义 URL 协议触发的打开事件(例如 ccswitch://...)
|
// 处理通过自定义 URL 协议触发的打开事件(例如 ccswitch://...)
|
||||||
@@ -1165,13 +1144,6 @@ pub fn run() {
|
|||||||
log::info!("RunEvent::Opened with URL: {url_str}");
|
log::info!("RunEvent::Opened with URL: {url_str}");
|
||||||
|
|
||||||
if url_str.starts_with("ccswitch://") {
|
if url_str.starts_with("ccswitch://") {
|
||||||
if crate::lightweight::is_lightweight_mode() {
|
|
||||||
if let Err(e) = crate::lightweight::exit_lightweight_mode(app_handle)
|
|
||||||
{
|
|
||||||
log::error!("退出轻量模式重建窗口失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析并广播深链接事件,复用与 single_instance 相同的逻辑
|
// 解析并广播深链接事件,复用与 single_instance 相同的逻辑
|
||||||
match crate::deeplink::parse_deeplink_url(&url_str) {
|
match crate::deeplink::parse_deeplink_url(&url_str) {
|
||||||
Ok(request) => {
|
Ok(request) => {
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
|
|
||||||
use tauri::Manager;
|
|
||||||
|
|
||||||
static LIGHTWEIGHT_MODE: AtomicBool = AtomicBool::new(false);
|
|
||||||
|
|
||||||
pub fn enter_lightweight_mode(app: &tauri::AppHandle) -> Result<(), String> {
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
|
||||||
let _ = window.set_skip_taskbar(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
crate::tray::apply_tray_policy(app, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
|
||||||
window
|
|
||||||
.destroy()
|
|
||||||
.map_err(|e| format!("销毁主窗口失败: {e}"))?;
|
|
||||||
}
|
|
||||||
// else: already in lightweight mode or window not found, just set the flag
|
|
||||||
|
|
||||||
LIGHTWEIGHT_MODE.store(true, Ordering::Release);
|
|
||||||
crate::tray::refresh_tray_menu(app);
|
|
||||||
log::info!("进入轻量模式");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn exit_lightweight_mode(app: &tauri::AppHandle) -> Result<(), String> {
|
|
||||||
use tauri::WebviewWindowBuilder;
|
|
||||||
|
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
|
||||||
let _ = window.unminimize();
|
|
||||||
let _ = window.show();
|
|
||||||
let _ = window.set_focus();
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
let _ = window.set_skip_taskbar(false);
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
crate::tray::apply_tray_policy(app, true);
|
|
||||||
}
|
|
||||||
LIGHTWEIGHT_MODE.store(false, Ordering::Release);
|
|
||||||
crate::tray::refresh_tray_menu(app);
|
|
||||||
log::info!("退出轻量模式");
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let window_config = app
|
|
||||||
.config()
|
|
||||||
.app
|
|
||||||
.windows
|
|
||||||
.iter()
|
|
||||||
.find(|w| w.label == "main")
|
|
||||||
.ok_or("主窗口配置未找到")?;
|
|
||||||
|
|
||||||
WebviewWindowBuilder::from_config(app, window_config)
|
|
||||||
.map_err(|e| format!("加载主窗口配置失败: {e}"))?
|
|
||||||
.visible(true)
|
|
||||||
.build()
|
|
||||||
.map_err(|e| format!("创建主窗口失败: {e}"))?;
|
|
||||||
|
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
|
||||||
let _ = window.set_focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
|
||||||
let _ = window.set_skip_taskbar(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
crate::tray::apply_tray_policy(app, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
LIGHTWEIGHT_MODE.store(false, Ordering::Release);
|
|
||||||
crate::tray::refresh_tray_menu(app);
|
|
||||||
log::info!("退出轻量模式");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_lightweight_mode() -> bool {
|
|
||||||
LIGHTWEIGHT_MODE.load(Ordering::Acquire)
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,6 @@ pub fn launch_terminal(
|
|||||||
"kitty" => launch_kitty(command, cwd),
|
"kitty" => launch_kitty(command, cwd),
|
||||||
"wezterm" => launch_wezterm(command, cwd),
|
"wezterm" => launch_wezterm(command, cwd),
|
||||||
"alacritty" => launch_alacritty(command, cwd),
|
"alacritty" => launch_alacritty(command, cwd),
|
||||||
"tabby" => launch_tabby(command, cwd),
|
|
||||||
"custom" => launch_custom(command, cwd, custom_config),
|
"custom" => launch_custom(command, cwd, custom_config),
|
||||||
_ => Err(format!("Unsupported terminal target: {target}")),
|
_ => Err(format!("Unsupported terminal target: {target}")),
|
||||||
}
|
}
|
||||||
@@ -212,35 +211,6 @@ fn launch_alacritty(command: &str, cwd: Option<&str>) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn launch_tabby(command: &str, cwd: Option<&str>) -> Result<(), String> {
|
|
||||||
let status = Command::new("open")
|
|
||||||
.args(build_tabby_args(command, cwd))
|
|
||||||
.status()
|
|
||||||
.map_err(|e| format!("Failed to launch Tabby: {e}"))?;
|
|
||||||
|
|
||||||
if status.success() {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err("Failed to launch Tabby.".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_tabby_args(command: &str, cwd: Option<&str>) -> Vec<String> {
|
|
||||||
let full_command = build_shell_command(command, cwd);
|
|
||||||
let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/zsh".to_string());
|
|
||||||
|
|
||||||
vec![
|
|
||||||
"-na".to_string(),
|
|
||||||
"Tabby".to_string(),
|
|
||||||
"--args".to_string(),
|
|
||||||
"run".to_string(),
|
|
||||||
shell,
|
|
||||||
"-l".to_string(),
|
|
||||||
"-c".to_string(),
|
|
||||||
full_command,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn launch_custom(
|
fn launch_custom(
|
||||||
command: &str,
|
command: &str,
|
||||||
cwd: Option<&str>,
|
cwd: Option<&str>,
|
||||||
@@ -335,44 +305,4 @@ mod tests {
|
|||||||
"raw:echo foo\\\\\\\\bar\\npwd\\n"
|
"raw:echo foo\\\\\\\\bar\\npwd\\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn tabby_uses_login_shell_for_resume_commands() {
|
|
||||||
let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/zsh".to_string());
|
|
||||||
let args = build_tabby_args("claude --resume abc-123", Some("/tmp/project dir"));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
args,
|
|
||||||
vec![
|
|
||||||
"-na",
|
|
||||||
"Tabby",
|
|
||||||
"--args",
|
|
||||||
"run",
|
|
||||||
&shell,
|
|
||||||
"-l",
|
|
||||||
"-c",
|
|
||||||
"cd \"/tmp/project dir\" && claude --resume abc-123",
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn tabby_keeps_command_when_no_cwd_is_provided() {
|
|
||||||
let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/zsh".to_string());
|
|
||||||
let args = build_tabby_args("claude --resume abc-123", None);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
args,
|
|
||||||
vec![
|
|
||||||
"-na",
|
|
||||||
"Tabby",
|
|
||||||
"--args",
|
|
||||||
"run",
|
|
||||||
&shell,
|
|
||||||
"-l",
|
|
||||||
"-c",
|
|
||||||
"claude --resume abc-123",
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,9 +264,9 @@ pub struct AppSettings {
|
|||||||
|
|
||||||
// ===== 终端设置 =====
|
// ===== 终端设置 =====
|
||||||
/// 首选终端应用(可选,默认使用系统默认终端)
|
/// 首选终端应用(可选,默认使用系统默认终端)
|
||||||
/// - macOS: "terminal" | "iterm2" | "alacritty" | "kitty" | "ghostty" | "wezterm" | "tabby"
|
/// - macOS: "terminal" | "iterm2" | "warp" | "alacritty" | "kitty" | "ghostty"
|
||||||
/// - Windows: "cmd" | "powershell" | "wt" (Windows Terminal) | "tabby"
|
/// - Windows: "cmd" | "powershell" | "wt" (Windows Terminal)
|
||||||
/// - Linux: "gnome-terminal" | "konsole" | "xfce4-terminal" | "alacritty" | "kitty" | "ghostty" | "tabby"
|
/// - Linux: "gnome-terminal" | "konsole" | "xfce4-terminal" | "alacritty" | "kitty" | "ghostty"
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub preferred_terminal: Option<String>,
|
pub preferred_terminal: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use crate::store::AppState;
|
|||||||
pub struct TrayTexts {
|
pub struct TrayTexts {
|
||||||
pub show_main: &'static str,
|
pub show_main: &'static str,
|
||||||
pub no_provider_hint: &'static str,
|
pub no_provider_hint: &'static str,
|
||||||
pub lightweight_mode: &'static str,
|
|
||||||
pub quit: &'static str,
|
pub quit: &'static str,
|
||||||
pub _auto_label: &'static str,
|
pub _auto_label: &'static str,
|
||||||
}
|
}
|
||||||
@@ -25,7 +24,6 @@ impl TrayTexts {
|
|||||||
"en" => Self {
|
"en" => Self {
|
||||||
show_main: "Open main window",
|
show_main: "Open main window",
|
||||||
no_provider_hint: " (No providers yet, please add them from the main window)",
|
no_provider_hint: " (No providers yet, please add them from the main window)",
|
||||||
lightweight_mode: "Lightweight Mode",
|
|
||||||
quit: "Quit",
|
quit: "Quit",
|
||||||
_auto_label: "Auto (Failover)",
|
_auto_label: "Auto (Failover)",
|
||||||
},
|
},
|
||||||
@@ -33,14 +31,12 @@ impl TrayTexts {
|
|||||||
show_main: "メインウィンドウを開く",
|
show_main: "メインウィンドウを開く",
|
||||||
no_provider_hint:
|
no_provider_hint:
|
||||||
" (プロバイダーがまだありません。メイン画面から追加してください)",
|
" (プロバイダーがまだありません。メイン画面から追加してください)",
|
||||||
lightweight_mode: "軽量モード",
|
|
||||||
quit: "終了",
|
quit: "終了",
|
||||||
_auto_label: "自動 (フェイルオーバー)",
|
_auto_label: "自動 (フェイルオーバー)",
|
||||||
},
|
},
|
||||||
_ => Self {
|
_ => Self {
|
||||||
show_main: "打开主界面",
|
show_main: "打开主界面",
|
||||||
no_provider_hint: " (无供应商,请在主界面添加)",
|
no_provider_hint: " (无供应商,请在主界面添加)",
|
||||||
lightweight_mode: "轻量模式",
|
|
||||||
quit: "退出",
|
quit: "退出",
|
||||||
_auto_label: "自动 (故障转移)",
|
_auto_label: "自动 (故障转移)",
|
||||||
},
|
},
|
||||||
@@ -386,18 +382,6 @@ pub fn create_tray_menu(
|
|||||||
menu_builder = menu_builder.separator();
|
menu_builder = menu_builder.separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
let lightweight_item = CheckMenuItem::with_id(
|
|
||||||
app,
|
|
||||||
"lightweight_mode",
|
|
||||||
tray_texts.lightweight_mode,
|
|
||||||
true,
|
|
||||||
crate::lightweight::is_lightweight_mode(),
|
|
||||||
None::<&str>,
|
|
||||||
)
|
|
||||||
.map_err(|e| AppError::Message(format!("创建轻量模式菜单失败: {e}")))?;
|
|
||||||
|
|
||||||
menu_builder = menu_builder.item(&lightweight_item).separator();
|
|
||||||
|
|
||||||
// 退出菜单(分隔符已在上面的 section 循环中添加)
|
// 退出菜单(分隔符已在上面的 section 循环中添加)
|
||||||
let quit_item = MenuItem::with_id(app, "quit", tray_texts.quit, true, None::<&str>)
|
let quit_item = MenuItem::with_id(app, "quit", tray_texts.quit, true, None::<&str>)
|
||||||
.map_err(|e| AppError::Message(format!("创建退出菜单失败: {e}")))?;
|
.map_err(|e| AppError::Message(format!("创建退出菜单失败: {e}")))?;
|
||||||
@@ -409,20 +393,6 @@ pub fn create_tray_menu(
|
|||||||
.map_err(|e| AppError::Message(format!("构建菜单失败: {e}")))
|
.map_err(|e| AppError::Message(format!("构建菜单失败: {e}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh_tray_menu(app: &tauri::AppHandle) {
|
|
||||||
use crate::store::AppState;
|
|
||||||
|
|
||||||
if let Some(state) = app.try_state::<AppState>() {
|
|
||||||
if let Ok(new_menu) = create_tray_menu(app, state.inner()) {
|
|
||||||
if let Some(tray) = app.tray_by_id("main") {
|
|
||||||
if let Err(e) = tray.set_menu(Some(new_menu)) {
|
|
||||||
log::error!("刷新托盘菜单失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub fn apply_tray_policy(app: &tauri::AppHandle, dock_visible: bool) {
|
pub fn apply_tray_policy(app: &tauri::AppHandle, dock_visible: bool) {
|
||||||
use tauri::ActivationPolicy;
|
use tauri::ActivationPolicy;
|
||||||
@@ -460,21 +430,6 @@ pub fn handle_tray_menu_event(app: &tauri::AppHandle, event_id: &str) {
|
|||||||
{
|
{
|
||||||
apply_tray_policy(app, true);
|
apply_tray_policy(app, true);
|
||||||
}
|
}
|
||||||
} else if crate::lightweight::is_lightweight_mode() {
|
|
||||||
if let Err(e) = crate::lightweight::exit_lightweight_mode(app) {
|
|
||||||
log::error!("退出轻量模式重建窗口失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"lightweight_mode" => {
|
|
||||||
if crate::lightweight::is_lightweight_mode() {
|
|
||||||
if let Err(e) = crate::lightweight::exit_lightweight_mode(app) {
|
|
||||||
log::error!("退出轻量模式失败: {e}");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Err(e) = crate::lightweight::enter_lightweight_mode(app) {
|
|
||||||
log::error!("进入轻量模式失败: {e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"quit" => {
|
"quit" => {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ const MACOS_TERMINALS = [
|
|||||||
{ value: "kitty", labelKey: "settings.terminal.options.macos.kitty" },
|
{ value: "kitty", labelKey: "settings.terminal.options.macos.kitty" },
|
||||||
{ value: "ghostty", labelKey: "settings.terminal.options.macos.ghostty" },
|
{ value: "ghostty", labelKey: "settings.terminal.options.macos.ghostty" },
|
||||||
{ value: "wezterm", labelKey: "settings.terminal.options.macos.wezterm" },
|
{ value: "wezterm", labelKey: "settings.terminal.options.macos.wezterm" },
|
||||||
{ value: "tabby", labelKey: "settings.terminal.options.macos.tabby" },
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const WINDOWS_TERMINALS = [
|
const WINDOWS_TERMINALS = [
|
||||||
@@ -26,7 +25,6 @@ const WINDOWS_TERMINALS = [
|
|||||||
labelKey: "settings.terminal.options.windows.powershell",
|
labelKey: "settings.terminal.options.windows.powershell",
|
||||||
},
|
},
|
||||||
{ value: "wt", labelKey: "settings.terminal.options.windows.wt" },
|
{ value: "wt", labelKey: "settings.terminal.options.windows.wt" },
|
||||||
{ value: "tabby", labelKey: "settings.terminal.options.windows.tabby" },
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const LINUX_TERMINALS = [
|
const LINUX_TERMINALS = [
|
||||||
@@ -42,7 +40,6 @@ const LINUX_TERMINALS = [
|
|||||||
{ value: "alacritty", labelKey: "settings.terminal.options.linux.alacritty" },
|
{ value: "alacritty", labelKey: "settings.terminal.options.linux.alacritty" },
|
||||||
{ value: "kitty", labelKey: "settings.terminal.options.linux.kitty" },
|
{ value: "kitty", labelKey: "settings.terminal.options.linux.kitty" },
|
||||||
{ value: "ghostty", labelKey: "settings.terminal.options.linux.ghostty" },
|
{ value: "ghostty", labelKey: "settings.terminal.options.linux.ghostty" },
|
||||||
{ value: "tabby", labelKey: "settings.terminal.options.linux.tabby" },
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// Get terminals for the current platform
|
// Get terminals for the current platform
|
||||||
|
|||||||
@@ -496,14 +496,12 @@
|
|||||||
"alacritty": "Alacritty",
|
"alacritty": "Alacritty",
|
||||||
"kitty": "Kitty",
|
"kitty": "Kitty",
|
||||||
"ghostty": "Ghostty",
|
"ghostty": "Ghostty",
|
||||||
"wezterm": "WezTerm",
|
"wezterm": "WezTerm"
|
||||||
"tabby": "Tabby"
|
|
||||||
},
|
},
|
||||||
"windows": {
|
"windows": {
|
||||||
"cmd": "Command Prompt",
|
"cmd": "Command Prompt",
|
||||||
"powershell": "PowerShell",
|
"powershell": "PowerShell",
|
||||||
"wt": "Windows Terminal",
|
"wt": "Windows Terminal"
|
||||||
"tabby": "Tabby"
|
|
||||||
},
|
},
|
||||||
"linux": {
|
"linux": {
|
||||||
"gnomeTerminal": "GNOME Terminal",
|
"gnomeTerminal": "GNOME Terminal",
|
||||||
@@ -511,8 +509,7 @@
|
|||||||
"xfce4Terminal": "Xfce4 Terminal",
|
"xfce4Terminal": "Xfce4 Terminal",
|
||||||
"alacritty": "Alacritty",
|
"alacritty": "Alacritty",
|
||||||
"kitty": "Kitty",
|
"kitty": "Kitty",
|
||||||
"ghostty": "Ghostty",
|
"ghostty": "Ghostty"
|
||||||
"tabby": "Tabby"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -496,14 +496,12 @@
|
|||||||
"alacritty": "Alacritty",
|
"alacritty": "Alacritty",
|
||||||
"kitty": "Kitty",
|
"kitty": "Kitty",
|
||||||
"ghostty": "Ghostty",
|
"ghostty": "Ghostty",
|
||||||
"wezterm": "WezTerm",
|
"wezterm": "WezTerm"
|
||||||
"tabby": "Tabby"
|
|
||||||
},
|
},
|
||||||
"windows": {
|
"windows": {
|
||||||
"cmd": "コマンドプロンプト",
|
"cmd": "コマンドプロンプト",
|
||||||
"powershell": "PowerShell",
|
"powershell": "PowerShell",
|
||||||
"wt": "Windows Terminal",
|
"wt": "Windows Terminal"
|
||||||
"tabby": "Tabby"
|
|
||||||
},
|
},
|
||||||
"linux": {
|
"linux": {
|
||||||
"gnomeTerminal": "GNOME Terminal",
|
"gnomeTerminal": "GNOME Terminal",
|
||||||
@@ -511,8 +509,7 @@
|
|||||||
"xfce4Terminal": "Xfce4 Terminal",
|
"xfce4Terminal": "Xfce4 Terminal",
|
||||||
"alacritty": "Alacritty",
|
"alacritty": "Alacritty",
|
||||||
"kitty": "Kitty",
|
"kitty": "Kitty",
|
||||||
"ghostty": "Ghostty",
|
"ghostty": "Ghostty"
|
||||||
"tabby": "Tabby"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -496,14 +496,12 @@
|
|||||||
"alacritty": "Alacritty",
|
"alacritty": "Alacritty",
|
||||||
"kitty": "Kitty",
|
"kitty": "Kitty",
|
||||||
"ghostty": "Ghostty",
|
"ghostty": "Ghostty",
|
||||||
"wezterm": "WezTerm",
|
"wezterm": "WezTerm"
|
||||||
"tabby": "Tabby"
|
|
||||||
},
|
},
|
||||||
"windows": {
|
"windows": {
|
||||||
"cmd": "命令提示符",
|
"cmd": "命令提示符",
|
||||||
"powershell": "PowerShell",
|
"powershell": "PowerShell",
|
||||||
"wt": "Windows Terminal",
|
"wt": "Windows Terminal"
|
||||||
"tabby": "Tabby"
|
|
||||||
},
|
},
|
||||||
"linux": {
|
"linux": {
|
||||||
"gnomeTerminal": "GNOME Terminal",
|
"gnomeTerminal": "GNOME Terminal",
|
||||||
@@ -511,8 +509,7 @@
|
|||||||
"xfce4Terminal": "Xfce4 Terminal",
|
"xfce4Terminal": "Xfce4 Terminal",
|
||||||
"alacritty": "Alacritty",
|
"alacritty": "Alacritty",
|
||||||
"kitty": "Kitty",
|
"kitty": "Kitty",
|
||||||
"ghostty": "Ghostty",
|
"ghostty": "Ghostty"
|
||||||
"tabby": "Tabby"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+3
-3
@@ -303,9 +303,9 @@ export interface Settings {
|
|||||||
|
|
||||||
// ===== 终端设置 =====
|
// ===== 终端设置 =====
|
||||||
// 首选终端应用(可选,默认使用系统默认终端)
|
// 首选终端应用(可选,默认使用系统默认终端)
|
||||||
// macOS: "terminal" | "iterm2" | "alacritty" | "kitty" | "ghostty" | "wezterm" | "tabby"
|
// macOS: "terminal" | "iterm2" | "warp" | "alacritty" | "kitty" | "ghostty"
|
||||||
// Windows: "cmd" | "powershell" | "wt" | "tabby"
|
// Windows: "cmd" | "powershell" | "wt"
|
||||||
// Linux: "gnome-terminal" | "konsole" | "xfce4-terminal" | "alacritty" | "kitty" | "ghostty" | "tabby"
|
// Linux: "gnome-terminal" | "konsole" | "xfce4-terminal" | "alacritty" | "kitty" | "ghostty"
|
||||||
preferredTerminal?: string;
|
preferredTerminal?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user