Skip to content

Commit

Permalink
fix: Switch to taskwarrior v3.X backend
Browse files Browse the repository at this point in the history
  • Loading branch information
RedEtherbloom committed Mar 28, 2024
1 parent 4902ecd commit d178b98
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "taskwarrior-tui"
version = "0.25.4"
version = "0.26.0"
license = "MIT"
description = "A Taskwarrior Terminal User Interface"
repository = "https://github.com/kdheepak/taskwarrior-tui/"
Expand All @@ -18,9 +18,7 @@ better-panic = "0.3.0"
cassowary = "0.3.0"
chrono = "0.4.26"
clap = { version = "4.4.1", features = ["derive"] }
crossterm = { version = "0.27.0", features = [
"event-stream",
] }
crossterm = { version = "0.27.0", features = ["event-stream"] }
dirs = "5.0.1"
futures = "0.3.28"
itertools = "0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `taskwarrior-tui`

> [!IMPORTANT]
> `taskwarrior-tui` is only tested with `taskwarrior` v2.x. [`taskwarrior` v3.x](https://github.com/GothenburgBitFactory/taskwarrior/releases/tag/v3.0.0) may not work as intended.
> [`taskwarrior` v3.x](https://github.com/GothenburgBitFactory/taskwarrior/releases/tag/v3.0.0) may break `taskwarrior-tui` features in unexpected ways. Please file a bug report if you encounter a bug.
[![CI](https://github.com/kdheepak/taskwarrior-tui/workflows/CI/badge.svg)](https://github.com/kdheepak/taskwarrior-tui/actions?query=workflow%3ACI)
[![](https://img.shields.io/github/license/kdheepak/taskwarrior-tui)](./LICENSE)
Expand Down
28 changes: 16 additions & 12 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const MAX_LINE: usize = 4096;

lazy_static! {
static ref START_TIME: Instant = Instant::now();
static ref TASKWARRIOR_VERSION_SUPPORTED: Versioning = Versioning::new("2.6.0").unwrap();
static ref TASKWARRIOR_VERSION_SUPPORTED: Versioning = Versioning::new("3.0.0").unwrap();
}

#[derive(Debug)]
Expand Down Expand Up @@ -1309,7 +1309,6 @@ impl TaskwarriorTui {
}
}

self.last_export = Some(std::time::SystemTime::now());
self.task_report_table.export_headers(None, &self.report)?;
self.export_tasks()?;
if self.config.uda_task_report_use_all_tasks_for_completion {
Expand All @@ -1321,6 +1320,10 @@ impl TaskwarriorTui {
self.task_details.clear();
self.dirty = false;
self.save_history()?;

// Some operations like export or summary change the taskwarrior database.
// The export time therefore gets set at the end, to avoid an infinite update loop.
self.last_export = Some(std::time::SystemTime::now());
}
self.cursor_fix();
self.update_task_table_state();
Expand Down Expand Up @@ -1608,20 +1611,21 @@ impl TaskwarriorTui {
}
}

fn get_task_files_max_mtime(&self) -> Result<SystemTime> {
let data_dir = shellexpand::tilde(&self.config.data_location).into_owned();
["backlog.data", "completed.data", "pending.data"]
.iter()
.map(|n| fs::metadata(Path::new(&data_dir).join(n)).map(|m| m.modified()))
.filter_map(Result::ok)
.filter_map(Result::ok)
.max()
.ok_or_else(|| anyhow!("Unable to get task files max time"))
fn get_task_database_mtime(&self) -> Result<SystemTime> {
let data_dir = shellexpand::tilde(&self.config.data_location);
let database_path = Path::new(data_dir.as_ref()).join("taskchampion.sqlite3");

let metadata = fs::metadata(database_path).context("Fetching the metadate of the task database failed")?;
let mtime = metadata
.modified()
.context("Could not get mtime of task database, but fetching metadata succeeded")?;

Ok(mtime)
}

pub fn tasks_changed_since(&mut self, prev: Option<SystemTime>) -> Result<bool> {
if let Some(prev) = prev {
let mtime = self.get_task_files_max_mtime()?;
let mtime = self.get_task_database_mtime()?;
if mtime > prev {
Ok(true)
} else {
Expand Down

0 comments on commit d178b98

Please sign in to comment.