Desktop time tracking
Desktop time tracking is a local-first system for recording work time and computer activity in Electron products. It keeps a signed-in employee's timer, activity periods, and optional screen evidence aligned with the Gauzy platform, even when the service is slow or offline.
Product family
The desktop products use one tracking model but present different user surfaces. The full desktop app gives access to the wider Gauzy desktop experience, the focused timer gives a small timer surface, and the agent keeps capture and delivery active in the background. The desktop app is packaged for supported macOS, Windows, and Linux targets and is delivered through desktop release packages. See the related Electron desktop applications, desktop agent capture and sync, and desktop shared libraries pages for focused views.
Desktop applications
The full desktop app and focused timer let an employee sign in, choose work context, start or stop tracking, and review captured work. Their windows and tray controls use the same local tracking state, so closing a view does not silently end a running session.
The products can connect to an integrated local service, a custom Gauzy server, or Gauzy Cloud. Setup saves the selected connection and applies it again after restart. Server products can also expose their API and web UI to other computers when LAN access is enabled.
References: apps/…/package.json• L21-146 packages/…/setup.component.ts• L343-370 packages/…/setup.component.ts• L402-445
Desktop agent
The agent is the background partner to the desktop products. After sign-in, it can run a timer, collect keyboard and mouse activity, record the active application or URL, take screenshots when policy allows, and place the resulting records on the delivery path.
The agent keeps capture separate from delivery. It writes timer and activity data locally first, then sends it to Gauzy. This lets work continue during a short service outage and gives later sync work a durable record to process.
References: apps/…/ipcMain.ts• L70-86 apps/…/pull-activities.ts• L264-301 apps/…/pull-activities.ts• L775-818
Shared desktop services
The shared desktop libraries provide the common boundary for account state, application settings, timer records, activity records, screenshots, queues, native windows, and local services. This boundary keeps the full app, timer, and agent consistent.
The libraries also coordinate service URLs and local web UI behavior. A local service can listen only on the computer or on a chosen LAN address. The web UI receives the API address at run time, so read-only app installs can still start without changing their installed files.
References: packages/…/index.ts• L1-33 packages/…/desktop-store.ts• L34-65 packages/…/server-config.ts• L13-85 packages/…/ui-service.ts• L45-59
Account and service boundary
Tracking belongs to a signed-in employee inside one tenant and organization. That scope must remain the same in the user interface, Electron main process, local records, and platform requests before capture or sync can proceed.
Authentication session
The desktop session holds access credentials and the active employee and organization. Password and provider sign-in end by placing the same account context in the desktop interface and main process. The agent waits for that context before it starts capture or queue work.
Platform requests include the active tenant and organization. If an access token expires, concurrent callers share one refresh operation and retry the failed request only once. A refresh that does not answer is abandoned instead of holding later work forever.
References: apps/…/api.ts• L185-205 apps/…/api.ts• L334-409 apps/…/api.ts• L474-547 apps/…/api.spec.ts• L83-150
Organization context
An organization change is a context change, not only a selector change. The desktop clears work selections, updates credentials on both sides of the Electron boundary, and reloads employee settings before it allows tracking to continue.
The timer does not start while the change is incomplete. If the new organization has no usable employee context, the product ends the session and asks the employee to sign in again rather than mix records from two organizations.
References: packages/…/organization-switch.service.ts• L51-65 packages/…/organization-switch.service.ts• L164-213 packages/…/organization-switch.service.ts• L294-390
Service setup
Setup selects the API endpoint and, for an integrated service, the local database and server settings. The saved setup controls the address used by the tracker, the local API, and any local web UI.
Server setup treats a listen address and a client address as different needs. Local-only clients use loopback. LAN clients use a reachable computer address. The setup screen offers suitable local addresses and warns about values that are valid but may not work in the selected network or SSL mode.
References: packages/…/setup.component.ts• L183-231 packages/…/server-host-input.component.ts• L9-20 packages/…/server-host.util.ts• L159-211 packages/…/desktop-network-addresses.ts• L19-37
Tracking model
The system treats work as a timer stream plus an activity stream. The timer defines when work is open. Activity periods describe what happened during that time, and screenshots provide optional visual evidence.
Timer session
A start creates a local timer record before it depends on a platform response. A stop records the local end first, then sends the matching change when the service is available. The local record keeps enough state for the platform sync path to finish or repair the remote time log.
The current project, task, contact, and team context travels with the timer. A later start must not close an earlier timer when transitions overlap, so each stop stays attached to the session that it began closing.
References: apps/…/pull-activities.ts• L309-348 apps/…/pull-activities.ts• L378-444 packages/…/desktop-timer.ts• L664-727 packages/…/desktop-ipc.ts• L832-903
Activity period
While a session runs, the capture loop groups input counts, active-window data, idle time, work context, and local screenshot paths into short periods. Each period is saved locally before a related platform time slot is created.
Activity can also include data from ActivityWatch or WakaTime when those integrations are enabled. An idle period remains part of the session record but does not request a screenshot.
References: apps/…/pull-activities.ts• L759-818 packages/…/desktop-timer.ts• L394-482 packages/…/types.ts• L116-162
Screen evidence
Screenshots are optional evidence for an activity period. Capture requires both the employee policy and the organization policy to allow it. Until the organization setting is known, the agent does not assume that capture is allowed.
The organization supplies the screenshot frequency. The agent reads it at tracking start and resume, then re-reads it during a long session. A missing or invalid value keeps the current usable period or falls back to the defined default. The employee's local settings control display scope, notice, sound, and random timing within that policy.
References: apps/…/util.ts• L166-228 apps/…/screenshot-interval.ts• L13-52 apps/…/pull-activities.ts• L621-659 packages/…/desktop-screenshot.ts• L528-547 packages/…/desktop-timer.ts• L539-576
Capture and synchronization flow
The normal flow moves from a user action to local records and then to platform records. Local persistence is the handoff between OS-facing capture and network-facing sync.
The diagram shows the normal path and the point where offline recovery takes over.
flowchart LR
A[Employee starts timer] --> B[Local timer record]
B --> C[Activity and active-window capture]
C --> D[Local activity period]
C -. optional .-> E[Local screenshot]
D --> F[Platform time slot]
F --> G[Linked screenshot upload]
G --> H[Local record marked complete]
F -. service unavailable .-> I[Durable retry work]
I --> F
Capture coordination
The agent starts capture only after it has a usable account scope. Its loop collects active windows, flushes input measures, tracks idle state, and requests screenshots according to employee and organization policy.
Power events use the same session state. Device sleep pauses capture only when tracking was running. Wake records the sleep span as idle activity and resumes only the session that sleep paused. A user stop during sleep cancels that resume.
The agent serializes start, stop, sleep, and wake transitions. A slow transition cannot block all later transitions forever, but a later transition still cannot silently replace the timer owned by an earlier one.
References: apps/…/pull-activities.ts• L154-218 apps/…/pull-activities.ts• L462-526 apps/…/pull-activities.ts• L844-877 apps/…/pull-activities.spec.ts• L188-326
Platform synchronization
The delivery path handles timer changes, activity time slots, and screenshots as related work. It creates the time slot before it links images to that slot, then updates local sync state only after the matching platform action succeeds.
Requests carry the active employee's tenant and organization. Records created under an older account or tracking session are ignored when their late network response arrives. This prevents stale settings or work from crossing an account boundary.
References: apps/…/api.ts• L224-332 apps/…/api.ts• L513-547 apps/…/pull-activities.ts• L621-643 packages/…/desktop-ipc.ts• L222-267
Offline recovery
Timer, activity, and screenshot work remains local until delivery succeeds. Connectivity checks move the desktop into offline mode when the API cannot answer and trigger sync when the connection returns. The check uses a bounded probe so a lost service is noticed within a defined time budget.
Timer jobs can use an optional persistent queue that survives a quit or crash. The default in-memory path remains available, and a job that cannot enter the persistent path runs in order after older stored work. This protects timer order without making a queue failure stop capture.
References: packages/…/connectivity-timing.ts• L1-11 packages/…/api-server-connectivity.ts• L9-43 packages/…/desktop-offline-mode-handler.ts• L43-127 packages/…/desktop-timer.ts• L773-809 packages/…/desktop-timer.ts• L939-1085
User control and desktop state
The desktop products expose one tracking state through windows, tray actions, notifications, and an optional always-on view. These surfaces show the state of the local timer and capture policy rather than creating separate timers.
Tray and windows
The agent tray shows whether the timer runs and which capture types are active. It opens the timer, settings, dashboard, and activity views. A deliberate exit can stop tracking and pending work when employee policy allows it; a running timer can require confirmation first.
Screenshot notices are temporary windows owned by the main process. Closing a notice cancels its pending display work and its auto-hide timer, so an old notice cannot close a later one.
References: apps/…/tray-notify.ts• L39-68 apps/…/window-manager.ts• L258-311 apps/…/screen-capture-window.ts• L15-33 packages/…/screen-capture.component.ts• L11-70
Account and capture policy
Employee policy controls capture permission, input tracking, display scope, logout, and application exit. Organization policy adds a second screen-capture gate and controls the screenshot frequency. Local preferences control how permitted capture is shown and heard on the computer.
The tray reflects the effective policy. It reports time capture and adds screenshot or input capture only when those activities are currently allowed.
References: apps/…/util.ts• L21-57 apps/…/util.ts• L184-209 apps/…/tray-notify.ts• L55-68 packages/…/settings.component.ts• L661-722
Window navigation
Electron windows with desktop privileges stay on their own pages or trusted service origins. Other links open in the user's browser. Provider sign-in is a controlled exception that returns through the configured service.
This boundary keeps task or server content from sending a privileged window to an untrusted page. The same rule matters when setup changes the service address.
References: packages/…/navigation-guard.ts• L62-145 packages/…/desktop-ipc.ts• L694-714 packages/…/ui-runtime-config.ts• L58-76
Change checklist
When these files or sections are changed, remember to consider these:
- Keep tenant, organization, employee identity, and record ownership aligned across renderer state, main-process state, local storage, agent state, and request headers.
- Keep organization changes atomic with timer starts, token refresh, work selection, employee settings, and tracker reloads.
- Keep employee capture permission and organization capture permission as separate inputs to the effective screenshot rule.
- Keep organization screenshot frequency aligned with the stored local period and the running capture schedule.
- Keep timer creation, activity save, time-slot creation, screenshot upload, and local completion in order.
- Keep sleep, wake, user stop, and application exit transitions aligned so stopped sessions do not resume and sleep is idle time.
- Keep persistent queue work ahead of fallback work and ahead of offline sync reads.
- Keep API probe, offline mode, reconnect sync, and user-visible connectivity notices within the same timing contract.
- Keep server listen hosts, client URLs, LAN access, runtime UI configuration, and navigation trust origins aligned.
- Keep screenshot notice close behavior connected to the main-process owner of its auto-hide timer.
- Keep custom screenshot sound files inside the app data boundary and keep the settings copy current after a sound change.
- Keep desktop build targets, native permissions, unpacked resources, and release artifacts aligned when packaging the desktop app for a platform.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Organization capture permission is not loaded or is turned off | The agent may capture under the wrong policy or keep showing capture as active | Capture requires both stored employee and organization permission; organization settings refresh while tracking runs |
| A late organization-settings response belongs to an earlier account or session | A new employee can receive an old screenshot period or permission | The agent checks account, organization, tenant, and tracking-session scope before applying the response |
| Device wake follows a user stop | A stopped timer can start again or record unowned idle time | Wake resumes only a sleep-paused session; stop cancels the pause |
| A persistent queue refuses a job | Timer or activity updates can be lost or run out of order | Work falls back in submission order after older stored jobs |
| A local service uses a LAN address while LAN access is off | The client points at an address where the service does not listen | Listen and client addresses resolve to loopback for local-only mode |
| A server install cannot write its UI files | Setup or server start can fail before the UI learns its API URL | The UI server injects runtime configuration while serving the page; file writing is only a fallback |
| A privileged window follows content to an untrusted origin | Untrusted content can gain access to desktop capabilities | Navigation is limited to app pages and trusted service origins |
| A screenshot window closes while its auto-hide is pending | The next screenshot notice can close too soon | The window manager owns both close and auto-hide cleanup |
| A platform package lacks a required native resource or permission | A desktop build can install but fail to capture, start, or run on that platform | Packaging keeps platform targets, native permissions, unpacked modules, and bundled resources aligned |
Key files
| File | Why to read it |
|---|---|
| apps/…/package.json | Desktop product identity, platform release targets for macOS, Windows, and Linux, native permissions, bundled resources, and release output. |
| apps/…/pull-activities.ts | Main agent lifecycle for timer transitions, activity capture, screenshots, sleep, and organization policy refresh. |
| apps/…/api.ts | Platform boundary for timers, time slots, screenshots, account settings, and token refresh. |
| apps/…/ipcMain.ts | Main-process control for sign-in, tracking start and stop, setup restart, and offline state. |
| apps/…/tray-notify.ts | Effective capture state shown by the agent tray. |
| apps/…/window-manager.ts | Agent window lifecycle and screenshot notice ownership. |
| packages/…/desktop-timer.ts | Timer activity collection, time-slot assembly, and ordered queue behavior. |
| packages/…/desktop-ipc.ts | Shared Electron boundary for timer control, screenshots, offline sync, permissions, and service links. |
| packages/…/desktop-screenshot.ts | Shared screenshot permission rule and active-display selection. |
| packages/…/desktop-store.ts | Local account, service, project, and application setting boundary. |
| packages/…/desktop-offline-mode-handler.ts | Offline and reconnect state used by tracking and sync. |
| packages/…/server-config.ts | Service host, client URL, LAN access, and local web UI address rules. |
| packages/…/ui-service.ts | Runtime API configuration passed to a locally served web UI. |
| packages/…/types.ts | Shared shape of account, service, project, and tracking settings. |
| packages/…/setup.component.ts | Setup choices for integrated, custom, and live service modes. |
| packages/…/settings.component.ts | User controls for capture, timer periods, sound, sleep, and server settings. |
| packages/…/organization-switch.service.ts | Organization switch safeguards around active tracking. |
| packages/…/navigation-guard.ts | Trust boundary for privileged Electron windows. |