From 5ebd07e52b4ebc1f59b603bbd4fe781871056755 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 23 Nov 2025 15:56:13 +0800 Subject: Add auto update feature via JV_AUTO_UPDATE env var When enabled, automatically runs `jv update` if vault content has been modified by local operations. --- src/utils/env.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/utils/env.rs') diff --git a/src/utils/env.rs b/src/utils/env.rs index 028995e..5a37365 100644 --- a/src/utils/env.rs +++ b/src/utils/env.rs @@ -26,3 +26,24 @@ pub fn current_locales() -> String { "en".to_string() } + +/// Checks if auto update is enabled based on environment variables. +/// +/// The function checks the JV_AUTO_UPDATE environment variable and compares +/// its value (after trimming and converting to lowercase) against known +/// positive and negative values. +/// +/// # Returns +/// `true` if the value matches "yes", "y", or "true" +/// `false` if the value matches "no", "n", or "false", or if the variable is not set +pub fn enable_auto_update() -> bool { + if let Ok(auto_update) = std::env::var("JV_AUTO_UPDATE") { + let normalized = auto_update.trim().to_lowercase(); + match normalized.as_str() { + "yes" | "y" | "true" => return true, + "no" | "n" | "false" => return false, + _ => {} + } + } + false +} -- cgit