diff --git a/.vscode/settings.json b/.vscode/settings.json index 0db8f97..a226e41 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,14 +9,19 @@ "cSpell.words": [ "arboard", "clipsync", + "dioxus", + "evenodd", "Freqs", "gethostname", "jieba", "libxcb", "Mmap", "mqtt", + "oninput", + "onsubmit", "rumqttc", "rustls", + "stylesheet", "tungstenite", "webbrowser", "xfixes" diff --git a/Cargo.lock b/Cargo.lock index 6e5a56d..adc88a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -374,7 +374,7 @@ checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "clip-sync" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "arboard", diff --git a/Cargo.toml b/Cargo.toml index 5ea0e19..2dfde7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clip-sync" authors = ["Chen Xu "] -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "A clipboard sync tool" rust-version = "1.75.0" diff --git a/clip-sync-ui/Cargo.toml b/clip-sync-ui/Cargo.toml index ffde516..49e202a 100644 --- a/clip-sync-ui/Cargo.toml +++ b/clip-sync-ui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clip-sync-ui" -version = "0.1.0" +version = "0.2.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/clip-sync-ui/src/main.rs b/clip-sync-ui/src/main.rs index b667c54..b32cfd4 100644 --- a/clip-sync-ui/src/main.rs +++ b/clip-sync-ui/src/main.rs @@ -1,12 +1,9 @@ -use std::time::Duration; -use chrono::{Utc, TimeZone}; -use dioxus::{ - html::GlobalAttributes, - prelude::*, -}; +use chrono::{TimeZone, Utc}; +use dioxus::{html::GlobalAttributes, prelude::*}; +use gloo_timers::future::sleep; use log::LevelFilter; use serde::{Deserialize, Serialize}; -use gloo_timers::future::sleep; +use std::time::Duration; pub static BASE_API_URL: &str = "/api"; @@ -17,7 +14,7 @@ pub fn base_url() -> String { #[derive(Clone, PartialEq, Eq, Deserialize, Serialize, Debug)] pub struct ClipboardEntry { pub source: String, - pub data: String, + pub text: String, pub timestamp: i64, } @@ -57,7 +54,7 @@ pub fn CopyButton(cx: Scope, text: String) -> Element { fn Entry(cx: Scope, entry: ClipboardEntry) -> Element { let ClipboardEntry { source, - data, + text, timestamp, } = entry; let datetime = Utc.timestamp_opt(*timestamp, 0).unwrap(); @@ -72,11 +69,11 @@ fn Entry(cx: Scope, entry: ClipboardEntry) -> Element { class: "min-w-0 flex-auto", pre { class: "my_pre", - "{data}" + "{text}" } span { class: "inline-flex items-center px-2 py-1 text-xs font-medium text-gray-600", - CopyButton { text: data.clone() } + CopyButton { text: text.clone() } } span { class: "inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-inset ring-yellow-600/20", @@ -136,7 +133,7 @@ pub fn app(cx: Scope) -> Element { class: "w-5 h-5", path { d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" - } + } } } } @@ -174,7 +171,6 @@ pub fn app(cx: Scope) -> Element { value: "{search_input}", placeholder: "Search for text...", oninput: move |evt| { search_input.set(evt.value.clone()); entries.restart(); }, - // onkeydown: move |evt| { if evt.key() == Key::Enter {} } } } match entries.value() { diff --git a/src/server/mod.rs b/src/server/mod.rs index e1efc00..6d10cfd 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -102,13 +102,15 @@ struct ClipboardMessage { timestamp: i64, } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ServerClipboardData { pub source: String, + #[serde(flatten)] pub content: ServerClipboardContent, } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum ServerClipboardContent { Text(String), ImageUrl(String), @@ -395,3 +397,26 @@ pub async fn server_main(mut args: ServerConfig) -> Result<(), std::io::Error> { } Ok(()) } + +#[cfg(test)] +mod tests { + #[test] + fn test_serde() { + use super::{ServerClipboardContent, ServerClipboardData}; + let data = ServerClipboardData { + source: "test".to_string(), + content: ServerClipboardContent::Text("test".to_string()), + }; + let json = serde_json::to_string(&data).unwrap(); + println!("{}", json); + let data2: ServerClipboardData = serde_json::from_str(&json).unwrap(); + assert_eq!(data, data2); + + let msg = super::ClipboardMessage { + entry: data, + timestamp: 0, + }; + let json = serde_json::to_string(&msg).unwrap(); + println!("{}", json); + } +}