@@ -73,6 +73,28 @@ impl Notification {
7373 }
7474
7575 /// Shows the notification.
76+ ///
77+ /// # Examples
78+ ///
79+ /// ```no_run
80+ /// use tauri::api::notification::Notification;
81+ ///
82+ /// // on an actual app, remove the string argument
83+ /// let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
84+ /// Notification::new(&context.config().tauri.bundle.identifier)
85+ /// .title("Tauri")
86+ /// .body("Tauri is awesome!")
87+ /// .show()
88+ /// .unwrap();
89+ /// ```
90+ ///
91+ /// ## Platform-specific
92+ ///
93+ /// - **Windows**: Not supported on Windows 7. If your app targets it, enable the `windows7-compat` feature and use [`Self::notify`].
94+ #[ cfg_attr(
95+ all( not( doc_cfg) , feature = "windows7-compat" ) ,
96+ deprecated = "This function does not work on Windows 7. Use `Self::notify` instead."
97+ ) ]
7698 pub fn show ( self ) -> crate :: api:: Result < ( ) > {
7799 let mut notification = notify_rust:: Notification :: new ( ) ;
78100 if let Some ( body) = self . body {
@@ -108,7 +130,76 @@ impl Notification {
108130 }
109131
110132 crate :: async_runtime:: spawn ( async move {
111- notification. show ( ) . expect ( "failed to show notification" ) ;
133+ let _ = notification. show ( ) ;
134+ } ) ;
135+
136+ Ok ( ( ) )
137+ }
138+
139+ /// Shows the notification. This API is similar to [`Self::show`], but it also works on Windows 7.
140+ ///
141+ /// # Examples
142+ ///
143+ /// ```no_run
144+ /// use tauri::api::notification::Notification;
145+ ///
146+ /// // on an actual app, remove the string argument
147+ /// let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
148+ /// let identifier = context.config().tauri.bundle.identifier.clone();
149+ ///
150+ /// tauri::Builder::default()
151+ /// .setup(move |app| {
152+ /// Notification::new(&identifier)
153+ /// .title("Tauri")
154+ /// .body("Tauri is awesome!")
155+ /// .notify(&app.handle())
156+ /// .unwrap();
157+ /// Ok(())
158+ /// })
159+ /// .run(context)
160+ /// .expect("error while running tauri application");
161+ /// ```
162+ #[ cfg( feature = "windows7-compat" ) ]
163+ #[ cfg_attr( doc_cfg, doc( cfg( feature = "windows7-compat" ) ) ) ]
164+ #[ allow( unused_variables) ]
165+ pub fn notify < R : crate :: Runtime > ( self , app : & crate :: AppHandle < R > ) -> crate :: api:: Result < ( ) > {
166+ #[ cfg( windows) ]
167+ {
168+ if crate :: utils:: platform:: is_windows_7 ( ) {
169+ self . notify_win7 ( app)
170+ } else {
171+ #[ allow( deprecated) ]
172+ self . show ( )
173+ }
174+ }
175+ #[ cfg( not( windows) ) ]
176+ {
177+ #[ allow( deprecated) ]
178+ self . show ( )
179+ }
180+ }
181+
182+ #[ cfg( all( windows, feature = "windows7-compat" ) ) ]
183+ fn notify_win7 < R : crate :: Runtime > ( self , app : & crate :: AppHandle < R > ) -> crate :: api:: Result < ( ) > {
184+ let app = app. clone ( ) ;
185+ let default_window_icon = app. manager . inner . default_window_icon . clone ( ) ;
186+ let _ = app. run_on_main_thread ( move || {
187+ let mut notification = win7_notifications:: Notification :: new ( ) ;
188+ if let Some ( body) = self . body {
189+ notification. body ( & body) ;
190+ }
191+ if let Some ( title) = self . title {
192+ notification. summary ( & title) ;
193+ }
194+ if let Some ( crate :: Icon :: Rgba {
195+ rgba,
196+ width,
197+ height,
198+ } ) = default_window_icon
199+ {
200+ notification. icon ( rgba, width, height) ;
201+ }
202+ let _ = notification. show ( ) ;
112203 } ) ;
113204
114205 Ok ( ( ) )
0 commit comments