This commit is contained in:
fengchuanhn@gmail.com
2026-05-22 14:52:30 +08:00
parent ce1fe99883
commit ca1b254825
2 changed files with 32 additions and 5 deletions

View File

@@ -5,8 +5,7 @@ use std::time::Duration;
use chrono::Utc;
use rand::Rng;
use tauri::AppHandle;
use tauri::Manager;
use tauri::{AppHandle, Emitter, Manager};
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use serde_json::Value;
@@ -161,6 +160,7 @@ pub async fn send_heartbeat(token: &str) -> Result<(), String> {
let server_code = response_server_verify_code(&value);
if server_code != Some(expected.as_str()) {
return Err("会员已过期".into());
}
@@ -192,8 +192,11 @@ pub fn spawn_heartbeat_loop(app: AppHandle) {
continue;
}
match send_heartbeat(&token).await {
Ok(()) => log::debug!(target: "heartbeat", "heartbeat ok"),
Err(e) => log::warn!(target: "heartbeat", "heartbeat failed: {e}"),
Ok(()) => {}
Err(e) => {
println!("[heartbeat] failed: {e}");
let _ = app.emit("auth-heartbeat-failed", e);
}
}
}
});