mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-29 10:02:09 +08:00
fix(updater): clear cache when auto-check is disabled
Assisted-by: vscode-copilot-chat:copilot:gpt-6-luna
This commit is contained in:
@@ -83,7 +83,7 @@ impl SilentUpdater {
|
||||
Ok(serde_json::from_str(&content)?)
|
||||
}
|
||||
|
||||
fn delete_cache() {
|
||||
pub fn delete_cache() {
|
||||
if let Ok(cache_dir) = Self::cache_dir()
|
||||
&& cache_dir.exists()
|
||||
{
|
||||
@@ -150,6 +150,11 @@ fn nsis_language_id(app_language: &str) -> &'static str {
|
||||
impl SilentUpdater {
|
||||
/// Installs a newer cached update before normal startup, if the user confirms.
|
||||
pub async fn try_install_on_startup(&self, app_handle: &tauri::AppHandle) -> bool {
|
||||
if !Config::verge().await.latest_arc().auto_check_update.unwrap_or(true) {
|
||||
Self::delete_cache();
|
||||
return false;
|
||||
}
|
||||
|
||||
let current_version = env!("CARGO_PKG_VERSION");
|
||||
|
||||
let meta = match Self::read_cache_meta() {
|
||||
@@ -470,9 +475,21 @@ impl SilentUpdater {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let config_write = Config::lock_config_write().await;
|
||||
let auto_check = Config::verge().await.latest_arc().auto_check_update.unwrap_or(true);
|
||||
if !auto_check {
|
||||
logging!(
|
||||
info,
|
||||
Type::System,
|
||||
"Silent updater: discarding download because auto check was disabled"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Err(e) = Self::write_cache(&bytes, &version) {
|
||||
logging!(warn, Type::System, "Silent updater: failed to write cache: {e:#}");
|
||||
}
|
||||
drop(config_write);
|
||||
|
||||
*self.pending_bytes.write() = Some(bytes);
|
||||
*self.pending_update.write() = Some(update);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
core::{CoreManager, autostart, handle, hotkey, logger, proxy_control, tray},
|
||||
core::{CoreManager, SilentUpdater, autostart, handle, hotkey, logger, proxy_control, tray},
|
||||
module::{auto_backup::AutoBackupManager, lightweight},
|
||||
};
|
||||
use anyhow::Result;
|
||||
@@ -318,6 +318,9 @@ pub(super) async fn apply_verge_patch_locked(
|
||||
let verge_data = verge.data_arc();
|
||||
verge_data.save_file().await?;
|
||||
}
|
||||
if patch.auto_check_update == Some(false) {
|
||||
SilentUpdater::delete_cache();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user