From 821ada0b8c3ffef3d4286f3c4fc15871ff9b5f65 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 3 Jun 2026 18:26:23 +0200 Subject: pkgs/tskm: Update `taskchampion` to 3.x --- pkgs/by-name/ts/tskm/src/task/mod.rs | 60 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'pkgs/by-name/ts/tskm/src/task') diff --git a/pkgs/by-name/ts/tskm/src/task/mod.rs b/pkgs/by-name/ts/tskm/src/task/mod.rs index 5e223e33..1362615d 100644 --- a/pkgs/by-name/ts/tskm/src/task/mod.rs +++ b/pkgs/by-name/ts/tskm/src/task/mod.rs @@ -10,14 +10,14 @@ use std::{ fmt::Display, - fs::{self, File, read_to_string}, + fs::{self, read_to_string, File}, path::PathBuf, process::Command, str::FromStr, sync::OnceLock, }; -use anyhow::{Context, Result, bail}; +use anyhow::{bail, Context, Result}; use log::{debug, info, trace}; use taskchampion::Tag; @@ -45,18 +45,20 @@ impl From<&taskchampion::TaskData> for Task { } impl Task { - pub fn from_working_set(id: usize, state: &mut State) -> Result> { + pub async fn from_working_set(id: usize, state: &mut State) -> Result> { Ok(state .replica() - .working_set()? + .working_set() + .await? .by_index(id) .map(|uuid| Self { uuid })) } - pub fn get_current(state: &mut State) -> Result> { + pub async fn get_current(state: &mut State) -> Result> { let tasks = state .replica() - .pending_tasks()? + .pending_tasks() + .await? .into_iter() .filter(taskchampion::Task::is_active) .collect::>(); @@ -76,62 +78,65 @@ impl Task { pub fn uuid(&self) -> &taskchampion::Uuid { &self.uuid } - pub fn working_set_id(&self, state: &mut State) -> Result { + pub async fn working_set_id(&self, state: &mut State) -> Result { Ok(state .replica() - .working_set()? + .working_set() + .await? .by_uuid(self.uuid) .expect("The task should be in the working set")) } - fn as_task(&self, state: &mut State) -> Result { + async fn as_task(&self, state: &mut State) -> Result { Ok(state .replica() - .get_task(self.uuid)? + .get_task(self.uuid) + .await? .expect("We have the task from this replica, it should still be in it")) } /// Adds a tag to the task, to show the user that it has additional neorg data. - pub fn mark_neorg_data(&self, state: &mut State) -> Result<()> { + pub async fn mark_neorg_data(&self, state: &mut State) -> Result<()> { let mut ops = vec![]; - self.as_task(state)? + self.as_task(state) + .await? .add_tag(&Tag::from_str("neorg_data").expect("Is valid"), &mut ops)?; - state.replica().commit_operations(ops)?; + state.replica().commit_operations(ops).await?; Ok(()) } /// Try to start this task. /// It will stop previously active tasks. - pub fn start(&self, state: &mut State) -> Result<()> { + pub async fn start(&self, state: &mut State) -> Result<()> { info!("Activating {self}"); - if let Some(active) = Self::get_current(state)? { - active.stop(state)?; + if let Some(active) = Self::get_current(state).await? { + active.stop(state).await?; } let mut ops = vec![]; - self.as_task(state)?.start(&mut ops)?; - state.replica().commit_operations(ops)?; + self.as_task(state).await?.start(&mut ops)?; + state.replica().commit_operations(ops).await?; Ok(()) } /// Stops this task. - pub fn stop(&self, state: &mut State) -> Result<()> { + pub async fn stop(&self, state: &mut State) -> Result<()> { info!("Stopping {self}"); let mut ops = vec![]; - self.as_task(state)?.stop(&mut ops)?; - state.replica().commit_operations(ops)?; + self.as_task(state).await?.stop(&mut ops)?; + state.replica().commit_operations(ops).await?; Ok(()) } - pub fn description(&self, state: &mut State) -> Result { - Ok(self.as_task(state)?.get_description().to_owned()) + pub async fn description(&self, state: &mut State) -> Result { + Ok(self.as_task(state).await?.get_description().to_owned()) } - pub fn project(&self, state: &mut State) -> Result { + pub async fn project(&self, state: &mut State) -> Result { let output = { - let task = self.as_task(state)?; + let task = self.as_task(state).await?; let task_data = task.into_task_data(); task_data .get("project") @@ -303,10 +308,11 @@ impl Project { /// # Errors /// When `task` execution fails. - pub fn get_tasks(&self, state: &mut State) -> Result> { + pub async fn get_tasks(&self, state: &mut State) -> Result> { Ok(state .replica() - .pending_task_data()? + .pending_task_data() + .await? .into_iter() .filter(|t| t.get("project").expect("Is set") == self.to_project_display()) .map(|t| Task::from(&t)) -- cgit v1.3.1