11use crate :: models:: { format_time, format_time_i64, get_current_timestamp, Force } ;
22use dioxus:: prelude:: * ;
3- #[ cfg( target_arch = "wasm32" ) ]
43use dioxus_i18n:: t;
54/// Timer tick interval in milliseconds
65#[ cfg( target_arch = "wasm32" ) ]
@@ -234,6 +233,25 @@ pub(super) fn RestTimerDisplay(
234233 schedule_notification_at ( title, body, "logout-rest" , target_unix_ms) ;
235234 }
236235 }
236+ // On native (Android), schedule a precise one-shot notification via tokio.
237+ #[ cfg( not( target_arch = "wasm32" ) ) ]
238+ if let Some ( start) = start_time {
239+ if rest_duration > 0 {
240+ let title = t ! ( "notif-rest-title" ) . to_string ( ) ;
241+ let body = t ! ( "notif-rest-body" ) . to_string ( ) ;
242+ let fire_at_secs = start + rest_duration;
243+ tokio:: spawn ( async move {
244+ let now = crate :: models:: get_current_timestamp ( ) ;
245+ if fire_at_secs > now {
246+ let delay = std:: time:: Duration :: from_secs ( fire_at_secs - now) ;
247+ tokio:: time:: sleep ( delay) . await ;
248+ }
249+ crate :: services:: android_notifications:: send_notification (
250+ & title, & body, "logout-rest" ,
251+ ) ;
252+ } ) ;
253+ }
254+ }
237255 }
238256 let Some ( start) = start_time else {
239257 return rsx ! {
@@ -255,6 +273,12 @@ pub(super) fn RestTimerDisplay(
255273 & t ! ( "notif-rest-body" ) ,
256274 "logout-rest" ,
257275 ) ;
276+ #[ cfg( not( target_arch = "wasm32" ) ) ]
277+ crate :: services:: android_notifications:: send_notification (
278+ & t ! ( "notif-rest-title" ) ,
279+ & t ! ( "notif-rest-body" ) ,
280+ "logout-rest" ,
281+ ) ;
258282 }
259283 }
260284 let remaining = rd. cast_signed ( ) - elapsed. cast_signed ( ) ;
@@ -295,6 +319,27 @@ pub(super) fn ExerciseElapsedTimer(
295319 }
296320 }
297321 }
322+ // On native (Android), schedule a precise one-shot notification via tokio.
323+ #[ cfg( not( target_arch = "wasm32" ) ) ]
324+ if !* duration_bell_rung. read ( ) {
325+ if let ( Some ( start) , Some ( dur) ) = ( exercise_start, last_duration) {
326+ if dur > 0 {
327+ let title = t ! ( "notif-duration-title" ) . to_string ( ) ;
328+ let body = t ! ( "notif-duration-body" ) . to_string ( ) ;
329+ let fire_at_secs = start + dur;
330+ tokio:: spawn ( async move {
331+ let now = crate :: models:: get_current_timestamp ( ) ;
332+ if fire_at_secs > now {
333+ let delay = std:: time:: Duration :: from_secs ( fire_at_secs - now) ;
334+ tokio:: time:: sleep ( delay) . await ;
335+ }
336+ crate :: services:: android_notifications:: send_notification (
337+ & title, & body, "logout-duration" ,
338+ ) ;
339+ } ) ;
340+ }
341+ }
342+ }
298343 } ) ;
299344 let mut now_tick = use_signal ( get_current_timestamp) ;
300345 use_coroutine ( move |_: UnboundedReceiver < ( ) > | async move {
@@ -323,6 +368,12 @@ pub(super) fn ExerciseElapsedTimer(
323368 & t ! ( "notif-duration-body" ) ,
324369 "logout-duration" ,
325370 ) ;
371+ #[ cfg( not( target_arch = "wasm32" ) ) ]
372+ crate :: services:: android_notifications:: send_notification (
373+ & t ! ( "notif-duration-title" ) ,
374+ & t ! ( "notif-duration-body" ) ,
375+ "logout-duration" ,
376+ ) ;
326377 }
327378 }
328379 }
@@ -362,6 +413,27 @@ pub(super) fn InlineExerciseTimer(
362413 }
363414 }
364415 }
416+ // On native (Android), schedule a precise one-shot notification via tokio.
417+ #[ cfg( not( target_arch = "wasm32" ) ) ]
418+ if !* duration_bell_rung. read ( ) {
419+ if let ( Some ( start) , Some ( dur) ) = ( exercise_start, last_duration) {
420+ if dur > 0 {
421+ let title = t ! ( "notif-duration-title" ) . to_string ( ) ;
422+ let body = t ! ( "notif-duration-body" ) . to_string ( ) ;
423+ let fire_at_secs = start + dur;
424+ tokio:: spawn ( async move {
425+ let now = crate :: models:: get_current_timestamp ( ) ;
426+ if fire_at_secs > now {
427+ let delay = std:: time:: Duration :: from_secs ( fire_at_secs - now) ;
428+ tokio:: time:: sleep ( delay) . await ;
429+ }
430+ crate :: services:: android_notifications:: send_notification (
431+ & title, & body, "logout-duration" ,
432+ ) ;
433+ } ) ;
434+ }
435+ }
436+ }
365437 } ) ;
366438 let mut now_tick = use_signal ( get_current_timestamp) ;
367439 use_coroutine ( move |_: UnboundedReceiver < ( ) > | async move {
@@ -390,6 +462,12 @@ pub(super) fn InlineExerciseTimer(
390462 & t ! ( "notif-duration-body" ) ,
391463 "logout-duration" ,
392464 ) ;
465+ #[ cfg( not( target_arch = "wasm32" ) ) ]
466+ crate :: services:: android_notifications:: send_notification (
467+ & t ! ( "notif-duration-title" ) ,
468+ & t ! ( "notif-duration-body" ) ,
469+ "logout-duration" ,
470+ ) ;
393471 }
394472 }
395473 }
0 commit comments