The Tauri command `get_init_error` was importing a function with the same name from `init_status` module, causing a compile-time error: "the name `get_init_error` is defined multiple times". Changes: - Remove `get_init_error` from the use statement in misc.rs - Use fully qualified path `crate::init_status::get_init_error()` in the command implementation to call the underlying function This eliminates the ambiguity while keeping the public API unchanged.
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
#![allow(non_snake_case)]
|
|
|
|
use tauri::AppHandle;
|
|
use tauri_plugin_opener::OpenerExt;
|
|
use crate::init_status::InitErrorPayload;
|
|
|
|
/// 打开外部链接
|
|
#[tauri::command]
|
|
pub async fn open_external(app: AppHandle, url: String) -> Result<bool, String> {
|
|
let url = if url.starts_with("http://") || url.starts_with("https://") {
|
|
url
|
|
} else {
|
|
format!("https://{}", url)
|
|
};
|
|
|
|
app.opener()
|
|
.open_url(&url, None::<String>)
|
|
.map_err(|e| format!("打开链接失败: {}", e))?;
|
|
|
|
Ok(true)
|
|
}
|
|
|
|
/// 检查更新
|
|
#[tauri::command]
|
|
pub async fn check_for_updates(handle: AppHandle) -> Result<bool, String> {
|
|
handle
|
|
.opener()
|
|
.open_url(
|
|
"https://github.com/farion1231/cc-switch/releases/latest",
|
|
None::<String>,
|
|
)
|
|
.map_err(|e| format!("打开更新页面失败: {}", e))?;
|
|
|
|
Ok(true)
|
|
}
|
|
|
|
/// 判断是否为便携版(绿色版)运行
|
|
#[tauri::command]
|
|
pub async fn is_portable_mode() -> Result<bool, String> {
|
|
let exe_path = std::env::current_exe().map_err(|e| format!("获取可执行路径失败: {}", e))?;
|
|
if let Some(dir) = exe_path.parent() {
|
|
Ok(dir.join("portable.ini").is_file())
|
|
} else {
|
|
Ok(false)
|
|
}
|
|
}
|
|
|
|
/// 获取应用启动阶段的初始化错误(若有)。
|
|
/// 用于前端在早期主动拉取,避免事件订阅竞态导致的提示缺失。
|
|
#[tauri::command]
|
|
pub async fn get_init_error() -> Result<Option<InitErrorPayload>, String> {
|
|
Ok(crate::init_status::get_init_error())
|
|
}
|