Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite to use objc2 #172

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading