## Run the Auto Clicker on Windows at Startup

This guide shows how to start the app automatically on a Windows VM using Task Scheduler and the provided Git Bash script.

### First-time setup
1. Get the code
   - If the repo already exists (recommended):
     ```bash
     cd "<REPO_ROOT>"   # e.g. "C:/Apps/auto_clicker" or "%USERPROFILE%/auto_clicker"
     git pull
     ```
   - If you need to clone it (replace with your repo URL):
     ```bash
     cd "<PARENT_DIR>"  # e.g. "C:/Apps" or "%USERPROFILE%"
     git clone <REPO_URL> auto_clicker
     cd auto_clicker
     ```
2. Create and activate the virtual environment, then install dependencies
   - Using Git Bash or Command Prompt:
     ```bash
     python -m venv venv
     # Activate (Git Bash)
     source venv/Scripts/activate
     # Or activate (CMD)
     venv\Scripts\activate
     pip install -r requirements.txt
     ```
   - Using PowerShell:
     ```powershell
     python -m venv venv
     .\venv\Scripts\Activate.ps1
     pip install -r requirements.txt
     ```
3. Optional: environment config
   - Copy the template and adjust values as needed:
     ```bash
     cp env_template.txt .env
     ```
4. Test run once manually
   ```bash
   bash scripts/start_windows.sh
   ```

### Prerequisites
- Git for Windows installed (includes Git Bash)
- Python 3 and the project virtual environment prepared
  - From the repo root: `python -m venv venv`
  - Activate it and install deps: `venv\Scripts\activate && pip install -r requirements.txt`

### Script
- Script path: `scripts/start_windows.sh`
- What it does:
  - Resolves the repo root and `cd` there
  - Activates the venv (Windows-friendly)
  - Starts the app via `main.py`
  - Appends logs to `logs/app_debug.log`

### Verify it runs manually
1. Open Git Bash.
2. Change directory to your repo root.
3. Run:
   ```bash
   bash scripts/start_windows.sh
   ```
4. Confirm the UI launches and `logs/app_debug.log` receives entries.

### Add to Windows Startup (Task Scheduler)
1. Open Task Scheduler.
2. Action: Create Task…
3. General tab:
   - Name: `AuditWhizz Autoclicker`
   - Security options: Select your user; check "Run only when user is logged on" (recommended for GUI apps).
4. Triggers tab:
   - New…
   - Begin the task: `At log on`
   - Specific user: your Windows user
   - Enabled: checked
5. Actions tab:
   - New…
   - Action: `Start a program`
   - Program/script: path to Git Bash, e.g.
     - `C:\Program Files\Git\bin\bash.exe`
   - Add arguments (optional):
     - `-lc "bash scripts/start_windows.sh"`
   - Start in (optional): set to the repository root folder, e.g.
     - `C:\Path\To\auto_clicker` or `%USERPROFILE%\auto_clicker`
6. Conditions tab:
   - Uncheck "Start the task only if the computer is on AC power" on laptops, if needed.
7. Settings tab:
   - Check "If the task fails, restart every: 1 minute" and set attempts as desired.

Click OK to save. Log out and back in (or reboot) to test.

### Optional: Auto-update on start
To pull latest code at each start, set an environment variable for the action:
- Actions → New… → Add arguments:
  - `-lc "UPDATE_ON_START=1 bash scripts/start_windows.sh"`

### Troubleshooting
- No UI appears:
  - Ensure the task is set to "Run only when user is logged on"; GUI apps won’t show under "Run whether user is logged on or not".
- Python not found:
  - Verify `venv\Scripts\python.exe` exists, or install Python 3 and recreate the venv.
- Logs are empty:
  - Check the Task Scheduler History tab and `logs/app_debug.log` for errors.
- Permission denied:
  - Ensure the repo folder is accessible to your user and not blocked by antivirus.


