Skip to content

Commit

Permalink
Rewrite to use objc2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
madsmtm committed Jun 26, 2024
1 parent 9231438 commit ee45451
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 295 deletions.
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 ee45451

Please sign in to comment.