Skip to content

Commit

Permalink
Delete autosave on timer stop
Browse files Browse the repository at this point in the history
  • Loading branch information
rickykresslein committed Sep 29, 2024
1 parent e130be2 commit 940b544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
};

use crate::{
autosave::{autosave_exists, restore_autosave, write_autosave},
autosave::{autosave_exists, delete_autosave, restore_autosave, write_autosave},
constants::{
ALLOWED_DB_EXTENSIONS, INSPECTOR_ALIGNMENT, INSPECTOR_PADDING, INSPECTOR_SPACING,
INSPECTOR_WIDTH, SETTINGS_SPACING,
Expand Down Expand Up @@ -4126,6 +4126,7 @@ fn stop_timer(state: &mut Furtherance, stop_time: DateTime<Local>) {
})
.expect("Couldn't write task to database.");

delete_autosave();
reset_timer(state);
}

Expand Down
18 changes: 9 additions & 9 deletions src/autosave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ pub fn write_autosave(task_input: &str, start_time: DateTime<Local>) -> Result<(
Ok(())
}

pub fn delete_autosave() {
let path = get_autosave_path();
if path.exists() {
if let Err(e) = remove_file(path) {
eprintln!("Error deleting autosave: {e}");
}
}
}

fn get_autosave_path() -> PathBuf {
let mut path = get_data_path();
path.extend(&["autosave.txt"]);
Expand Down Expand Up @@ -112,12 +121,3 @@ fn task_from_autosave(path: &PathBuf) -> Option<FurTask> {
return None;
}
}

fn delete_autosave() {
let path = get_autosave_path();
if path.exists() {
if let Err(e) = remove_file(path) {
eprintln!("Error deleting autosave: {e}");
}
}
}

0 comments on commit 940b544

Please sign in to comment.