feat(event) persist state (#129)
* feat(event) persist state * `Event::default()`
This commit is contained in:
parent
d2f41e04e2
commit
e11dcaa913
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -642,6 +642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071"
|
checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"powerfmt",
|
"powerfmt",
|
||||||
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@ -35,7 +35,7 @@ tracing = "0.1.41"
|
|||||||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
||||||
directories = "5.0.1"
|
directories = "5.0.1"
|
||||||
clap = { version = "4.5.48", features = ["derive"] }
|
clap = { version = "4.5.48", features = ["derive"] }
|
||||||
time = { version = "0.3.44", features = ["formatting", "local-offset", "parsing", "macros"] }
|
time = { version = "0.3.44", features = ["formatting", "local-offset", "parsing", "macros", "serde"] }
|
||||||
notify-rust = "4.11.7"
|
notify-rust = "4.11.7"
|
||||||
rodio = { version = "0.20.1", features = [
|
rodio = { version = "0.20.1", features = [
|
||||||
"symphonia-mp3",
|
"symphonia-mp3",
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use crate::{
|
|||||||
args::Args,
|
args::Args,
|
||||||
common::{AppEditMode, AppTime, AppTimeFormat, ClockTypeId, Content, Style, Toggle},
|
common::{AppEditMode, AppTime, AppTimeFormat, ClockTypeId, Content, Style, Toggle},
|
||||||
constants::TICK_VALUE_MS,
|
constants::TICK_VALUE_MS,
|
||||||
event::{Event, get_default_event},
|
event::Event,
|
||||||
events::{self, TuiEventHandler},
|
events::{self, TuiEventHandler},
|
||||||
storage::AppStorage,
|
storage::AppStorage,
|
||||||
terminal::Terminal,
|
terminal::Terminal,
|
||||||
@ -135,7 +135,7 @@ impl From<FromAppArgs> for App {
|
|||||||
None => stg.elapsed_value_countdown,
|
None => stg.elapsed_value_countdown,
|
||||||
},
|
},
|
||||||
current_value_timer: stg.current_value_timer,
|
current_value_timer: stg.current_value_timer,
|
||||||
event: args.event.unwrap_or_else(get_default_event),
|
event: args.event.unwrap_or(stg.event),
|
||||||
app_tx,
|
app_tx,
|
||||||
#[cfg(feature = "sound")]
|
#[cfg(feature = "sound")]
|
||||||
sound_path: args.sound,
|
sound_path: args.sound,
|
||||||
@ -470,6 +470,7 @@ impl App {
|
|||||||
),
|
),
|
||||||
elapsed_value_countdown: Duration::from(*self.countdown.get_elapsed_value()),
|
elapsed_value_countdown: Duration::from(*self.countdown.get_elapsed_value()),
|
||||||
current_value_timer: Duration::from(*self.timer.get_clock().get_current_value()),
|
current_value_timer: Duration::from(*self.timer.get_clock().get_current_value()),
|
||||||
|
event: self.event.get_event(),
|
||||||
footer_app_time: self.footer.app_time_format().is_some().into(),
|
footer_app_time: self.footer.app_time_format().is_some().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/event.rs
19
src/event.rs
@ -1,21 +1,20 @@
|
|||||||
use time::macros::format_description;
|
use serde::{Deserialize, Serialize};
|
||||||
|
use time::macros::{datetime, format_description};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
pub date_time: time::PrimitiveDateTime,
|
pub date_time: time::PrimitiveDateTime,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_default_event() -> Event {
|
impl Default for Event {
|
||||||
Event {
|
fn default() -> Self {
|
||||||
date_time: time::PrimitiveDateTime::parse(
|
Self {
|
||||||
// Mario Bros. "...entered mass production in Japan on June 21" 1983
|
// Mario Bros. "...entered mass production in Japan on June 21" 1983
|
||||||
// https://en.wikipedia.org/wiki/Mario_Bros.#Release
|
// https://en.wikipedia.org/wiki/Mario_Bros.#Release
|
||||||
"1983-06-21 00:00",
|
date_time: datetime!(1983-06-21 00:00),
|
||||||
format_description!("[year]-[month]-[day] [hour]:[minute]"),
|
title: Some("Release date of Mario Bros. in Japan".into()),
|
||||||
)
|
}
|
||||||
.unwrap(),
|
|
||||||
title: Some("Release date of Mario Bros. in Japan".into()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
common::{AppTimeFormat, Content, Style, Toggle},
|
common::{AppTimeFormat, Content, Style, Toggle},
|
||||||
|
event::Event,
|
||||||
widgets::pomodoro::Mode as PomodoroMode,
|
widgets::pomodoro::Mode as PomodoroMode,
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
@ -44,6 +45,8 @@ pub struct AppStorage {
|
|||||||
pub elapsed_value_countdown: Duration,
|
pub elapsed_value_countdown: Duration,
|
||||||
// timer
|
// timer
|
||||||
pub current_value_timer: Duration,
|
pub current_value_timer: Duration,
|
||||||
|
// event
|
||||||
|
pub event: Event,
|
||||||
// footer
|
// footer
|
||||||
pub footer_app_time: Toggle,
|
pub footer_app_time: Toggle,
|
||||||
}
|
}
|
||||||
@ -75,6 +78,8 @@ impl Default for AppStorage {
|
|||||||
elapsed_value_countdown: Duration::ZERO,
|
elapsed_value_countdown: Duration::ZERO,
|
||||||
// timer
|
// timer
|
||||||
current_value_timer: Duration::ZERO,
|
current_value_timer: Duration::ZERO,
|
||||||
|
// event
|
||||||
|
event: Event::default(),
|
||||||
// footer
|
// footer
|
||||||
footer_app_time: Toggle::Off,
|
footer_app_time: Toggle::Off,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -203,7 +203,7 @@ fn test_format_by_duration_boundaries() {
|
|||||||
Format::YyyDddHhMmSs
|
Format::YyyDddHhMmSs
|
||||||
);
|
);
|
||||||
|
|
||||||
// YyyDdHhMmSs
|
// YyyyDdHhMmSs
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format_by_duration::<DurationEx>(&(1000 * ONE_YEAR + 10 * ONE_DAY).into()),
|
format_by_duration::<DurationEx>(&(1000 * ONE_YEAR + 10 * ONE_DAY).into()),
|
||||||
Format::YyyyDdHhMmSs
|
Format::YyyyDdHhMmSs
|
||||||
|
|||||||
@ -73,6 +73,13 @@ impl EventState {
|
|||||||
self.with_decis = with_decis;
|
self.with_decis = with_decis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_event(&self) -> Event {
|
||||||
|
Event {
|
||||||
|
title: self.title.clone(),
|
||||||
|
date_time: time::PrimitiveDateTime::new(self.event_time.date(), self.event_time.time()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_percentage_done(&self) -> u16 {
|
pub fn get_percentage_done(&self) -> u16 {
|
||||||
get_percentage(self.start_time, self.event_time, self.app_time)
|
get_percentage(self.start_time, self.event_time, self.app_time)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user