Ellpeck / ObsidianSimpleTimeTracker

Multi-purpose time trackers for your notes!
MIT License
132 stars 19 forks source link

fix: file rename bug #46

Closed jacobtread closed 4 months ago

jacobtread commented 4 months ago

Description

Hey! I've been building out a similar time tracker more tailored to my needs. Using the same storage medium of code blocks as you. I've just patched a bug in mine that I'd been searching for a while but could never figure out why it was happening.

The bug is what was a seemingly random failure to save the time tracking data (Although now I realize it was very much not random)

The bug is caused by the file name changing and the tracker not realizing and trying to modify the old file that doesn't exist. As often I renamed the file before stopping my tracker for the day and thus I encountered this bug.

How to reproduce

  1. Open a file and create a time tracker
  2. Start the timer
  3. Rename the file (Using the editable title in Obsidian)
  4. Stop the timer
  5. Bam saving silently fails (If you close and open the file again you'll see the timer wasn't stopped)

The fix

The fix I came up with for my plugin was to use vault.on with the "rename" event to update the file path that i'm saving to the code for that looks a little something like this:

I've modified your code slightly to pass the file name using a function that is called whenever you save the tracker that way its always the latest value which is being obtained through the rename event

Ellpeck commented 4 months ago

Thanks so much!! This looks good.

jacobtread commented 4 months ago

Haha, never seen a PR merged this quick awesome!

Ellpeck commented 4 months ago

Don't worry, because, knowing me, it'll be a whiiiiiiile until this actually makes it into a new release of the plugin