eatgrass / obsidian-pomodoro-timer

A pomodoro timer that helps manage your daily focus
MIT License
93 stars 5 forks source link

Log to File Active at Start #7

Closed theotheo closed 6 months ago

theotheo commented 6 months ago

Hello. Thank you for such a nice plugin! I would like to suggest a few additions.

My workflow involves logging into different files corresponding to different tasks. This way, I want to track how much time I've dedicated to specific tasks. Therefore, I added an option to log into the file that was active (open) when I started the timer. I updated the README accordingly.

However, there are a few questionable points:

  1. To log into the active file at launch, I need to store it somewhere. I'm currently doing this in TimerState — it seems logical, but passing the TFile to saveLog makes this function more tightly coupled. I don't like it, but I haven't come up with a better solution.
  2. It seems that some active files may not be suitable for logging — for example, it could be a Canvas-file. So, I first check if the file exists and if it is a .md-file. If not, I log it in Daily. This seems like a very specific solution. I understand if you don't like it.

I would appreciate your feedback. I understand if this complication doesn't suit your taste. I have no problem using my fork of your excellent plugin!

eatgrass commented 6 months ago

Hi @theotheo

Thanks for this PR! and I like the idea of having different log files for different tasks, It makes sense for keeping track of things, but I'm a bit unsure about automatically using the file that's opened when we start the timer, I think it's easy to lose track or mix up where we started, I guess that's why you added a fallback to the daily note, it just seems not so intuitive for me. I'm open to merging this if we can add a explicit option for users to choose their fallback policy (None, File, Daily Note)

BTW, I've been considering implementing time stats into the log, so we could figure out which file gets the most attention during a session, and perhaps choose it as the file for logging, could that be an approach fits with your workflow?

Here's a snippet as a POC, let me know what you think.

    const stat: Record<string, number> = {}
    let currentFile: TFile | null | undefined =
        this.app.workspace.getActiveViewOfType(MarkdownView)?.file

    this.registerEvent(
        this.app.workspace.on('active-leaf-change', () => {
            const view =
                this.app.workspace.getActiveViewOfType(MarkdownView)
            if (view) {
                let file = view.file
                if (file?.extension == 'md') {
                    currentFile = file
                } else {
                    currentFile = null
                }
            } else {
                currentFile = null
            }
        }),
    )

    // update time
    this.registerInterval(
        window.setInterval(() => {
            if (currentFile) {
                let total = stat[currentFile.path]
                stat[currentFile.path] = total ? total + 1 : 1
            }

            console.log(stat)
        }, 1000),
    )
eatgrass commented 6 months ago

see #11