Skip to content

Commit

Permalink
feat: derive serde for more types
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Aug 16, 2023
1 parent d5cd20e commit 75fed4a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/serde.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tray-icon": "patch"
---

Derive `serde` for more types.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ categories = [ "gui" ]
[features]
default = [ "libxdo" ]
libxdo = [ "muda/libxdo" ]
serde = [ "muda/serde" ]
serde = [ "muda/serde", "dep:serde" ]
common-controls-v6 = [ "muda/common-controls-v6" ]

[dependencies]
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"
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/tray_icon_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 75fed4a

Please sign in to comment.