From 75fed4aeca82c5614777865a9f6fa2d4457f47a1 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 16 Aug 2023 19:37:14 +0300 Subject: [PATCH] feat: derive serde for more types --- .changes/serde.md | 5 +++++ Cargo.toml | 5 +++-- README.md | 2 +- src/lib.rs | 3 +++ src/tray_icon_id.rs | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changes/serde.md diff --git a/.changes/serde.md b/.changes/serde.md new file mode 100644 index 0000000..87a9f9e --- /dev/null +++ b/.changes/serde.md @@ -0,0 +1,5 @@ +--- +"tray-icon": "patch" +--- + +Derive `serde` for more types. diff --git a/Cargo.toml b/Cargo.toml index 9790d45..06bedc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ categories = [ "gui" ] [features] default = [ "libxdo" ] libxdo = [ "muda/libxdo" ] -serde = [ "muda/serde" ] +serde = [ "muda/serde", "dep:serde" ] common-controls-v6 = [ "muda/common-controls-v6" ] [dependencies] @@ -19,6 +19,7 @@ muda = { version = "0.8", default-features = false } crossbeam-channel = "0.5" once_cell = "1" thiserror = "1.0" +serde = { version = "1", optional = true } [target."cfg(target_os = \"windows\")".dependencies.windows-sys] version = "0.48" @@ -27,7 +28,7 @@ features = [ "Win32_Foundation", "Win32_System_SystemServices", "Win32_Graphics_Gdi", - "Win32_UI_Shell" + "Win32_UI_Shell", ] [target."cfg(target_os = \"linux\")".dependencies] diff --git a/README.md b/README.md index c596804..e1288f2 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ tray-icon lets you create tray icons for desktop applications. - `common-controls-v6`: Use `TaskDialogIndirect` API from `ComCtl32.dll` v6 on Windows for showing the predefined `About` menu item dialog. - `libxdo`: Enables linking to `libxdo` which is used for the predfined `Copy`, `Cut`, `Paste` and `SelectAll` menu item, see https://github.com/tauri-apps/muda#cargo-features -- `serde`:Enables de/serializing the dpi types. +- `serde`: Enables de/serializing derives. ## Dependencies (Linux Only) diff --git a/src/lib.rs b/src/lib.rs index 907d4ba..5b44c15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -402,6 +402,7 @@ impl TrayIcon { /// - **Linux**: Unsupported. The event is not emmited even though the icon is shown, /// the icon will still show a context menu on right click. #[derive(Debug, Clone, Default)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TrayIconEvent { /// Id of the tray icon which triggered this event. pub id: TrayIconId, @@ -416,6 +417,7 @@ pub struct TrayIconEvent { } #[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ClickType { Left, Right, @@ -430,6 +432,7 @@ impl Default for ClickType { /// Describes a rectangle including position (x - y axis) and size. #[derive(Debug, PartialEq, Clone, Copy, Default)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Rectangle { pub left: f64, pub right: f64, diff --git a/src/tray_icon_id.rs b/src/tray_icon_id.rs index 194c335..9c0f6af 100644 --- a/src/tray_icon_id.rs +++ b/src/tray_icon_id.rs @@ -2,6 +2,7 @@ use std::{convert::Infallible, str::FromStr}; /// An unique id that is associated with a tray icon. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TrayIconId(pub String); impl TrayIconId {