Complete private authentication, server integrations and activity reporting
Add Fabric/Forge version builds and Paper integration, preserve permanent player identities across renames, harden session authorization, and surface privacy-conscious launcher/server activity in the panel.
This commit is contained in:
commit
a1f19e86c6
74 files changed
+2108
-95
No files matched your search
@@ -0,0 +1,55 @@
|
||||
//! Account-attributed activity only; no passwords, game logs, chat, or local paths.
|
||||
use crate::{accounts, state::AppState};
|
||||
use scopenet_shared::LaunchEvent;
|
||||
use std::time::Duration;
|
||||
|
||||
/// Capture the identity when work starts, so switching accounts cannot
|
||||
/// attribute a running game's exit to the newly selected player.
|
||||
#[derive(Clone)]
|
||||
pub struct Recorder {
|
||||
http: reqwest::Client,
|
||||
panel: String,
|
||||
token: String,
|
||||
}
|
||||
|
||||
pub fn capture(state: &AppState) -> Option<Recorder> {
|
||||
Some(Recorder { http: state.http.clone(), panel: state.panel_url()?, token: accounts::panel_token(state)? })
|
||||
}
|
||||
|
||||
impl Recorder {
|
||||
pub async fn send(&self, kind: &str, instance: &str) -> anyhow::Result<()> {
|
||||
self.http
|
||||
.post(format!("{}/api/v1/launcher/events", self.panel))
|
||||
.bearer_auth(&self.token)
|
||||
.timeout(Duration::from_secs(5))
|
||||
.json(&LaunchEvent { kind: kind.into(), instance_id: instance.into(), username: None })
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn background(&self, kind: &str, instance: &str) {
|
||||
let recorder = self.clone();
|
||||
let kind = kind.to_owned();
|
||||
let instance = instance.to_owned();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
if let Err(e) = recorder.send(&kind, &instance).await {
|
||||
tracing::warn!("activity report failed: {e}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send(state: &AppState, kind: &str, instance: &str) -> anyhow::Result<()> {
|
||||
if let Some(recorder) = capture(state) {
|
||||
recorder.send(kind, instance).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn background(state: &AppState, kind: &str, instance: &str) {
|
||||
if let Some(recorder) = capture(state) {
|
||||
recorder.background(kind, instance);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user