Skip to content

Golangcodes/app-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

App Usage Tracker

A lightweight daemon written in Go that tracks your application usage time on Ubuntu/Linux systems. Perfect for monitoring productivity and understanding how you spend time across different applications.

Features

  • 🕒 Automatic Time Tracking - Monitors active application usage in real-time
  • 📊 Simple Reporting - Generate usage reports with time breakdown
  • 🚀 Lightweight Daemon - Runs efficiently in the background
  • 💾 Persistent Storage - Saves data between sessions
  • 🛠 Easy CLI Control - Simple start/stop/report commands

Installation

Prerequisites

# Install xdotool for window detection
sudo apt update
sudo apt install xdotool

Build from Source

# Clone or download the source code
git clone https://github.com/Golangcodes/app-tracker.git
cd app-tracker

# Build the binary
go build -o app-tracker

# Make executable
chmod +x app-tracker

Quick Start

# Start the tracking daemon
./app-tracker start

# Use your computer normally...
# Work in terminal, browser, editor, etc.

# Check your usage report
./app-tracker report

# Stop tracking when done
./app-tracker stop

Usage

Commands

Command Description
./app-tracker start Start the tracking daemon in background
./app-tracker stop Stop the running daemon
./app-tracker report Show usage summary report
./app-tracker Show help and run in foreground for testing

Example Output

$ ./app-tracker report

=== Usage Report ===
brave          :   2.1 hours
neovim         :   3.5 hours
terminal       :   0.8 hours
tmux           :   1.2 hours
ide            :   0.5 hours

How It Works

  • Polling: Checks active window every 3 seconds using xdotool
  • App Detection: Identifies applications based on window titles
  • Session Tracking: Records time spent in each application
  • Data Storage: Saves sessions to /tmp/app-usage.json

Supported Applications

The tracker automatically detects:

  • Brave Browser - Web browsing and AI tools
  • Neovim - Code editing sessions
  • Terminal - Command line usage
  • tmux - Terminal multiplexer sessions
  • IDEs - VS Code, GoLand, IntelliJ
  • Other - Fallback for unidentified applications

Advanced Setup

Systemd Service (Optional)

For automatic startup, create a systemd service:

# Create service file
sudo nano /etc/systemd/system/app-tracker.service

Add the following content:

[Unit]
Description=App Usage Tracker
After=network.target

[Service]
Type=simple
User=your-username
ExecStart=/path/to/your/app-tracker
WorkingDirectory=/path/to/your/
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Enable the service:

sudo systemctl daemon-reload
sudo systemctl enable app-tracker
sudo systemctl start app-tracker

Customization

You can modify the app detection logic in the detectApp() function to add support for additional applications or customize the naming.

File Locations

  • Binary: Your compiled app-tracker executable
  • PID File: /tmp/app-tracker.pid (process tracking)
  • Data File: /tmp/app-usage.json (usage statistics)

Troubleshooting

Common Issues

  1. "xdotool not found"

    sudo apt install xdotool
  2. Daemon not starting

    • Check if another instance is running: ./app-tracker stop
    • Verify xdotool is installed
    • Check permissions on the binary
  3. No data in report

    • Ensure daemon is running: check PID file
    • Verify the data file exists: /tmp/app-usage.json

Debug Mode

Run in foreground to see real-time activity:

./app-tracker

Development

Extending Functionality

The code is structured to be easily extensible:

  • Add new app detection in detectApp() function
  • Modify tracking interval in the ticker (default: 3 seconds)
  • Enhance reporting with additional metrics

Building from Source

# Requires Go 1.16+
go mod init app-tracker
go build -o app-tracker

License

MIT License - feel free to modify and distribute.

Contributing

Contributions welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.


Note: This tool respects your privacy - all data is stored locally and never transmitted elsewhere.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages