Metadata-Version: 2.4
Name: lumitray
Version: 0.4.0
Summary: Privacy-preserving webcam-based automatic laptop brightness
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: numpy>=1.26
Requires-Dist: opencv-python-headless<5,>=4.8
Requires-Dist: psutil>=5.9
Requires-Dist: platformdirs>=4
Requires-Dist: Pillow>=10
Requires-Dist: pystray>=0.19
Requires-Dist: screen-brightness-control>=0.24
Requires-Dist: winsdk>=1.0.0b10; platform_system == "Windows" and python_version < "3.14"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"

# LumiTray

LumiTray is a background Windows/Linux application that approximates ambient light with one low-resolution webcam frame and adjusts the built-in laptop display. It samples every **2 minutes by default**, with a configurable **1–10 minute** interval. On battery it pauses capture by default and resumes automatically when AC power returns.

## Privacy and accuracy

- Frames are processed in memory and are never saved.
- On battery, capture and brightness changes are skipped by default; the camera stays closed.
- Debug mode writes only numeric luminance, acquisition time, and brightness values to the rotating log; it never saves frames.
- There is no recording, face detection, telemetry, or cloud service.
- The webcam is closed between measurements; its indicator may turn on briefly.
- A webcam is not a true ambient-light sensor. Use quick calibration and brightness bias to adapt the approximation to your laptop and room.
- Manual brightness changes pause automatic adjustment for 15 minutes.

## Install with pipx

Requires Python 3.11 or newer, including Python 3.14:

```bash
pipx install lumitray
lumitray install --autostart
```

`lumitray install` creates a per-user Start Menu shortcut on Windows or application entry on Linux. `--autostart` also starts LumiTray at login. No administrator privileges are required.

To remove launchers while preserving settings:

```bash
lumitray uninstall
pipx uninstall lumitray
```

## Standalone Windows and Linux packages

Download `lumitray-windows.zip` or `lumitray-linux.tar.gz` from the GitHub release and extract both executables. No system Python is required.

On Windows:

```powershell
.\lumitray.exe install --autostart
.\lumitray-tray.exe
```

On Linux:

```bash
./lumitray install --autostart
./lumitray-tray
```

Linux requires a V4L2-compatible webcam, a supported tray/AppIndicator environment, and `brightnessctl` with user-writable backlight permissions. Python-based Linux installations also need Tk support for the settings dialog. The installers do not change system permissions.

## Settings

Right-click the tray icon and choose **Settings…**, or run:

```bash
lumitray settings
lumitray settings --min 70 --max 100
lumitray settings --interval-minutes 2
lumitray settings --no-disable-on-battery
lumitray settings --debug
```

Defaults are **70–100%** brightness, a **2-minute** capture interval, **Disable on battery** enabled, and **Debug mode** disabled. Brightness limits must be integers satisfying `5 <= minimum < maximum <= 100`. Capture intervals must be integers from `1` to `10` minutes. Invalid updates leave the existing configuration untouched. Saving from the tray applies the settings immediately when automatic adjustment is active; paused and disabled states are preserved. Camera frames are never saved.

Debug mode writes numeric luminance, acquisition time, and current/target brightness details to the rotating log file. It does not enable photo saving. Release builds disable debug logging unconditionally, even if a configuration file contains `"debug_mode": true`.

## Commands

```bash
# Check platform, power source, and brightness support
lumitray diagnose

# Capture one frame and print only numeric luminance
lumitray sample

# Run one automatic adjustment cycle
lumitray once

# Change brightness slightly, verify it, then restore the original value
lumitray brightness-test --delta 5

# Create or remove per-user application launchers
lumitray install [--autostart]
lumitray uninstall

# Run in the background tray
lumitray tray
```

When running from the project without adding the console script to `PATH`, use `.venv\Scripts\python.exe -m lumitray ...` on Windows or `.venv/bin/python -m lumitray ...` on Linux.

## Tray controls

The tray menu provides status, pause/resume, brightness bias, settings, quick calibration, automatic-adjustment enable/disable, login autostart, and Exit. Only one tray instance can run at a time.

When the camera cannot provide a frame, the tray tooltip and the disabled status area show a short category such as **Camera not found**, **Camera in use**, or **Camera access blocked**. The disabled detail row keeps the original technical error for diagnosis. LumiTray sends one tray notification when a new camera-error episode starts; a successful frame clears the error and restores the normal tooltip.

While a camera error is active, **Retry now** requests an immediate sample without waiting for the next interval. **Quick fix** is context-sensitive:

- **Camera not found:** resets LumiTray's camera backend, attempts a non-administrative device rescan, and retries. If the camera is still unavailable, the item changes to **Open Device Manager**.
- **Camera in use:** releases only LumiTray's camera handle and retries. LumiTray never closes other applications; persistent errors keep the instruction to close apps using the camera.
- **Camera access blocked:** opens Windows camera privacy settings. LumiTray never changes permissions automatically.
- **Dark or covered lens:** shows instructions to check the lens and lighting, then retries.
- **Invalid frame or driver failure:** recreates the capture session and retries. Persistent driver failures offer Windows camera troubleshooting.
- **Unknown failure:** runs the safe reset/retry sequence and preserves the original error in the detail row and log.

Quick fixes and Retry now never start concurrent captures. Repeated clicks coalesce into one pending request, and automatic retries remain bounded by the existing failure backoff. No recovery action kills other processes, installs drivers, changes privacy permissions, requires administrator rights, or saves a photo.

## Ambient-light response

The generic response interpolates between these normalized camera-luminance anchors:

| Camera-relative luminance | Target before bias and user limits |
| --- | --- |
| 0.00 | 20% |
| 0.08 | 25% |
| 0.20 | 40% |
| 0.40 | 55% |
| 0.60 | 70% |
| 0.80 | 85% |
| 1.00 | 95% |

The curve is inspired by adaptive-brightness research, but normalized camera luminance is **not measured lux**. Webcam exposure, gain, direction, and scene content vary. Quick calibration, brightness bias, smoothing, a deadband, and maximum-step limits let LumiTray adapt without abrupt changes.

Research references:

- Microsoft adaptive-brightness guidance: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/sensors-adaptive-brightness
- Controlled screen-brightness study: https://jps.ecnu.edu.cn/EN/abstract/abstract9078.shtml
- Example of device-specific webcam/lux calibration: https://www.medrxiv.org/content/10.1101/2020.05.28.20115725v2.full-text

## Platform details

On Windows with Python 3.11–3.13, LumiTray uses native WinRT `MediaCapture` through `winsdk`, captures a 320 × 240 JPEG directly into memory, and closes the capture session after every sample. Python 3.14 uses OpenCV because `winsdk` does not yet provide Python 3.14 binaries. OpenCV is also the camera backend on Linux.

Linux standalone artifacts are built and CLI-smoke-tested in native CI; they are not hardware-verified from a Windows development machine.

## Configuration and logs

Settings and logs are stored in the platform-specific user configuration/log directories reported by `platformdirs`. Configuration is JSON. Logs contain numeric status and error information plus detailed debug lines only when debug mode is enabled, never images.

## Development verification

```bash
python -m venv .venv
.venv/Scripts/python -m pip install -e ".[dev]"  # Windows
.venv/Scripts/python -m pytest -q                 # Windows
.venv/Scripts/python -m build
```

The automated suite uses fake hardware. Real display verification is performed only by the explicit `brightness-test` command, which restores the original value in a `finally` path.

## Limitations

External monitors, macOS, and every OEM-specific display driver are not guaranteed in this release. Long-duration battery-drain measurements require separate testing on each supported laptop model.
