feat(event) desktop notification at event time (#124)
This commit is contained in:
parent
6b6221803c
commit
758a72fbf6
@ -213,7 +213,7 @@ impl App {
|
|||||||
event: EventState::new(EventStateArgs {
|
event: EventState::new(EventStateArgs {
|
||||||
app_time,
|
app_time,
|
||||||
event_time: time::PrimitiveDateTime::parse(
|
event_time: time::PrimitiveDateTime::parse(
|
||||||
"2025-10-09 21:32:30",
|
"2025-10-10 10:30:30",
|
||||||
format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"),
|
format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
|||||||
@ -25,6 +25,7 @@ pub enum Content {
|
|||||||
pub enum ClockTypeId {
|
pub enum ClockTypeId {
|
||||||
Countdown,
|
Countdown,
|
||||||
Timer,
|
Timer,
|
||||||
|
Event,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, ValueEnum, Default, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, ValueEnum, Default, Serialize, Deserialize)]
|
||||||
|
|||||||
@ -7,9 +7,9 @@ use ratatui::{
|
|||||||
use time::{OffsetDateTime, macros::format_description};
|
use time::{OffsetDateTime, macros::format_description};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{AppTime, Style},
|
common::{AppTime, ClockTypeId, Style},
|
||||||
duration::CalendarDuration,
|
duration::CalendarDuration,
|
||||||
events::{AppEventTx, TuiEvent, TuiEventHandler},
|
events::{AppEvent, AppEventTx, TuiEvent, TuiEventHandler},
|
||||||
utils::center,
|
utils::center,
|
||||||
widgets::{clock, clock_elements::DIGIT_HEIGHT},
|
widgets::{clock, clock_elements::DIGIT_HEIGHT},
|
||||||
};
|
};
|
||||||
@ -25,6 +25,7 @@ pub struct EventState {
|
|||||||
/// counter to simulate `DONE` state
|
/// counter to simulate `DONE` state
|
||||||
/// Default value: `None`
|
/// Default value: `None`
|
||||||
done_count: Option<u64>,
|
done_count: Option<u64>,
|
||||||
|
app_tx: AppEventTx,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventStateArgs {
|
pub struct EventStateArgs {
|
||||||
@ -45,8 +46,6 @@ impl EventState {
|
|||||||
app_tx,
|
app_tx,
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
// TODO: Handle app Events
|
|
||||||
let _ = app_tx;
|
|
||||||
let app_datetime = OffsetDateTime::from(app_time);
|
let app_datetime = OffsetDateTime::from(app_time);
|
||||||
// assume event has as same `offset` as `app_time`
|
// assume event has as same `offset` as `app_time`
|
||||||
let event_offset = event_time.assume_offset(app_datetime.offset());
|
let event_offset = event_time.assume_offset(app_datetime.offset());
|
||||||
@ -58,6 +57,7 @@ impl EventState {
|
|||||||
start_time: app_datetime,
|
start_time: app_datetime,
|
||||||
with_decis,
|
with_decis,
|
||||||
done_count: None,
|
done_count: None,
|
||||||
|
app_tx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +91,10 @@ impl EventState {
|
|||||||
if duration < Duration::from_millis(100) {
|
if duration < Duration::from_millis(100) {
|
||||||
// reset `done_count`
|
// reset `done_count`
|
||||||
self.done_count = Some(clock::MAX_DONE_COUNT);
|
self.done_count = Some(clock::MAX_DONE_COUNT);
|
||||||
|
// send notification
|
||||||
|
_ = self
|
||||||
|
.app_tx
|
||||||
|
.send(AppEvent::ClockDone(ClockTypeId::Event, self.title.clone()));
|
||||||
}
|
}
|
||||||
// count (possible) `done`
|
// count (possible) `done`
|
||||||
self.done_count = clock::count_clock_done(self.done_count);
|
self.done_count = clock::count_clock_done(self.done_count);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user