DEV Community

Cover image for A Timer Is Not a Clock: What We Learned Building a Time Tracker for Windows, Mac and Linux
TimoDesk
TimoDesk

Posted on Originally published at timodesk.hashnode.dev

A Timer Is Not a Clock: What We Learned Building a Time Tracker for Windows, Mac and Linux

Counting seconds sounds like the easiest program in the world. Start a timer, add one every second, show the number.

We build TimoDesk, a time tracker for remote teams: a desktop app that tracks time on tasks, takes screenshots at set intervals, measures keyboard and mouse activity, and syncs it all to a web dashboard. After shipping it on three platforms, we can say this with confidence: counting seconds is the hardest part of the whole product.

This is our first post here, so instead of a feature tour, here are the lessons that cost us the most to learn.

Three apps, one product

TimoDesk started as a single Electron app. Today it is three:

  • Windows: .NET (WPF)
  • Mac: Swift and SwiftUI
  • Linux: Electron

We moved Windows and Mac to native code because a time tracker lives in the background all day. It hooks the keyboard and mouse, captures the screen, and wakes up every second. On those two platforms, native code gave us lower memory use, better system integration and fewer surprises with permissions and sleep.

The price is real: every rule about time has to be written three times and has to behave the same way three times. Most of what follows came out of that.

Lesson 1: a timer is not a clock

Our first version did the obvious thing. Every tick, add one second, and stamp the work with "start time plus seconds counted".

That works until the computer stops ticking. A laptop lid closes. A PC with 95% of its memory in use freezes for two minutes. The app's tick loop gets starved by something else on the machine. When ticking resumes, the counter is behind the real clock, and every timestamp built from it is now in the past.

On Windows this turned into a nasty bug. We cut tracked time into chunks and send them to the server every 10 minutes. After one two-minute stall, the minute-by-minute records sat two minutes earlier than the time they actually measured. Each later chunk ended with a stretch that held no ticks, our own gap check took that stretch out, and the server refused the empty piece. One stall cost about two minutes in every ten for the rest of the day.

Users described it perfectly: "time disappears from the counter." We found it by reading 199 refused chunks in our error reports. Every one started on a 10-minute boundary and ended at the next upload, which is the fingerprint of a stamp that drifted once and never caught up.

The fix was a rule we now apply everywhere: stamp work with the clock reading taken at the tick, never with the number of ticks counted. A gap is measured once, removed once, and everything after it is correct again.

Lesson 2: the user's clock is not your clock

Plenty of computers have the wrong time. Wrong time zone, a manual change, a dead motherboard battery, a clock that jumps after sleep.

For a time tracker this matters twice. A clock that runs ahead creates work stamped in the future. A clock that jumps makes a short pause look like an hour away.

What we do now:

  • Server time is the reference. The app keeps an offset to the server's clock and stamps work with it, not with the computer's raw time.
  • Durations use a monotonic clock. "How long has it been" is measured with a clock that cannot jump, never by subtracting two wall times.
  • A jump is detected by comparing both. If wall time moved much more than monotonic time, the clock changed. We first compared wall time against "one second per tick", and a late tick then looked like a clock change. Comparing against a real monotonic clock fixed that.

Lesson 3: billed time can never exceed counted time

Early on we had the opposite bug from Lesson 1: in a few situations the app could report more time than it had actually counted. For a product people use to bill clients and run payroll, that is worse than losing time.

So we wrote it down as a hard guarantee: billed time is never more than ticked time. Idle time is removed from tracked time. When the app is unsure, it holds the data and waits; it does not guess.

Having the rule written as one sentence made code reviews much simpler. Any change that could break it is wrong, no discussion needed.

Lesson 4: offline data is the user's work, never delete it

People track time on trains, in cafés with bad Wi-Fi, and on networks that block things. TimoDesk keeps tracking offline and syncs later. That part is easy.

The hard part is every path where a careless line deletes the queue. Signing out, a forced sign-out, a server error, a reinstall. Our rule: queued time and screenshots are parked, not deleted. A sign-out moves them aside, and the same user's next sign-in brings them back and sends them. A server error keeps the data and retries; it does not throw it away.

Lesson 5 (Mac): one number can redraw your whole app

This one surprised us most.

On the Mac, the app's state lived in one big observable object with about 30 properties. One of them was the number of seconds tracked today, updated every second. In SwiftUI, every change to that object tells every view that watches it to redraw. So once a second, the whole window redrew: the project list, the task list, the search fields.

On a busy Mac, that was enough to keep the main thread nearly 100% busy. The app did not freeze in one place; it was simply never free to handle a click. Our hang reports showed stalls of 14 seconds.

The fix was small: move the counter into its own tiny object that only the timer label watches. Stalls dropped from about 14 seconds to under one second.

We learned the same lesson again later with in-app notifications. On Macs where the user had turned off system notifications, our reminders fell back to an in-app card. Showing and hiding that card lived on the same big object, so each one redrew the whole window, and in one user's logs almost every stall started within a second of a card appearing. Same fix: give it its own object.

The rule we took away: in SwiftUI, anything that changes often gets its own observable object.

Lesson 6: you cannot fix what you cannot read

For months, our Mac hang reports were lists of memory addresses. We could see that the app froze, but not where.

The reason was boring: our release script uploaded the debug symbols (dSYM files) that turn addresses into function names, but a check that should have stopped the release when the upload failed was being skipped. Once that was fixed, the next release's hang reports showed exact function names, and within a day we knew which code to change.

If your crash reports are unreadable, fix that before you fix anything else.

What TimoDesk does today

If you manage a remote team, here is what the product covers:

  • Time tracking linked to projects and tasks
  • Screenshots every 3 to 60 minutes, with optional blur
  • Keyboard and mouse activity levels
  • App and website usage per task
  • Idle time detection with automatic removal
  • Offline tracking that syncs when you are back online
  • Kanban task boards, list and calendar views
  • Timesheets, reports and PDF/CSV exports
  • A live team dashboard and a view-only client portal

Desktop apps for Windows, Mac and Linux, with a 15-day free trial and no card needed.

What's next on this blog

We plan to write about the engineering behind TimoDesk as we go: how we test time logic that depends on sleep and clock changes, how we keep three codebases in step, and what our crash reports teach us after each release.

If you have built anything that depends on time, we would love to hear which of these bugs you have met too. Tell us in the comments.

Try TimoDesk free at timodesk.com.

Top comments (0)