This is part 3 of my serie on building WriteRise.
As I shared at the beginning of this journey I'm working on my own word tracking app for Mac OS - WriteRise. I am planning to share its development process in the open through a series of articles here and on Twitter.
Early on I introduced the concept of sessions. A writing session would start when you switch to the application for the first time and would end when you switch to a different application.
This is great and works well, but it's not always so cut and dry. You might be writing and researching so you switch constantly between your writing application and the browser. Or you might have a preview of your markdown next to editor and you switch between the two applications to edit the text.
Until yesterday WriteRise would count all those examples as 2 different sessions. But in reality, they're one session with an interruption in the middle.
A better way is to assume that if we switched back to an application we already have opened (we didn't ⌘+Q, closed it and reopened it) and the last word we wrote in that application is in the last half hour than we're continuing our previous session. Still, need to tweak the timing. Probably can shorten the interval to around 15 minutes instead of a whopping half an hour.
An even better way would be to find the name of the open document and track that, but that comes with the drawback of not always being available. A match between the two systems would cover all the use cases. Use the title of the document when available, use the timer otherwise.