Skip to content

Commit

Permalink
Rewrite to use objc2 (#172)
Browse files Browse the repository at this point in the history
* Rewrite to use objc2

This ensures that memory management rules are upheld, as well as greatly
improving type-safety.

API-wise, this adds a new error case `NotMainThread`, which is triggered
when a TrayIcon is created on a thread that is not the main thread.

* Fix clippy CI in Windows platform

* Add changelog entries
  • Loading branch information
madsmtm authored Jun 28, 2024
1 parent 9231438 commit d407869
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 296 deletions.
5 changes: 5 additions & 0 deletions .changes/add_mainthread_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tray-icon": minor
---

Added a new variant `NotMainThread` to the `Error` enum, which is emitted on macOS when trying to create tray icons from a thread that is not the main thread.
7 changes: 7 additions & 0 deletions .changes/rewrite_objc2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tray-icon": patch
---

Rewrite the internals of the crate to use `objc2` instead of `objc`.

This should have no user-facing changes, other than improved memory safety, and less leaking.
39 changes: 31 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ description = "Create tray icons for desktop applications"
homepage = "https://github.com/tauri-apps/tray-icon"
repository = "https://github.com/tauri-apps/tray-icon"
license = "MIT OR Apache-2.0"
categories = [ "gui" ]
categories = ["gui"]

[features]
default = [ "libxdo" ]
libxdo = [ "muda/libxdo" ]
serde = [ "muda/serde", "dep:serde" ]
common-controls-v6 = [ "muda/common-controls-v6" ]
default = ["libxdo"]
libxdo = ["muda/libxdo"]
serde = ["muda/serde", "dep:serde"]
common-controls-v6 = ["muda/common-controls-v6"]

[dependencies]
muda = { version = "0.13", default-features = false }
Expand All @@ -28,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 All @@ -39,8 +39,31 @@ dirs = "5"
gtk = "0.18"

[target."cfg(target_os = \"macos\")".dependencies]
cocoa = "0.25"
objc = "0.2"
objc2 = "0.5.2"
objc2-foundation = { version = "0.2.2", features = [
"block2",
"NSArray",
"NSData",
"NSEnumerator",
"NSGeometry",
"NSString",
"NSThread",
] }
objc2-app-kit = { version = "0.2.2", features = [
"NSButton",
"NSCell",
"NSControl",
"NSEvent",
"NSImage",
"NSMenu",
"NSResponder",
"NSStatusBar",
"NSStatusBarButton",
"NSStatusItem",
"NSTrackingArea",
"NSView",
"NSWindow",
] }
core-graphics = "0.23"

[target."cfg(target_os = \"macos\")".dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum Error {
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[error(transparent)]
PngEncodingError(#[from] png::EncodingError),
#[error("not on the main thread")]
NotMainThread,
}

/// Convenient type alias of Result type for tray-icon.
Expand Down
Loading

0 comments on commit d407869

Please sign in to comment.