# Theme Switcher Testing Guide

This guide will help you test the theme switcher module on the nate-work host.

## Pre-Testing Checklist

### 1. Review Current Configuration

Check your current nate-work configuration:

```bash
# View current wallpaper rotator settings
grep -A 10 "wallpaperRotator" nate-work/desktop-configuration.nix

# View current GTK/Qt theme settings
grep -A 10 "gtk\|kvantum" nate-work/modules/home-manager/home.nix
```

### 2. Files to Modify

You'll need to modify these files:

1. **nate-work/desktop-configuration.nix** (or wherever you import modules)
   - Add themeSwitcher import
   - Disable wallpaperRotator if enabled
   - Configure themeSwitcher settings

2. **nate-work/modules/home-manager/home.nix**
   - Comment out static GTK theme configuration
   - Comment out static Kvantum configuration
   - Keep icon and cursor themes

## Testing Phase 1: Manual Mode

Start with manual mode to test theme generation before enabling automation.

### Step 1: Add Module Configuration

Edit `nate-work/desktop-configuration.nix`:

```nix
{
  imports = [
    # ... existing imports ...
    ../../shared/modules/services/theme_switcher
  ];
  
  # Disable old wallpaper rotator if present
  # services.wallpaperRotator.enable = false;
  
  # Enable theme switcher in manual mode
  services.themeSwitcher = {
    enable = true;
    user = "nate";
    
    # Start with manual mode (no auto-switching)
    enableAutoSwitch = false;
    
    # Use switch-only mode for testing (no continuous rotation yet)
    rotation.mode = "switch-only";
    
    # Configure wpaperd
    wpaperd = {
      enable = true;
      mode = "center";
      transition.effect = "fade";
      transition.duration = 300;
    };
  };
}
```

### Step 2: Comment Out Static Themes

Edit `nate-work/modules/home-manager/home.nix`:

```nix
# Comment out these sections:
# gtk.theme = { ... };
# xdg.configFile."Kvantum/kvantum.kvconfig" = ...;
# xdg.configFile."gtk-4.0/..." = ...;

# Keep these (icon and cursor themes are independent):
gtk.iconTheme = { ... };  # Keep
gtk.cursorTheme = { ... };  # Keep
```

### Step 3: Rebuild System

```bash
# From /home/nate/nixos directory
sudo nixos-rebuild switch --flake .#nate-work
```

This will:
- Install pywal16, haishoku, wpaperd
- Install apply-theme.sh to ~/.local/bin/
- Install pywal templates
- Start wpaperd (but with no auto-rotation)
- NOT start any timers (manual mode)

### Step 4: Manual Testing

After rebuild, test the script manually:

```bash
# Test light theme
~/.local/bin/apply-theme.sh --light

# Verify:
# 1. Wallpaper changed to one from Light/ directory
# 2. Colors extracted: cat ~/.cache/wal/colors.json
# 3. GTK theme generated: ls ~/.config/gtk-3.0/gtk.css
# 4. Kvantum theme generated: ls ~/.config/Kvantum/PywalTheme/
# 5. Open a GTK app (nautilus, calculator) - check colors
```

```bash
# Test dark theme
~/.local/bin/apply-theme.sh --dark

# Verify same things with Dark wallpaper
```

```bash
# Test with specific wallpaper
~/.local/bin/apply-theme.sh --light --wallpaper-path ~/nixos/shared/modules/services/wallpapers/Light/IU-Light.jpg
```

### Step 5: Verify Wpaperd Integration

```bash
# Check if wpaperd is running
pgrep wpaperd

# Check wpaperd status
systemctl --user status wpaperd

# Manually change wallpaper using wpaperctl
wpaperctl wallpaper ~/nixos/shared/modules/services/wallpapers/Dark/IU-Dark.jpg
```

## Testing Phase 2: Automatic Switching (Time-Based)

Once manual testing works, enable automatic time-based switching.

### Step 1: Enable Auto-Switch

Edit `nate-work/desktop-configuration.nix`:

```nix
services.themeSwitcher = {
  enable = true;
  user = "nate";
  
  # Enable automatic switching
  enableAutoSwitch = true;
  
  # Keep switch-only mode for now
  rotation.mode = "switch-only";
  
  # Optional: Adjust times for testing
  lightTime = "08:00:00";  # Your preferred time
  darkTime = "17:00:00";   # Your preferred time
};
```

