Skip to content

ShawnL57/Cal_hacks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

21 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ† Duck Controller - Complete Application

A desktop application that sends random duck messages from Python โ†’ Tauri โ†’ Browser Extension, displaying them on any webpage.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 Python Backend (Port 5000)               โ”‚
โ”‚  - Random message generator                              โ”‚
โ”‚  - Sends messages every 5-10 seconds                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ HTTP POST
                      โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚            Tauri Desktop App (Rust + React)              โ”‚
โ”‚  - HTTP Server (Port 3030) - receives from Python       โ”‚
โ”‚  - WebSocket Server (Port 3030/ws) - sends to extension โ”‚
โ”‚  - React Dashboard - displays activity                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ WebSocket
                      โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Browser Extension (Chrome/Edge)             โ”‚
โ”‚  - Background service worker                             โ”‚
โ”‚  - Content script injection                              โ”‚
โ”‚  - Displays duck messages on all web pages               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

Prerequisites

  • Rust (latest stable) - Install
  • Node.js 18+ - Install
  • Python 3.8+ - Install
  • Chrome/Edge Browser
  • ffmpeg - Install (for video generation)
  • Muse EEG Headset - muse-lsl for streaming
  • API Keys:
    • Anthropic Claude API key
    • Fish Audio API key

๐Ÿ“ฆ Installation

1. Setup Tauri Desktop App

cd calhackproj

# Install dependencies
npm install

# Run in development mode
npm run tauri dev

This will:

  • Start the React frontend on http://localhost:1420
  • Start the Rust backend with HTTP server on http://localhost:3030
  • Start WebSocket server on ws://localhost:3030/ws

2. Setup Python Backend

cd python-backend

# Create virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create .env file with API keys
echo "ANTHROPIC_API_KEY=your_key_here" > .env
echo "FISH_AUDIO_API_KEY=your_key_here" >> .env

# Run the backend
python main.py

The Python backend will:

  • Start Flask server on port 5000
  • Connect to Muse EEG headset for focus detection
  • Take screenshots every 30 seconds
  • Generate questions with Claude AI
  • Create TTS audio with Fish Audio (Donald Duck voice)
  • Generate lip-sync videos with animated duck
  • Send video when user regains focus

3. Install Browser Extension

  1. Open Chrome/Edge
  2. Navigate to chrome://extensions/ (or edge://extensions/)
  3. Enable Developer mode (toggle in top-right)
  4. Click Load unpacked
  5. Select the browser-extension folder
  6. The extension icon should appear in your toolbar

๐ŸŽฎ Usage

Running the Complete System

Terminal 1: Start Tauri App

cd calhackproj
npm run tauri dev

Terminal 2: Start Python Backend

cd python-backend
python main.py

Browser: Enable Extension

  • Extension auto-connects to Tauri WebSocket
  • Visit any website (e.g., google.com, youtube.com)
  • Duck messages will appear as floating notifications!

๐Ÿ“Š What Each Component Does

Python Backend (python-backend/main.py)

  • Connects to Muse EEG headset for real-time brain monitoring
  • Takes screenshots every 30 seconds
  • Uses Claude AI to generate questions about screen content
  • Generates TTS audio with Fish Audio (Donald Duck voice)
  • Creates lip-sync videos with animated duck mouth movements
  • Detects focus state changes and sends videos when focus is restored
  • Endpoints:
    • GET /health - Health check
    • GET /api/metrics - Current EEG metrics
    • GET /video/<filename> - Serve generated videos
    • GET /screenshot/status - Screenshot generator status
    • GET /screenshot/latest - Latest generated video path

Tauri Backend (calhackproj/src-tauri/src/lib.rs)

  • HTTP Server (Port 3030)
    • POST /api/message - Receives messages from Python
    • POST /api/video - Receives video URLs from Python
    • GET /health - Health check
  • WebSocket Server (Port 3030/ws)
    • Broadcasts messages to all connected browser extensions
    • Forwards video URLs to browser for display
  • Tauri Commands
    • get_service_status - Returns status of all services

React Frontend (calhackproj/src/App.tsx)

  • Beautiful dashboard showing:
    • Service status (HTTP, WebSocket, Extension)
    • Message count
    • Real-time activity log
    • Setup instructions

Browser Extension (AnnoyingDuckExtension/)

  • Background Worker (background.js)
    • Connects to Tauri WebSocket
    • Auto-reconnects on disconnect
    • Forwards messages to content scripts
  • Content Script (content.ts)
    • Spawns animated walking duck GIFs on distractions
    • Displays lip-sync videos bottom-right with fade in/out
    • Tracks attention metrics over 2-minute timeline
    • Saves scroll positions when focus drops
  • Popup (popup.html)
    • Shows EEG connection status
    • Displays attention timeline chart
    • Manual quack button for testing
    • Settings for duck visibility

