use std::path::{Path, PathBuf};
use anyhow::Result;
pub fn load_profile() -> (sculk::persist::Profile, Option<String>) {
match sculk::persist::Profile::load() {
Ok(p) => (p, None),
Err(e) => (Default::default(), Some(format!("配置加载失败: {e}"))),
}
}
#[cfg(not(test))]
pub fn save_profile(profile: &sculk::persist::Profile) -> Result<()> {
Ok(profile.save()?)
}
#[cfg(test)]
pub fn save_profile(_profile: &sculk::persist::Profile) -> Result<()> {
Ok(())
}
pub fn resolve_relay_url(
profile: &sculk::persist::Profile,
custom: Option<&str>,
) -> Result<Option<sculk::RelayUrl>> {
Ok(profile.resolve_relay_url(custom)?)
}
pub fn default_key_path() -> Result<PathBuf> {
sculk::persist::default_key_path().map_err(Into::into)
}
pub fn load_or_generate_key(path: &Path) -> Result<sculk::SecretKey> {
Ok(sculk::persist::load_or_generate_key(path)?)
}
#[cfg(not(test))]
pub fn clipboard_copy(content: &str) -> bool {
sculk::clipboard::clipboard_copy(content)
}
#[cfg(test)]
pub fn clipboard_copy(_content: &str) -> bool {
false
}