Release 1.0
This commit is contained in:
parent
009ea6da0e
commit
730a8b61d7
32 changed files with 6629 additions and 0 deletions
8
bread-shared/Cargo.toml
Normal file
8
bread-shared/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "bread-shared"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
45
bread-shared/src/lib.rs
Normal file
45
bread-shared/src/lib.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq, Hash)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AdapterSource {
|
||||
Hyprland,
|
||||
Udev,
|
||||
Power,
|
||||
Network,
|
||||
System,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RawEvent {
|
||||
pub source: AdapterSource,
|
||||
pub kind: String,
|
||||
pub payload: serde_json::Value,
|
||||
pub timestamp: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BreadEvent {
|
||||
pub event: String,
|
||||
pub timestamp: u64,
|
||||
pub source: AdapterSource,
|
||||
pub data: serde_json::Value,
|
||||
}
|
||||
|
||||
impl BreadEvent {
|
||||
pub fn new(event: impl Into<String>, source: AdapterSource, data: serde_json::Value) -> Self {
|
||||
Self {
|
||||
event: event.into(),
|
||||
timestamp: now_unix_ms(),
|
||||
source,
|
||||
data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn now_unix_ms() -> u64 {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as u64
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue