From cd8ab5c12bf8715aa845236dc61ef98b4e3049c0 Mon Sep 17 00:00:00 2001 From: NimBold Date: Thu, 9 Jul 2026 18:15:29 +0330 Subject: [PATCH] fix(deps): scope linux keyring entries --- src-tauri/src/db.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index 516aad5..f386fd2 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -908,11 +908,32 @@ fn ensure_keyring_store() -> Result<(), String> { } } -fn keychain_entry(id: &str) -> Result { +fn keychain_entry_with_target( + id: &str, + target: Option<&str>, +) -> Result { ensure_keyring_store()?; + if let Some(target) = target { + return keyring_core::Entry::new_with_modifiers( + KEYCHAIN_SERVICE, + id, + &std::collections::HashMap::from([("target", target)]), + ) + .map_err(|error| error.to_string()); + } keyring_core::Entry::new(KEYCHAIN_SERVICE, id).map_err(|error| error.to_string()) } +fn keychain_entry(id: &str) -> Result { + #[cfg(target_os = "linux")] + { + return keychain_entry_with_target(id, Some("default")); + } + + #[cfg(not(target_os = "linux"))] + keychain_entry_with_target(id, None) +} + pub fn set_keychain_password(id: &str, password: &str) -> Result<(), String> { let entry = keychain_entry(id)?; entry @@ -922,7 +943,15 @@ pub fn set_keychain_password(id: &str, password: &str) -> Result<(), String> { pub fn get_keychain_password(id: &str) -> Result { let entry = keychain_entry(id)?; - entry.get_password().map_err(|error| error.to_string()) + match entry.get_password() { + Ok(password) => Ok(password), + #[cfg(target_os = "linux")] + Err(_) => keychain_entry_with_target(id, None)? + .get_password() + .map_err(|error| error.to_string()), + #[cfg(not(target_os = "linux"))] + Err(error) => Err(error.to_string()), + } } pub fn delete_keychain_password(id: &str) -> Result<(), String> {