Log loading
This commit is contained in:
parent
239484c3bc
commit
99af3eb2b8
4 changed files with 39 additions and 8 deletions
|
@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use toml::value::{Date, Time};
|
use toml::value::{Date, Time};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Log {
|
pub struct Log {
|
||||||
pub date: Date,
|
pub date: Date,
|
||||||
pub events: Vec<Event>
|
pub events: Vec<Event>
|
||||||
|
@ -64,7 +64,7 @@ impl Log {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub start: Time,
|
pub start: Time,
|
||||||
|
|
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.
|
// 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")]
|
#![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 aliveline::{config::Config, load_config, log::{Event, Log}};
|
||||||
use chrono::{Datelike, Timelike};
|
use chrono::{Datelike, Timelike};
|
||||||
use slint::{Model, SharedString, ToSharedString, VecModel};
|
use slint::{Model, ModelRc, SharedString, ToSharedString, VecModel};
|
||||||
use toml::value::{Date as TomlDate, Time};
|
use toml::value::{Date as TomlDate, Time};
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
@ -26,10 +26,11 @@ impl From<TimelineEvent> for Event {
|
||||||
second: (event.start % 60) as u8,
|
second: (event.start % 60) as u8,
|
||||||
nanosecond: 0
|
nanosecond: 0
|
||||||
};
|
};
|
||||||
|
let endsecs = event.start + event.duration;
|
||||||
let end = Time {
|
let end = Time {
|
||||||
hour: start.hour + (event.duration / 3600) as u8,
|
hour: (endsecs / 3600) as u8,
|
||||||
minute: start.minute + ((event.duration % 3600) / 60) as u8,
|
minute: ((endsecs % 3600) / 60) as u8,
|
||||||
second: start.second + (event.duration % 60) as u8,
|
second: (endsecs % 60) as u8,
|
||||||
nanosecond: 0
|
nanosecond: 0
|
||||||
};
|
};
|
||||||
Event { start, end, name: event.label.to_string(), finished: event.finished }
|
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 config: Arc<Config> = Arc::new(load_config());
|
||||||
let writing_log: Arc<Mutex<Log>> = Arc::new(Mutex::new(Log::load_from(&config, date)));
|
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_update_record_offset(offset as i32);
|
||||||
|
ui.invoke_load_log();
|
||||||
|
ui.invoke_another_call();
|
||||||
|
|
||||||
ui.on_save_log({
|
ui.on_save_log({
|
||||||
let config = config.clone();
|
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({
|
ui.on_update_record_visible_time({
|
||||||
let ui_weak = ui.as_weak();
|
let ui_weak = ui.as_weak();
|
||||||
move |hours_string: SharedString| {
|
move |hours_string: SharedString| {
|
||||||
|
|
|
@ -10,6 +10,8 @@ export component AppWindow inherits Window {
|
||||||
callback chain-event <=> record.chain-event;
|
callback chain-event <=> record.chain-event;
|
||||||
callback update-record-offset(int);
|
callback update-record-offset(int);
|
||||||
callback save-log;
|
callback save-log;
|
||||||
|
callback another-call;
|
||||||
|
callback load-log;
|
||||||
|
|
||||||
update-record-offset(new-offset) => {
|
update-record-offset(new-offset) => {
|
||||||
record.offset = new-offset;
|
record.offset = new-offset;
|
||||||
|
@ -18,6 +20,7 @@ export component AppWindow inherits Window {
|
||||||
in-out property record-events <=> record.events;
|
in-out property record-events <=> record.events;
|
||||||
in-out property record-offset <=> record.offset;
|
in-out property record-offset <=> record.offset;
|
||||||
in-out property<int> record-visible-time <=> record.visible-time;
|
in-out property<int> record-visible-time <=> record.visible-time;
|
||||||
|
in-out property<bool> in-progress <=> record.in-progress;
|
||||||
property<[string]> combo-spans: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
|
property<[string]> combo-spans: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
|
||||||
|
|
||||||
title: "Aliveline";
|
title: "Aliveline";
|
||||||
|
|
|
@ -11,7 +11,7 @@ export component RecordWidget inherits VerticalBox {
|
||||||
in-out property offset <=> tl.offset;
|
in-out property offset <=> tl.offset;
|
||||||
in-out property events <=> tl.events;
|
in-out property events <=> tl.events;
|
||||||
in property<[string]> combo-spans: [];
|
in property<[string]> combo-spans: [];
|
||||||
property<bool> in-progress: false;
|
in-out property<bool> in-progress: false;
|
||||||
property<string> event-name <=> le.text;
|
property<string> event-name <=> le.text;
|
||||||
|
|
||||||
tl := Timeline {
|
tl := Timeline {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue