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
Open a file and create a time tracker
Start the timer
Rename the file (Using the editable title in Obsidian)
Stop the timer
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
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
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