-
Notifications
You must be signed in to change notification settings - Fork 415
Different way of notif #1408
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
Different way of notif #1408
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "notification-interface" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| serde = { workspace = true, features = ["derive"] } | ||
| specta = { workspace = true, features = ["derive"] } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #[derive(Debug, serde::Serialize, serde::Deserialize, specta::Type)] | ||
| pub struct Notification { | ||
| pub title: String, | ||
| pub message: String, | ||
| pub url: Option<String>, | ||
| pub timeout: Option<std::time::Duration>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Represent duration with a primitive (e.g., milliseconds as u64) to avoid interop ambiguity when exporting to TS/JSON via specta. Prompt for AI agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "notification-macos" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [build-dependencies] | ||
| swift-rs = { workspace = true, features = ["build"] } | ||
|
|
||
| [dependencies] | ||
| hypr-notification-interface = { workspace = true } | ||
| swift-rs = { workspace = true } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| fn main() { | ||
| #[cfg(target_os = "macos")] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using #[cfg(target_os = "macos")] in a build.rs checks the host OS, not the Cargo target; this can misbehave during cross-compilation. Prefer branching on CARGO_CFG_TARGET_OS to make the build script target-aware. Prompt for AI agents |
||
| { | ||
| swift_rs::SwiftLinker::new("14.2") | ||
| .with_package("swift-lib", "./swift-lib/") | ||
| .link(); | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "macos"))] | ||
| { | ||
| println!("cargo:warning=Swift linking is only available on macOS"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| use notification_macos::*; | ||
| use std::time::Duration; | ||
|
|
||
| #[cfg(target_os = "macos")] | ||
| #[link(name = "AppKit", kind = "framework")] | ||
| #[link(name = "Foundation", kind = "framework")] | ||
| extern "C" { | ||
| fn NSApplicationLoad() -> bool; | ||
| fn CFRunLoopRun(); | ||
| fn CFRunLoopStop(rl: *const std::ffi::c_void); | ||
| fn CFRunLoopGetMain() -> *const std::ffi::c_void; | ||
| } | ||
|
|
||
| fn main() { | ||
| #[cfg(target_os = "macos")] | ||
| { | ||
| unsafe { | ||
| NSApplicationLoad(); | ||
| } | ||
|
|
||
| std::thread::spawn(|| { | ||
| std::thread::sleep(Duration::from_millis(100)); | ||
|
|
||
| let notification = Notification { | ||
| title: "Test Notification".to_string(), | ||
| message: "This is a test message from Rust".to_string(), | ||
| url: Some("https://example.com".to_string()), | ||
| timeout: Some(Duration::from_secs(3)), | ||
| }; | ||
|
|
||
| show(¬ification); | ||
|
|
||
| std::thread::sleep(Duration::from_secs(5)); | ||
| unsafe { | ||
| let main_loop = CFRunLoopGetMain(); | ||
| CFRunLoopStop(main_loop); | ||
| } | ||
| }); | ||
|
|
||
| unsafe { | ||
| CFRunLoopRun(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| pub use hypr_notification_interface::*; | ||
|
|
||
| #[cfg(target_os = "macos")] | ||
| use swift_rs::{swift, Bool, SRString}; | ||
|
|
||
| #[cfg(target_os = "macos")] | ||
| swift!(fn _show_notification( | ||
| title: &SRString, | ||
| message: &SRString, | ||
| url: &SRString, | ||
| has_url: Bool, | ||
| timeout_seconds: f64 | ||
| ) -> Bool); | ||
|
|
||
| #[cfg(target_os = "macos")] | ||
| pub fn show(notification: &hypr_notification_interface::Notification) { | ||
| unsafe { | ||
| let title = SRString::from(notification.title.as_str()); | ||
| let message = SRString::from(notification.message.as_str()); | ||
| let url = notification | ||
| .url | ||
| .as_ref() | ||
| .map(|u| SRString::from(u.as_str())) | ||
| .unwrap_or_else(|| SRString::from("")); | ||
| let has_url = notification.url.is_some(); | ||
| let timeout_seconds = notification.timeout.map(|d| d.as_secs_f64()).unwrap_or(5.0); | ||
|
|
||
| _show_notification(&title, &message, &url, has_url, timeout_seconds); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_notification() { | ||
| let notification = hypr_notification_interface::Notification { | ||
| title: "Test Title".to_string(), | ||
| message: "Test message content".to_string(), | ||
| url: Some("https://example.com".to_string()), | ||
| timeout: Some(std::time::Duration::from_secs(3)), | ||
| }; | ||
|
|
||
| show(¬ification); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .DS_Store | ||
| /.build | ||
| /Packages | ||
| /*.xcodeproj | ||
| xcuserdata/ | ||
| DerivedData/ | ||
| .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // swift-tools-version:5.9 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "swift-lib", | ||
| platforms: [.macOS("14.2")], | ||
| products: [ | ||
| .library( | ||
| name: "swift-lib", | ||
| type: .static, | ||
| targets: ["swift-lib"]) | ||
| ], | ||
| dependencies: [ | ||
| .package( | ||
| url: "https://github.com/Brendonovich/swift-rs", | ||
| revision: "01980f981bc642a6da382cc0788f18fdd4cde6df") | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "swift-lib", | ||
| dependencies: [ | ||
| .product(name: "SwiftRs", package: "swift-rs") | ||
| ], | ||
| path: "src" | ||
| ) | ||
| ] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a typed URL (e.g., url::Url) instead of String to validate and prevent malformed URLs in the public interface.
Prompt for AI agents