### Step 2: Rebuild and Check Timer

```bash
sudo nixos-rebuild switch --flake .#nate-work

# Verify timer is installed
systemctl --user list-timers | grep theme

# Should show two entries (one for lightTime, one for darkTime)
systemctl --user status theme-switcher.timer
```

### Step 3: Test Timer Manually

```bash
# Manually trigger the service
systemctl --user start theme-switcher.service

# Check logs
journalctl --user -u theme-switcher.service -n 50

# Should show theme being applied based on current time
```

## Testing Phase 3: Continuous Rotation

Once automatic switching works, enable continuous wallpaper rotation.

### Step 1: Enable Continuous Mode

Edit `nate-work/desktop-configuration.nix`:

```nix
services.themeSwitcher = {
  enable = true;
  user = "nate";
  enableAutoSwitch = true;
  
  # Enable continuous rotation
  rotation = {
    mode = "continuous";
    interval = "5m";  # Rotate every 5 minutes
  };
};
```

### Step 2: Rebuild and Monitor

```bash
sudo nixos-rebuild switch --flake .#nate-work

# Check rotation timer
systemctl --user list-timers | grep wallpaper
systemctl --user status wallpaper-rotation.timer

# Watch logs in real-time
journalctl --user -u wallpaper-rotation.service -f
```

### Step 3: Verify Rotation

Wait 5 minutes and verify:
- Wallpaper changes
- Theme regenerates
- Colors match new wallpaper

## Troubleshooting

### Theme Not Applying

```bash
# Check if pywal generated files
ls -la ~/.cache/wal/

# Expected files:
# - colors.json
# - gtk-3.0.css
# - gtk-4.0.css
# - PywalTheme.kvconfig
# - ghostty.conf
```

### Wallpaper Not Changing

```bash
# Check wpaperd status
systemctl --user status wpaperd
journalctl --user -u wpaperd -n 50

# Try manual change
wpaperctl wallpaper ~/path/to/wallpaper.jpg
```

### GTK Theme Not Loading

```bash
# Check GTK config
ls -la ~/.config/gtk-3.0/
ls -la ~/.config/gtk-4.0/

# Check if files are symlinks
readlink ~/.config/gtk-3.0/gtk.css
# Should point to ~/.cache/wal/gtk-3.0.css
```

### Kvantum Theme Not Loading

```bash
# Check Kvantum directory
ls -la ~/.config/Kvantum/PywalTheme/

# Manually set theme
kvantummanager --set PywalTheme

# Restart Qt applications
```

### Service Failures

```bash
# Check service logs
journalctl --user -u theme-switcher.service --since today
journalctl --user -u wallpaper-rotation.service --since today

# Check environment
systemctl --user show theme-switcher.service | grep PATH
```

## Performance Monitoring

### Resource Usage (Continuous Mode)

```bash
# Monitor theme regeneration
watch -n 60 'ls -lh ~/.cache/wal/colors.json'

# Check pywal CPU usage
top -b -n 1 | grep wal
```

If continuous mode is too resource-intensive, switch to switch-only mode.

## Success Criteria

- ✓ Manual theme switching works (--light and --dark)
- ✓ Wallpapers change via wpaperctl
- ✓ GTK apps reflect new colors
- ✓ Qt apps reflect new Kvantum theme
- ✓ Ghostty terminal shows new colors (if installed)
- ✓ Timers appear in systemctl --user list-timers
- ✓ Automatic switching works at configured times
- ✓ Continuous rotation works (if enabled)
- ✓ No service failures in journalctl

## Next Steps After Testing

Once everything works on nate-work:

1. Consider applying to other hosts (frame12, nate, scrappy)
2. Fine-tune rotation interval if needed
3. Try different pywal backends (modern_colorthief, etc.)
4. Customize wpaperd transition effects
5. Add custom pywal templates for other apps

## Rollback Plan

If something goes wrong:

```bash
# Disable the module
# In nate-work/desktop-configuration.nix:
services.themeSwitcher.enable = false;

# Re-enable old configuration
# services.wallpaperRotator.enable = true;
# Uncomment GTK/Qt theme settings in home.nix

# Rebuild
sudo nixos-rebuild switch --flake .#nate-work
```
