fix(tray): resolve tray open log failed (#6301)

* fix(tray): resolve tray open log failed

* fix(ci): allow missing_const_for_fn

* fix(windows): run snapshot log cleanup unconditionally and cover all temp dirs

* refactor: simplify snapshot_path

* fix: clippy

* refactor: delete_snapshot_logs

---------

Co-authored-by: Slinetrac <realakayuki@gmail.com>
This commit is contained in:
AetherWing
2026-02-12 03:53:36 +00:00
committed by GitHub
co-authored by Slinetrac
parent 81c56d46c1
commit 847a0a6afd
4 changed files with 59 additions and 2 deletions
+27
View File
@@ -13,11 +13,35 @@ use crate::{
use anyhow::Result;
use chrono::{Local, TimeZone as _};
use clash_verge_logging::Type;
#[cfg(target_os = "windows")]
use std::path::Path;
use std::{path::PathBuf, str::FromStr as _};
use tauri_plugin_shell::ShellExt as _;
use tokio::fs;
use tokio::fs::DirEntry;
#[cfg(target_os = "windows")]
async fn delete_snapshot_logs(log_dir: &Path) -> Result<()> {
let temp_dirs = [
log_dir.join("temp"),
log_dir.join("service").join("temp"),
log_dir.join("sidecar").join("temp"),
];
for temp_dir in temp_dirs.iter().filter(|d| d.exists()) {
let mut entries = fs::read_dir(temp_dir).await?;
while let Some(entry) = entries.next_entry().await? {
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) == Some("log") {
let _ = path.remove_if_exists().await;
logging!(info, Type::Setup, "delete snapshot log file: {}", path.display());
}
}
}
Ok(())
}
// TODO flexi_logger 提供了最大保留天数,或许我们应该用内置删除log文件
/// 删除log文件
pub async fn delete_log() -> Result<()> {
@@ -26,6 +50,9 @@ pub async fn delete_log() -> Result<()> {
return Ok(());
}
#[cfg(target_os = "windows")]
delete_snapshot_logs(&log_dir).await?;
let auto_log_clean = {
let verge = Config::verge().await;
let verge = verge.data_arc();