DEV Community

4ndriiK0
4ndriiK0

Posted on

Building a Private Productivity Tracker from Scratch with C++ and Crow

As a developer, I often lose track of time while sitting at my computer. At the end of the day, it is hard to tell how many hours I actually spent coding versus how much time I spent gaming, browsing, or watching videos.

There are many commercial tools available for this, but most of them require a subscription or upload your data to a cloud server. I wanted a solution that was completely private, lightweight, and transparent.

I decided to build LocalFlow, a simple desktop monitor written in C++ that logs active window usage and presents the data in a local web dashboard.

The Goal
I wanted to answer a simple question: Where does my time go?

I needed a tool that could distinguish between:

  • Productivity: Using Visual Studio, Terminal, or Documentation.
  • Gaming: Time spent playing specific games.
  • Viewing: Time spent watching movies or streams (Netflix, YouTube, VLC) without input.

How It Works
The application runs in the background and uses the Windows API to check the active window state.

  1. Window Detection (C++ & WinAPI)
    The core loop uses GetForegroundWindow to identify which application is currently in focus. It extracts the process name (e.g., chrome.exe, valorant.exe, vlc.exe) and logs the duration.

  2. Handling Inactivity (AFK)
    A major issue with simple time trackers is that they keep counting if you walk away from the computer.
    I implemented an AFK detector using GetLastInputInfo. If there is no mouse or keyboard movement for a set period, the timer normally pauses.

  3. Intelligent "Viewing" Mode
    The standard AFK logic has a flaw: if I am watching a 2-hour movie, I am not moving the mouse, so the tracker would incorrectly mark me as "Inactive".

To solve this, I added a check for Full Screen Mode.
If the system detects no mouse movement, it checks the dimensions of the active window. If the window covers the entire screen (hiding the taskbar), the system assumes I am consuming media. Instead of pausing the timer as "AFK", it logs the time as "Viewing".

Local Web Dashboard (Crow)
Instead of building a complex desktop GUI, I embedded a C++ web server using Crow. This allows me to view my stats by simply opening http://localhost:18080 in my browser.

The frontend uses Chart.js to visualize the data. It clearly shows the breakdown of my day, separating active work, gaming sessions, and media viewing time.

Technical Implementation
The project is designed to be portable. It does not require an installer and keeps all data in local JSON files.

  • Language: C++ (for low-level system access and performance).
  • Web Framework: Crow (Microframework for C++).
  • Data Storage: JSON Lines (text-based logs).

Conclusion
This project was a great way to practice systems programming and web integration. It provides an honest look at my daily habits without sending any personal data to a third-party server.

If you are interested in C++ development, WinAPI, or just want to see where your time goes, the source code is available on GitHub.

Repository: github.com/4ndriiK0/LocalFlow

Top comments (0)