๐Ÿ”ง Configuration

Python Backend

Edit python-backend/main.py:

TAURI_HTTP_URL = "http://localhost:3030/api/message"
MESSAGE_INTERVAL_MIN = 5  # seconds
MESSAGE_INTERVAL_MAX = 10  # seconds

Browser Extension

Edit browser-extension/background.js:

const WEBSOCKET_URL = 'ws://127.0.0.1:3030/ws';
const RECONNECT_INTERVAL = 3000; // 3 seconds
const MAX_RECONNECT_ATTEMPTS = 10;

๐Ÿ› Troubleshooting

Extension Not Connecting

  1. Check Tauri app is running: http://localhost:3030/health
  2. Check WebSocket server in terminal logs
  3. Open extension popup โ†’ Click "Reconnect"
  4. Check browser console (F12) for errors

Python Backend Can't Connect

  1. Ensure Tauri app is running first
  2. Check Tauri logs for HTTP server status
  3. Try manual send: curl -X POST http://localhost:3030/api/message -H "Content-Type: application/json" -d '{"message":"Test","timestamp":"2024-01-01T00:00:00Z","type":"test"}'

No Messages Appearing

  1. Check Python backend logs - should show "Sent to Tauri"
  2. Check Tauri logs - should show "Received from Python"
  3. Check extension background worker console:
    • Right-click extension icon โ†’ "Inspect service worker"
  4. Check webpage console (F12) - should show "Received duck message"

Port Already in Use

If port 3030 or 5000 is taken:

  • Change ports in code (see Configuration section)
  • Kill existing processes: lsof -ti:3030 | xargs kill -9

๐Ÿ“ Development

Build for Production

Tauri App:

cd calhackproj
npm run tauri build

Python Backend (Executable):

cd python-backend
pip install pyinstaller
pyinstaller --onefile main.py

Browser Extension:

  • Zip the browser-extension folder
  • Upload to Chrome Web Store

๐ŸŽจ Customization

Add More Duck Messages

Edit python-backend/main.py:

DUCK_MESSAGES = [
    "๐Ÿฆ† Your custom message!",
    "๐Ÿฆ† Another message!",
    # Add more...
]

Change Message Display Style

Edit browser-extension/content.js - modify the createMessageBox() function CSS.

Adjust Message Frequency

Edit python-backend/main.py:

MESSAGE_INTERVAL_MIN = 2  # Faster
MESSAGE_INTERVAL_MAX = 5

๐Ÿ“š File Structure

annoying-duck-extension/
โ”œโ”€โ”€ calhackproj/              # Tauri Desktop App
โ”‚   โ”œโ”€โ”€ src/                  # React Frontend
โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx          # Main dashboard
โ”‚   โ”‚   โ””โ”€โ”€ App.css          # Styling
โ”‚   โ”œโ”€โ”€ src-tauri/           # Rust Backend
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ lib.rs       # HTTP + WebSocket server
โ”‚   โ”‚   โ””โ”€โ”€ Cargo.toml       # Rust dependencies
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ python-backend/           # Python Backend
โ”‚   โ”œโ”€โ”€ main.py              # Flask server + message generator
โ”‚   โ””โ”€โ”€ requirements.txt     # Python dependencies
โ”œโ”€โ”€ browser-extension/        # Chrome Extension
โ”‚   โ”œโ”€โ”€ manifest.json        # Extension config
โ”‚   โ”œโ”€โ”€ background.js        # Service worker
โ”‚   โ”œโ”€โ”€ content.js           # Page injection
โ”‚   โ”œโ”€โ”€ popup.html           # Popup UI
โ”‚   โ””โ”€โ”€ popup.js             # Popup logic
โ””โ”€โ”€ README.md                # This file

๐Ÿšฆ Testing the Flow

  1. Start Tauri: Should see "HTTP Server started" in terminal
  2. Start Python: Should see "Random message loop started!"
  3. Load Extension: Check popup shows "Connected"
  4. Open any website: Within 5-10 seconds, a duck message appears!
  5. Check Tauri Dashboard: Messages logged in real-time

๐ŸŽฏ Next Steps / Enhancements

  • Add Python as Tauri sidecar (auto-start with app)
  • Add native messaging for direct extension โ†” Tauri communication
  • Persistent storage for message history
  • Settings panel (message frequency, colors, sounds)
  • Multiple duck themes/GIFs
  • Desktop notifications
  • System tray integration

๐Ÿ“„ License

MIT License - Feel free to modify and use!


๐Ÿฆ† Enjoy Your Ducks!

Questions? Issues? Create a GitHub issue or check the troubleshooting section above.

Happy Ducking! ๐Ÿฆ†

About

Contributors: Shawn Lin, Clark Peng, Jared Fellin, Gary Xue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors