From a1b5859cd6292c39c65caf6d666ed1ba385abf03 Mon Sep 17 00:00:00 2001 From: Vixalie Date: Wed, 5 Mar 2025 21:54:59 +0800 Subject: [PATCH] add pattern sort fields. --- src-tauri/Cargo.toml | 2 ++ src-tauri/src/pattern/mod.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index eb1ad7b..4e996cf 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -36,6 +36,8 @@ rand = "0.8.5" tauri-plugin-devtools = "2.0.0" tauri-plugin-os = "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] tauri-plugin-single-instance = "2" diff --git a/src-tauri/src/pattern/mod.rs b/src-tauri/src/pattern/mod.rs index ce2055c..d176a80 100644 --- a/src-tauri/src/pattern/mod.rs +++ b/src-tauri/src/pattern/mod.rs @@ -4,15 +4,24 @@ mod pulse; use std::collections::VecDeque; +use chrono::{ + naive::serde::{ts_milliseconds, ts_milliseconds_option}, + NaiveDateTime, +}; pub use pulse::Pulse; use pulse::{generate_pulse_sequence, RawPulse}; use serde::{Deserialize, Serialize}; +use sled::IVec; use uuid::Uuid; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Pattern { pub id: Uuid, pub name: String, + #[serde(with = "ts_milliseconds")] + pub created_at: NaiveDateTime, + #[serde(with = "ts_milliseconds_option")] + pub last_modified_at: Option, pub smooth_repeat: bool, pub pulses: VecDeque, } @@ -64,3 +73,27 @@ impl Pattern { duration } } + +impl From<&[u8]> for Pattern { + fn from(bytes: &[u8]) -> Self { + bincode::deserialize(&bytes).unwrap() + } +} + +impl From for Pattern { + fn from(bytes: IVec) -> Self { + bincode::deserialize(&bytes).unwrap() + } +} + +impl Into for Pattern { + fn into(self) -> IVec { + bincode::serialize(&self).unwrap().into() + } +} + +impl Into for &Pattern { + fn into(self) -> IVec { + bincode::serialize(self).unwrap().into() + } +}