data between friends (with some crazy fancy UI)

This commit is contained in:
2026-08-10 02:07:51 +08:00
parent 8bc1d074d4
commit 4c0cbc9c85
10 changed files with 757 additions and 20 deletions
+37
View File
@@ -0,0 +1,37 @@
use serde::{Deserialize, Serialize};
use crate::cursor::CursorPositions;
use crate::ufa::AppMeta;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum LiveData {
Cursor { positions: CursorPositions },
ForegroundApp { meta: AppMeta },
}
#[cfg(test)]
mod tests {
use super::*;
use crate::cursor::{CursorPosition, CursorPositions};
#[test]
fn live_data_is_internally_tagged_for_client_side_dispatch() {
let payload = serde_json::to_string(&LiveData::Cursor {
positions: CursorPositions {
raw: CursorPosition { x: 120.0, y: 80.0 },
mapped: CursorPosition { x: 0.25, y: 0.5 },
},
})
.unwrap();
assert_eq!(
payload,
r#"{"type":"cursor","positions":{"raw":{"x":120.0,"y":80.0},"mapped":{"x":0.25,"y":0.5}}}"#
);
assert!(matches!(
serde_json::from_str(&payload).unwrap(),
LiveData::Cursor { .. }
));
}
}