diff --git a/Cargo.lock b/Cargo.lock index b97cf5f91a61..67cb6c859d76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4273,15 +4273,6 @@ dependencies = [ "similar", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "interpolate_name" version = "0.2.4" @@ -8921,9 +8912,8 @@ dependencies = [ [[package]] name = "tao" -version = "0.30.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833b4d43383d76d5078d72f3acd977f47eb5b6751eb40baa665d13828e7b79df" +version = "0.30.8" +source = "git+https://github.com/sgammon/tao.git?rev=11854b206d1eb32aa88d542bb2f8e3f20eebbb4c#11854b206d1eb32aa88d542bb2f8e3f20eebbb4c" dependencies = [ "bitflags 2.6.0", "cocoa 0.26.0", @@ -8936,7 +8926,6 @@ dependencies = [ "gdkwayland-sys", "gdkx11-sys", "gtk", - "instant", "jni", "lazy_static", "libc", @@ -8949,7 +8938,7 @@ dependencies = [ "parking_lot", "raw-window-handle", "scopeguard", - "tao-macros", + "tao-macros 0.1.3 (git+https://github.com/sgammon/tao.git?rev=11854b206d1eb32aa88d542bb2f8e3f20eebbb4c)", "unicode-segmentation", "url", "windows", @@ -8969,6 +8958,16 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "tao-macros" +version = "0.1.3" +source = "git+https://github.com/sgammon/tao.git?rev=11854b206d1eb32aa88d542bb2f8e3f20eebbb4c#11854b206d1eb32aa88d542bb2f8e3f20eebbb4c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "tap" version = "1.0.1" @@ -11310,7 +11309,7 @@ dependencies = [ "raw-window-handle", "sha2", "soup3", - "tao-macros", + "tao-macros 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.68", "tracing", "url", diff --git a/Cargo.toml b/Cargo.toml index 963894b5910b..b8caff7e75fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,3 +70,4 @@ opt-level = "s" [patch.crates-io] schemars_derive = { git = 'https://github.com/tauri-apps/schemars.git', branch = 'feat/preserve-description-newlines' } tauri = { path = "./crates/tauri" } +tao = { git = "https://github.com/sgammon/tao.git", rev = "79cae516189f4a1253ff2956295ec3c9411a4383" } diff --git a/crates/tauri-runtime-wry/Cargo.toml b/crates/tauri-runtime-wry/Cargo.toml index 125b1de598cd..cecaa139e7d4 100644 --- a/crates/tauri-runtime-wry/Cargo.toml +++ b/crates/tauri-runtime-wry/Cargo.toml @@ -23,7 +23,7 @@ wry = { version = "0.47", default-features = false, features = [ "os-webview", "linux-body", ] } -tao = { version = "0.30.6", default-features = false, features = ["rwh_06"] } +tao = { version = "0.30.8", default-features = false, features = ["rwh_06"] } tauri-runtime = { version = "2.2.0", path = "../tauri-runtime" } tauri-utils = { version = "2.1.0", path = "../tauri-utils" } raw-window-handle = "0.6" @@ -64,6 +64,7 @@ jni = "0.21" [features] devtools = ["wry/devtools", "tauri-runtime/devtools"] +push-notifications = ["tao/push-notifications"] macos-private-api = [ "wry/fullscreen", "wry/transparent", diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 12629db18420..ca648ac8eaa1 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -30,6 +30,9 @@ use tauri_runtime::{ UserEvent, WebviewDispatch, WebviewEventId, WindowDispatch, WindowEventId, }; +#[cfg(feature = "push-notifications")] +use tauri_runtime::PushToken; + #[cfg(any(target_os = "macos", target_os = "ios"))] use objc2::rc::Retained; #[cfg(target_os = "macos")] @@ -1351,6 +1354,10 @@ pub enum Message { Box (String, TaoWindowBuilder) + Send>, Sender>>, ), + #[cfg(feature = "push-notifications")] + PushRegistration(PushToken), + #[cfg(feature = "push-notifications")] + PushRegistrationFailed(String), UserEvent(T), } @@ -3551,6 +3558,11 @@ fn handle_user_message( } } + #[cfg(feature = "push-notifications")] + Message::PushRegistration(_) => (), + #[cfg(feature = "push-notifications")] + Message::PushRegistrationFailed(_) => (), + Message::UserEvent(_) => (), Message::EventLoopWindowTarget(message) => match message { EventLoopWindowTargetMessage::CursorPosition(sender) => { @@ -3805,6 +3817,11 @@ fn handle_event_loop( } => callback(RunEvent::Reopen { has_visible_windows, }), + #[cfg(feature = "push-notifications")] + Event::PushRegistration(token) => callback(RunEvent::PushRegistration(token)), + #[cfg(feature = "push-notifications")] + Event::PushRegistrationError(token) => callback(RunEvent::PushRegistrationFailed(token)), + _ => (), } } diff --git a/crates/tauri-runtime/Cargo.toml b/crates/tauri-runtime/Cargo.toml index 6a2110af08a0..14b19f01c079 100644 --- a/crates/tauri-runtime/Cargo.toml +++ b/crates/tauri-runtime/Cargo.toml @@ -51,3 +51,4 @@ url = "2" [features] devtools = [] macos-private-api = [] +push-notifications = [] diff --git a/crates/tauri-runtime/src/lib.rs b/crates/tauri-runtime/src/lib.rs index 1257dab15f86..d4e0d0771d2a 100644 --- a/crates/tauri-runtime/src/lib.rs +++ b/crates/tauri-runtime/src/lib.rs @@ -47,6 +47,7 @@ pub use dpi; pub type WindowEventId = u32; pub type WebviewEventId = u32; +pub type PushToken = Vec; /// A rectangular region. #[derive(Clone, Copy, Debug, Serialize)] @@ -248,6 +249,12 @@ pub enum RunEvent { /// Indicates whether the NSApplication object found any visible windows in your application. has_visible_windows: bool, }, + /// Push token was registered. + #[cfg(feature = "push-notifications")] + PushRegistration(PushToken), + /// Push token failure. + #[cfg(feature = "push-notifications")] + PushRegistrationFailed(String), /// A custom event defined by the user. UserEvent(T), } diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml index 5acb944033e0..ec07d25bfae5 100644 --- a/crates/tauri/Cargo.toml +++ b/crates/tauri/Cargo.toml @@ -169,6 +169,10 @@ tray-icon = ["dep:tray-icon"] tracing = ["dep:tracing", "tauri-macros/tracing", "tauri-runtime-wry/tracing"] test = [] compression = ["tauri-macros/compression", "tauri-utils/compression"] +push-notifications = [ + "tauri-runtime/push-notifications", + "tauri-runtime-wry/push-notifications", +] wry = ["tauri-runtime-wry"] objc-exception = ["tauri-runtime-wry/objc-exception"] linux-libxdo = ["tray-icon/libxdo", "muda/libxdo"] diff --git a/crates/tauri/src/app.rs b/crates/tauri/src/app.rs index 509ba340c8f4..eeec7ff89e7a 100644 --- a/crates/tauri/src/app.rs +++ b/crates/tauri/src/app.rs @@ -69,6 +69,10 @@ pub type OnPageLoad = dyn Fn(&Webview, &PageLoadPayload<'_>) + Send + Sync pub type ChannelInterceptor = Box, CallbackFn, usize, &InvokeResponseBody) -> bool + Send + Sync + 'static>; +/// Push notifications token type. +#[cfg(feature = "push-notifications")] +pub type PushToken = Vec; + /// The exit code on [`RunEvent::ExitRequested`] when [`AppHandle#method.restart`] is called. pub const RESTART_EXIT_CODE: i32 = i32::MAX; @@ -246,6 +250,12 @@ pub enum RunEvent { /// Indicates whether the NSApplication object found any visible windows in your application. has_visible_windows: bool, }, + #[cfg(feature = "push-notifications")] + /// Indicates that a push token has become available. + PushRegistration(PushToken), + #[cfg(feature = "push-notifications")] + /// Indicates that an error occurred while registering for push notification services. + PushRegistrationFailed(String), } impl From for RunEvent { @@ -2201,6 +2211,10 @@ fn on_event_loop_event( } RuntimeRunEvent::Resumed => RunEvent::Resumed, RuntimeRunEvent::MainEventsCleared => RunEvent::MainEventsCleared, + #[cfg(feature = "push-notifications")] + RuntimeRunEvent::PushRegistration(t) => RunEvent::PushRegistration(t), + #[cfg(feature = "push-notifications")] + RuntimeRunEvent::PushRegistrationFailed(err) => RunEvent::PushRegistrationFailed(err), RuntimeRunEvent::UserEvent(t) => { match t { #[cfg(desktop)] diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs index e37df1624d07..5df69537e562 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -37,6 +37,7 @@ //! - **image-png**: Adds support to parse `.png` image, see [`Image`]. //! - **macos-proxy**: Adds support for [`WebviewBuilder::proxy_url`] on macOS. Requires macOS 14+. //! - **specta**: Add support for [`specta::specta`](https://docs.rs/specta/%5E2.0.0-rc.9/specta/attr.specta.html) with Tauri arguments such as [`State`](crate::State), [`Window`](crate::Window) and [`AppHandle`](crate::AppHandle) +//! - **push-notifications**: Add support for [Apple APNS](https://developer.apple.com/notifications/), [Windows WNS](https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/notifications/push-notifications/), and similar systems //! //! ## Cargo allowlist features //! @@ -79,6 +80,9 @@ pub use tauri_macros::{command, generate_handler}; use tauri_utils::assets::AssetsIter; pub use url::Url; +#[cfg(feature = "push-notifications")] +pub use app::PushToken; + pub(crate) mod app; pub mod async_runtime; mod error;