add pattern sort fields.

This commit is contained in:
Vixalie 2025-03-05 21:54:59 +08:00
parent db5b7f1dec
commit a1b5859cd6
2 changed files with 35 additions and 0 deletions

View File

@ -36,6 +36,8 @@ rand = "0.8.5"
tauri-plugin-devtools = "2.0.0" tauri-plugin-devtools = "2.0.0"
tauri-plugin-os = "2" tauri-plugin-os = "2"
tauri-plugin-notification = "2" tauri-plugin-notification = "2"
chrono = { version = "0.4.40", features = ["serde"] }
tzfile = "0.1.3"
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-single-instance = "2" tauri-plugin-single-instance = "2"

View File

@ -4,15 +4,24 @@ mod pulse;
use std::collections::VecDeque; use std::collections::VecDeque;
use chrono::{
naive::serde::{ts_milliseconds, ts_milliseconds_option},
NaiveDateTime,
};
pub use pulse::Pulse; pub use pulse::Pulse;
use pulse::{generate_pulse_sequence, RawPulse}; use pulse::{generate_pulse_sequence, RawPulse};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sled::IVec;
use uuid::Uuid; use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Pattern { pub struct Pattern {
pub id: Uuid, pub id: Uuid,
pub name: String, pub name: String,
#[serde(with = "ts_milliseconds")]
pub created_at: NaiveDateTime,
#[serde(with = "ts_milliseconds_option")]
pub last_modified_at: Option<NaiveDateTime>,
pub smooth_repeat: bool, pub smooth_repeat: bool,
pub pulses: VecDeque<Pulse>, pub pulses: VecDeque<Pulse>,
} }
@ -64,3 +73,27 @@ impl Pattern {
duration duration
} }
} }
impl From<&[u8]> for Pattern {
fn from(bytes: &[u8]) -> Self {
bincode::deserialize(&bytes).unwrap()
}
}
impl From<IVec> for Pattern {
fn from(bytes: IVec) -> Self {
bincode::deserialize(&bytes).unwrap()
}
}
impl Into<IVec> for Pattern {
fn into(self) -> IVec {
bincode::serialize(&self).unwrap().into()
}
}
impl Into<IVec> for &Pattern {
fn into(self) -> IVec {
bincode::serialize(self).unwrap().into()
}
}