summaryrefslogtreecommitdiff
path: root/utils/src/legacy/env.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-21 18:44:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-21 18:44:56 +0800
commit90dcfdd8b81948fa9aabf9ea36761e7d7bc1061b (patch)
tree142a4352f8fa146b2e80320d51dc9300dc92f22f /utils/src/legacy/env.rs
parent40b688f44009b5a82855db298be33483d2e2d619 (diff)
Remove legacy modules and unused dependencies
Diffstat (limited to 'utils/src/legacy/env.rs')
-rw-r--r--utils/src/legacy/env.rs104
1 files changed, 0 insertions, 104 deletions
diff --git a/utils/src/legacy/env.rs b/utils/src/legacy/env.rs
deleted file mode 100644
index b4ad089..0000000
--- a/utils/src/legacy/env.rs
+++ /dev/null
@@ -1,104 +0,0 @@
-use std::path::PathBuf;
-
-/// Returns the current locale string based on environment variables.
-///
-/// The function checks for locale settings in the following order:
-/// 1. JV_LANG environment variable
-/// 2. APP_LANG environment variable
-/// 3. LANG environment variable (extracts base language before dot and replaces underscores with hyphens)
-/// 4. Defaults to "en" if no locale environment variables are found
-///
-/// # Returns
-/// A String containing the detected locale code
-pub fn current_locales() -> String {
- if let Ok(lang) = std::env::var("JV_LANG") {
- return lang;
- }
-
- if let Ok(lang) = std::env::var("APP_LANG") {
- return lang;
- }
-
- if let Ok(lang) = std::env::var("LANG") {
- if let Some(base_lang) = lang.split('.').next() {
- return base_lang.replace('_', "-");
- }
- return lang;
- }
-
- "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
-}
-
-/// Gets the auto update expiration time based on environment variables.
-///
-/// The function checks the JV_OUTDATED_MINUTES environment variable.
-/// Requires JV_AUTO_UPDATE to be enabled.
-/// Next time the `jv` command is used, if the content is outdated, `jv update` will be automatically executed.
-///
-/// # Returns
-/// - When the set number is < 0, timeout-based update is disabled
-/// - When the set number = 0, update runs every time (not recommended)
-/// - When the set number > 0, update according to the specified time
-/// - If not set or conversion error occurs, the default is -1
-pub fn auto_update_outdate() -> i64 {
- if !enable_auto_update() {
- return -1;
- }
-
- match std::env::var("JV_OUTDATED_MINUTES") {
- Ok(value) => value.trim().parse::<i64>().unwrap_or(-1),
- Err(_) => -1,
- }
-}
-
-/// Gets the default text editor based on environment variables.
-///
-/// The function checks the JV_TEXT_EDITOR and EDITOR environment variables
-/// and returns their values if they are set. If neither variable is set,
-/// it returns "jvii" as the default editor.
-///
-/// # Returns
-/// A String containing the default text editor
-pub async fn get_default_editor() -> String {
- if let Ok(editor) = std::env::var("JV_TEXT_EDITOR") {
- return editor;
- }
-
- if let Ok(editor) = std::env::var("EDITOR") {
- return editor;
- }
-
- "jvii".to_string()
-}
-
-/// Get temporary file path
-pub fn current_tempfile_path(name: &str) -> Option<PathBuf> {
- dirs::config_local_dir().map(|path| {
- if cfg!(target_os = "linux") {
- path.join("jvcs").join(".temp").join(name)
- } else {
- path.join("JustEnoughVCS").join(".temp").join(name)
- }
- })
-}