From cb9004906ceac7f60655a89c7284f63c2c84555a Mon Sep 17 00:00:00 2001 From: Sanpi Date: Tue, 17 Dec 2024 19:58:58 +0100 Subject: [PATCH] Uses todo_txt::Config --- Cargo.toml | 3 ++- src/application/mod.rs | 36 +++++++----------------------------- src/main.rs | 4 +++- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 878d6a3..784a528 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,4 +32,5 @@ features = ["std"] [dependencies.todo-txt] version = "3.1" -features = ["extended"] +path = "../parser" +features = ["config", "extended"] diff --git a/src/application/mod.rs b/src/application/mod.rs index e0ab4dd..fc7e820 100644 --- a/src/application/mod.rs +++ b/src/application/mod.rs @@ -60,6 +60,7 @@ pub enum Msg { pub struct Model { add_popover: gtk::Popover, agenda: relm4::Controller, + config: todo_txt::Config, contexts: relm4::Controller, defered_button: gtk::CheckButton, done_button: gtk::CheckButton, @@ -261,23 +262,7 @@ impl Model { } fn update_tasks(&self) { - let todo_file = match std::env::var("TODO_FILE") { - Ok(todo_file) => todo_file, - Err(err) => { - eprintln!("Launch this program via todo.sh: {err}"); - std::process::exit(1); - } - }; - - let done_file = match std::env::var("DONE_FILE") { - Ok(done_file) => done_file, - Err(err) => { - eprintln!("Launch this program via todo.sh: {err}"); - std::process::exit(1); - } - }; - - let list = crate::tasks::List::from_files(&todo_file, &done_file); + let list = crate::tasks::List::from_files(&self.config.todo_file, &self.config.done_file); globals::tasks::replace(list); globals::preferences::replace(crate::application::Preferences { @@ -301,14 +286,6 @@ impl Model { fn watch(&self, sender: relm4::ComponentSender) { use notify::Watcher as _; - let todo_dir = match std::env::var("TODO_DIR") { - Ok(todo_dir) => todo_dir, - Err(err) => { - eprintln!("Launch this program via todo.sh: {err}"); - std::process::exit(1); - } - }; - let mut watcher = notify::recommended_watcher(move |res| match res { Ok(_) => { sender.input(Msg::Refresh); @@ -318,10 +295,10 @@ impl Model { }) .unwrap(); - log::debug!("watching {todo_dir} for changes"); + log::debug!("watching {} for changes", self.config.todo_file); if let Err(err) = watcher.watch( - std::path::PathBuf::from(todo_dir).as_path(), + std::path::PathBuf::from(self.config.todo_file.clone()).as_path(), notify::RecursiveMode::Recursive, ) { log::warn!("Unable to setup hot reload: {err}"); @@ -331,12 +308,12 @@ impl Model { #[relm4::component(pub)] impl relm4::SimpleComponent for Model { - type Init = (); + type Init = todo_txt::Config; type Input = Msg; type Output = (); fn init( - _init: Self::Init, + init: Self::Init, root: Self::Root, sender: relm4::ComponentSender, ) -> relm4::ComponentParts { @@ -420,6 +397,7 @@ impl relm4::SimpleComponent for Model { let model = Self { add_popover: gtk::Popover::new(), agenda, + config: init, contexts, defered_button, done_button, diff --git a/src/main.rs b/src/main.rs index 9965e3e..ab2b397 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,9 +23,11 @@ fn main() { std::process::exit(0); } + let config = todo_txt::Config::from_env(); + let app = relm4::RelmApp::new("txt.todo.effitask") .with_args(Vec::new()); - app.run::(()); + app.run::(config); } fn usage(program: &str) {