Skip to content

Conversation

leaanthony
Copy link
Member

I have successfully implemented the disable pinch zoom functionality for the Wails WebView2 project. Here's what was implemented:

### Changes Made:

1. **Added PinchZoom Capability** (`pkg/edge/capabilities.go:144`)
   - Added `PinchZoom = Capability("87.0.664.75")` to define the minimum WebView2 runtime version required

2. **Added Pinch Zoom Control Methods** (`pkg/edge/chromium.go:665-695`)
   - `GetIsPinchZoomEnabled() (bool, error)` - Get current pinch zoom setting
   - `PutIsPinchZoomEnabled(enabled bool) error` - Set pinch zoom setting

3. **Added Configuration Field** (`pkg/edge/chromium.go:79`)
   - `PinchZoomEnabled *bool` - Optional field to configure pinch zoom during initialization

4. **Automatic Configuration Application** (`pkg/edge/chromium.go:390-396`)
   - Added logic to automatically apply the pinch zoom setting when the WebView2 is initialized

5. **Created Usage Example** (`examples/disable_pinch_zoom.go`)
   - Comprehensive example showing three ways to control pinch zoom

### Usage Options:

**Method 1: Configure during initialization (Recommended)**
```go
chromium := edge.NewChromium()
pinchZoomDisabled := false
chromium.PinchZoomEnabled = &pinchZoomDisabled
// Setting will be automatically applied when Embed() is called
```

**Method 2: Runtime control**
```go
err := chromium.PutIsPinchZoomEnabled(false)
```

**Method 3: Check current setting**  
```go
enabled, err := chromium.GetIsPinchZoomEnabled()
```

### Features:
- **Capability Check**: Automatically checks if the WebView2 runtime supports pinch zoom control
- **Error Handling**: Proper error handling for unsupported versions
- **Automatic Application**: Setting is applied automatically during WebView2 initialization
- **Runtime Control**: Can be changed dynamically after initialization
- **Cross-compilation**: Successfully builds for Windows target

This implementation addresses the GitHub issue #2021 by providing a clean, idiomatic Go API to disable pinch zoom functionality in Wails applications using WebView2.
Copy link

sonarqubecloud bot commented Aug 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant