use crate::config::Config;
use crate::config::remote::RemoteConfigManager;
use crate::{log_err, log_info, log_warn};
pub async fn try_auto_sync(config: &Config) {
if let Ok(local_config) = config.load().await {
let remote = local_config.remote.clone().unwrap_or_default();
let remote_mgr = RemoteConfigManager::new(remote.url);
if remote.autosync.unwrap_or_default() {
match remote_mgr.fetch().await {
Ok(()) => {
if let Err(e) = remote_mgr.save().await {
log_err!("Failed to save remote config after auto-sync: {e}");
}
}
Err(e) => {
log_warn!("Remote config auto-sync failed: {e}",);
}
}
} else {
log_info!("Skipping auto-sync since disabled in config.",);
}
}
}