优化,贴图

This commit is contained in:
zhongluofeng
2026-08-07 18:09:13 +08:00
parent e09b0567d6
commit d09599fa95
40 changed files with 1627 additions and 493 deletions
+26 -5
View File
@@ -67,6 +67,27 @@ pub async fn screenshot_unregister_shortcut(app: tauri::AppHandle) -> Result<(),
Ok(())
}
/// 注册(或切换)贴图全局快捷键。传入空字符串则禁用快捷键。
/// 按下时 emit 'screenshot-pin-shortcut',由前端切换贴图窗口显示/隐藏。
#[tauri::command]
#[specta::specta]
pub async fn screenshot_register_pin_shortcut(
app: tauri::AppHandle,
shortcut: String,
) -> Result<(), String> {
crate::shortcut::register_shortcut(&app, "贴图", &shortcut, |a| {
let _ = a.emit(crate::constants::events::SCREENSHOT_PIN_SHORTCUT, ());
})
}
/// 注销贴图全局快捷键
#[tauri::command]
#[specta::specta]
pub async fn screenshot_unregister_pin_shortcut(app: tauri::AppHandle) -> Result<(), String> {
crate::shortcut::unregister_shortcut(&app, "贴图");
Ok(())
}
/// 捕获整个虚拟屏(多显示器拼接)存入静态,不做 PNG 编码
#[tauri::command]
#[specta::specta]
@@ -349,17 +370,17 @@ pub async fn screenshot_save_png(png_base64: String, path: String) -> Result<(),
.map_err(|e| format!("保存任务失败: {}", e))?
}
// ===== 截图历史缓存:完整 PNG 落盘缓存目录,内存只保留缩略图 =====
// ===== 截图历史缓存:完整 PNG 落盘到应用数据目录(持久化,随历史保留数量清理),内存只保留缩略图 =====
/// 历史缓存根目录(app_cache_dir/screenshot/history
/// 历史根目录(app_data_dir/screenshot/history
fn history_cache_dir(app: &tauri::AppHandle) -> Result<std::path::PathBuf, String> {
let dir = app
.path()
.app_cache_dir()
.map_err(|e| format!("获取缓存目录失败: {}", e))?
.app_data_dir()
.map_err(|e| format!("获取应用数据目录失败: {}", e))?
.join("screenshot")
.join("history");
std::fs::create_dir_all(&dir).map_err(|e| format!("创建缓存目录失败: {}", e))?;
std::fs::create_dir_all(&dir).map_err(|e| format!("创建历史目录失败: {}", e))?;
Ok(dir)
}