Log loading
This commit is contained in:
parent
239484c3bc
commit
99af3eb2b8
4 changed files with 39 additions and 8 deletions
38
src/main.rs
38
src/main.rs
|
@ -1,11 +1,11 @@
|
|||
// Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::{error::Error, sync::{Arc, Mutex}};
|
||||
use std::{error::Error, rc::Rc, sync::{Arc, Mutex}};
|
||||
|
||||
use aliveline::{config::Config, load_config, log::{Event, Log}};
|
||||
use chrono::{Datelike, Timelike};
|
||||
use slint::{Model, SharedString, ToSharedString, VecModel};
|
||||
use slint::{Model, ModelRc, SharedString, ToSharedString, VecModel};
|
||||
use toml::value::{Date as TomlDate, Time};
|
||||
|
||||
slint::include_modules!();
|
||||
|
@ -26,10 +26,11 @@ impl From<TimelineEvent> for Event {
|
|||
second: (event.start % 60) as u8,
|
||||
nanosecond: 0
|
||||
};
|
||||
let endsecs = event.start + event.duration;
|
||||
let end = Time {
|
||||
hour: start.hour + (event.duration / 3600) as u8,
|
||||
minute: start.minute + ((event.duration % 3600) / 60) as u8,
|
||||
second: start.second + (event.duration % 60) as u8,
|
||||
hour: (endsecs / 3600) as u8,
|
||||
minute: ((endsecs % 3600) / 60) as u8,
|
||||
second: (endsecs % 60) as u8,
|
||||
nanosecond: 0
|
||||
};
|
||||
Event { start, end, name: event.label.to_string(), finished: event.finished }
|
||||
|
@ -47,7 +48,26 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let config: Arc<Config> = Arc::new(load_config());
|
||||
let writing_log: Arc<Mutex<Log>> = Arc::new(Mutex::new(Log::load_from(&config, date)));
|
||||
|
||||
{
|
||||
println!("Log: {:?}", writing_log.lock().unwrap().events);
|
||||
let ui_weak = ui.as_weak();
|
||||
let log = writing_log.clone();
|
||||
(move || {
|
||||
println!("c");
|
||||
let ui = ui_weak.unwrap();
|
||||
let log_guard = log.lock().expect("Log shouldn't be used twice");
|
||||
let events: Vec<TimelineEvent> = (*log_guard).events.iter().map(|event| TimelineEvent::from((*event).clone())).collect();
|
||||
let in_progress = events.iter().any(|event| !event.finished);
|
||||
let model: ModelRc<TimelineEvent> = Rc::new(VecModel::from(events)).into();
|
||||
println!("get: {:?}", model);
|
||||
ui.set_record_events(model);
|
||||
ui.set_in_progress(in_progress);
|
||||
})()
|
||||
}
|
||||
|
||||
ui.invoke_update_record_offset(offset as i32);
|
||||
ui.invoke_load_log();
|
||||
ui.invoke_another_call();
|
||||
|
||||
ui.on_save_log({
|
||||
let config = config.clone();
|
||||
|
@ -60,6 +80,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
});
|
||||
|
||||
ui.on_another_call({
|
||||
println!("outside move");
|
||||
move || {
|
||||
println!("inside move");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ui.on_update_record_visible_time({
|
||||
let ui_weak = ui.as_weak();
|
||||
move |hours_string: SharedString| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue