# WebDrop Bridge

> Professional Qt-based desktop application for intelligent drag-and-drop file handling between web applications and desktop clients (InDesign, Word, Notepad++, etc.)

![Status](https://img.shields.io/badge/Status-Phase%204%20Complete-green) ![License](https://img.shields.io/badge/License-MIT-blue) ![Python](https://img.shields.io/badge/Python-3.10%2B-blue)

## Overview

WebDrop Bridge is a sophisticated desktop bridge application that intercepts text-based drag-and-drop operations from embedded web applications and converts them into native file-drag operations recognized by professional desktop applications.

### The Problem
Modern web applications can transmit file paths via drag-and-drop, but desktop applications expect native file handles. Traditional solutions fail because:
- Browsers sandbox cross-origin drag-and-drop
- Web apps can't access the file system directly
- Native apps need OS-level file handles (CF_HDROP on Windows, NSFilenamesPboardType on macOS)

### The Solution
WebDrop Bridge embeds a web application in a Qt container with full filesystem access, intelligently intercepting and converting drag operations at the OS boundary.

## Features

- ✅ **Qt-based Architecture** - Professional Windows support via PySide6 (macOS support planned)
- ✅ **Embedded Web App** - QtWebEngine provides Chromium without browser limitations
- ✅ **Drag Interception** - Converts text paths to native file operations
- ✅ **Path Whitelist** - Security-conscious file system access control
- ✅ **Configuration Management** - Profile-based settings with validation
- ✅ **Settings Dialog** - Professional UI for path, URL, logging, and window configuration
- ✅ **Auto-Update System** - Automatic release detection via Forgejo API
- ✅ **Professional Build Pipeline** - MSI for Windows, DMG for macOS
- ✅ **Comprehensive Testing** - Unit, integration, and end-to-end tests (80%+ coverage)
- ✅ **Continuous Testing** - GitHub Actions test automation
- ✅ **Structured Logging** - File-based logging with configurable levels

## Quick Start

### Requirements
- Python 3.10+
- Windows 10/11
- 200 MB disk space (includes Chromium from PyInstaller)

### Installation from Source

```bash
# Clone repository
git clone https://git.him-tools.de/HIM-public/webdrop-bridge.git
cd webdrop-bridge

# Create and activate virtual environment
python -m venv venv
# venv\Scripts\activate.ps1       # Windows (PowerShell)
# venv\Scripts\activate.bat       # Windows (cmd.exe)

# Install dependencies
pip install -r requirements.txt

# Run application
python -m webdrop_bridge.main
```

### Development Setup

```bash
# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
pytest tests -v

# Run all quality checks (lint, type, format)
tox

# Build installers
python build/scripts/build_windows.py --msi    # Windows MSI
```

## Project Structure

```
webdrop-bridge/
├── src/webdrop_bridge/          # Main application package
│   ├── core/                    # Core logic (drag interception, config)
│   ├── ui/                      # UI components (main window, widgets)
│   ├── utils/                   # Utilities (logging, validation)
│   ├── main.py                  # Entry point
│   └── config.py                # Configuration management
├── tests/
│   ├── unit/                    # Unit tests
│   ├── integration/             # Integration tests
│   ├── fixtures/                # Test data and fixtures
│   └── conftest.py              # Pytest configuration
├── build/
│   ├── windows/                 # Windows-specific build configs
│   └── scripts/                 # Build automation scripts
├── webapp/                      # Embedded web application
├── resources/
│   ├── icons/                   # Application icons
│   └── stylesheets/            # Qt stylesheets
├── docs/                        # Documentation
├── pyproject.toml               # Modern Python packaging
├── pytest.ini                   # Test configuration
├── tox.ini                      # Test automation
└── README.md                    # This file
```

## Architecture

```
┌────────────────────────────────────────┐
│  Qt Main Window (PySide6)              │
│  ┌──────────────────────────────────┐  │
│  │  QtWebEngineView                 │  │
│  │  ┌────────────────────────────┐  │  │
│  │  │  Web Application (HTML/JS) │  │  │
│  │  │  • Drag with file paths    │  │  │
│  │  │  • Native drag operations  │  │  │
│  │  └────────────────────────────┘  │  │
│  └──────────────────────────────────┘  │
│         ↓ Drag Leave Event              │
│  ┌──────────────────────────────────┐  │
│  │  DragInterceptor                 │  │
│  │  • Validates path (whitelist)    │  │
│  │  • Creates QUrl + QMimeData      │  │
│  │  • Starts native file drag       │  │
│  └──────────────────────────────────┘  │
└────────────────────────────────────────┘
         ↓ Native File Drag
   ┌─────────────────┐
   │ InDesign/Word   │
   │ (receives file) │
   └─────────────────┘
```

## Configuration

WebDrop Bridge supports two configuration methods:

### 1. Settings Dialog (Recommended)
Launch the application and access the Settings menu to configure:
- **Paths Tab** - Add/remove allowed root directories
- **URLs Tab** - Configure allowed web URLs (whitelist mode)
- **Logging Tab** - Set log level and file location
- **Window Tab** - Configure window dimensions
- **Profiles Tab** - Save/load/export-import configuration profiles

Profiles are saved in `~/.webdrop-bridge/profiles/`

### 2. Environment Variables
Create a `.env` file in the project root. Available settings:

```bash
# Application
APP_NAME=WebDrop Bridge
APP_VERSION=1.0.0

# Paths (comma-separated)
ALLOWED_ROOTS=Z:/,C:/Users/Public

# Web URLs (empty = no restriction, items = kiosk mode)
ALLOWED_URLS=

# Interface
WEBAPP_URL=file:///./webapp/index.html
WINDOW_WIDTH=1024
WINDOW_HEIGHT=768

# Logging
LOG_LEVEL=INFO
ENABLE_LOGGING=true
```

## Testing

WebDrop Bridge includes comprehensive test coverage with unit, integration, and end-to-end tests.

```bash
# Run all tests
pytest tests -v

# Run with coverage report
pytest tests --cov=src/webdrop_bridge --cov-report=html

# Run specific test categories
pytest tests/unit -v                    # Unit tests only
pytest tests/integration -v             # Integration tests only

# Run specific test
pytest tests/unit/test_validator.py -v

# Run tests matching a pattern
pytest tests -k "config" -v
```

**Test Coverage**: 
- Current target: 80%+
- Coverage report: `htmlcov/index.html`

Integration tests cover:
- Drag-and-drop workflow
- Update flow and release detection
- End-to-end application scenarios

## Auto-Update System

WebDrop Bridge includes an intelligent auto-update system that:

- **Automatic Detection**: Periodically checks Forgejo/GitHub releases API
- **Smart Caching**: Avoids redundant network calls with smart caching
- **User Notification**: Alerts users of available updates via UI
- **Release Notes**: Displays release notes and changes
- **Safe Deployment**: Only triggers on newer versions

The update system is fully integrated with the application and runs in the background without blocking the UI.

For technical details, see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md#update-system).

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for release notes.

## Building Installers

### Windows MSI Installer

```bash
# Build with MSI installer (recommended)
python build/scripts/build_windows.py --msi

# Build with code signing (requires certificate)
python build/scripts/build_windows.py --msi --code-sign
```

Output:
- Portable executable: `build/dist/windows/WebDropBridge/WebDropBridge.exe` (~195 MB)
- Professional MSI installer: `build/dist/windows/WebDropBridge-{version}-Setup.msi`
- SHA256 checksum: `build/dist/windows/WebDropBridge/WebDropBridge.exe.sha256`

**Note on macOS**: Build scripts exist for macOS (DMG generation), but have never been built or tested. macOS support is theoretical at this point. The Qt/PySide6 architecture should support macOS, but platform-specific testing and validation would be required.

### Creating Releases

For Forgejo/GitHub releases:

```bash
# Windows - Create release with MSI installer
powershell -ExecutionPolicy Bypass -File build/scripts/create_release.ps1
```

## Development Workflow

1. **Create feature branch**
   ```bash
   git checkout -b feature/my-feature
   ```

2. **Write tests first**
   ```bash
   pytest tests/unit/test_my_feature.py
   ```

3. **Implement feature**
   ```bash
   # Edit src/webdrop_bridge/...
   ```

4. **Run quality checks**
   ```bash
   tox -e lint,type  # Run linting and type checking
   ```

5. **Submit pull request**

## Troubleshooting

### Application won't start
- Ensure Python 3.10+ is installed
- Check `logs/webdrop_bridge.log` for errors
- Verify all dependencies: `pip list`

### Drag-and-drop not working
- Verify paths in `.env` are valid
- Check `ALLOWED_ROOTS` whitelist includes your test directory
- On macOS, check System Preferences → Security & Privacy → Accessibility

### Build errors
- Clean build directory: `rm -rf build/temp build/dist`
- Reinstall dependencies: `pip install --force-reinstall -r requirements.txt`
- Check platform-specific requirements (Windows SDK, Xcode for macOS)

## Platform Support

| Platform | Version | Status | Notes |
|----------|---------|--------|-------|
| Windows | 10, 11 | ✅ Full | Tested on x64, MSI installer support |
| macOS | 12+ | ⚠️ **Untested** | Possible via Qt/PySide6, but never built or tested. Theoretical support only. |

**Note**: WebDrop Bridge is currently developed and tested exclusively on Windows. While the Qt/PySide6 framework supports macOS, we cannot guarantee functionality without actual macOS testing and validation. Contributions for macOS support validation are welcome.

## Contributing

We welcome contributions! Please:

1. Fork the repository
2. Create a feature branch
3. Write/update tests
4. Submit a pull request
5. Ensure CI passes

See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.

## License

MIT License - see [LICENSE](LICENSE) file for details

## Credits

- Built with [PySide6](https://wiki.qt.io/Qt_for_Python)
- Inspired by professional desktop integration practices
- Special thanks to the Qt community

## Development Status

**Current Phase**: Phase 4 Complete - Phase 5 (Release Candidates) Planned

**Completed**:
- ✅ Phase 1: Core Components (Validator, Config, Drag Interceptor, Main Window)
- ✅ Phase 2: Testing & Quality (99 tests, 85%+ coverage)
- ✅ Phase 3: Build & Distribution (Windows MSI, macOS DMG, Release Scripts)
- ✅ Phase 4.1: Auto-Update System (Forgejo API integration, 76 tests)
- ✅ Phase 4.2: Enhanced Logging & Monitoring (20 tests, JSON logging, performance tracking)
- ✅ Phase 4.3: Advanced Configuration (Profiles, Validation, Settings UI, 43 tests)
- ✅ **Total Phase 4**: 139 tests passing, 90%+ coverage

**In Progress/Planned**:
- Phase 4.4: User Documentation (manuals, tutorials, guides)
- Phase 5: Release Candidates & Final Testing (v1.0.0 stable release)
- Post-Release: Analytics, Community Support

## Roadmap

- [x] Core drag-drop functionality
- [x] Configuration management with profiles
- [x] Auto-update system
- [x] Professional build pipeline
- [x] Comprehensive test suite
- [ ] Performance benchmarking & optimization
- [ ] Security audit & hardening
- [ ] v1.1 - Advanced filtering and extended logging
- [ ] v1.2 - API for custom handlers
- [ ] v2.0 - Plugin architecture

## Support

- 📖 [Documentation](https://git.him-tools.de/HIM-public/webdrop-bridge/wiki)
- 🐛 [Issue Tracker](https://git.him-tools.de/HIM-public/webdrop-bridge/issues)
- 📦 [Releases](https://git.him-tools.de/HIM-public/webdrop-bridge/releases)

---

**Development Phase**: Phase 4 Complete | **Last Updated**: February 18, 2026 | **Current Version**: 1.0.0 | **Python**: 3.10+ | **Qt**: PySide6 (Qt 6)
