Skip to content

Conversation

@gmegidish
Copy link
Member

@gmegidish gmegidish commented Jan 1, 2026

Summary by CodeRabbit

  • New Features
    • Added configurable duration for long-press operations via a new command flag and API parameter.
    • Users can now customize press duration, with a default of 500ms if not specified.
    • Long-press confirmation messages now display the actual duration applied for improved transparency.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 1, 2026

Walkthrough

This PR extends the long-press functionality to accept a configurable duration parameter throughout the CLI, command layer, device implementations, and server API. The duration parameter propagates from command-line flags through device implementations to WDA client calls, with a default value of 500ms.

Changes

Cohort / File(s) Summary
CLI Integration
cli/io.go
Adds longPressDuration package variable and registers --duration command flag (default 500ms) for the ioLongPressCmd command.
Command Layer
commands/input.go
Adds Duration field to LongPressRequest struct; updates LongPressCommand invocation to pass three parameters (x, y, duration) instead of two; success message now includes duration in milliseconds.
Device Interface
devices/common.go
Updates ControllableDevice interface method signature: LongPress(x, y, duration int) error instead of LongPress(x, y int) error.
Device Implementations
devices/android.go, devices/ios.go, devices/simulator.go
Updates LongPress method signatures across all implementations to accept duration parameter; Android implementation uses duration in adb command instead of hardcoded "500"; iOS and Simulator implementations pass duration to underlying WDA client.
WDA Client
devices/wda/longpress.go
Updates WdaClient.LongPress method signature to accept duration parameter; uses provided duration for pause action instead of hardcoded 500ms value.
Server API
server/server.go
Adds Duration field to IoLongPressParams struct; introduces defaulting logic in handleIoLongPress to use 500ms when duration is not provided; passes resolved duration to underlying command.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a --duration flag to the io longpress command, which is reflected across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
commands/input.go (1)

80-98: Add validation for the duration parameter.

The duration parameter is passed through without validation. Consider adding bounds checking similar to the coordinate validation to prevent negative, zero, or unreasonably large duration values that could cause unexpected behavior.

🔎 Proposed validation
 func LongPressCommand(req LongPressRequest) *CommandResponse {
 	if req.X < 0 || req.Y < 0 {
 		return NewErrorResponse(fmt.Errorf("x and y coordinates must be non-negative, got x=%d, y=%d", req.X, req.Y))
 	}
+
+	if req.Duration <= 0 || req.Duration > 60000 {
+		return NewErrorResponse(fmt.Errorf("duration must be between 1 and 60000 milliseconds, got %d", req.Duration))
+	}
 
 	targetDevice, err := FindDeviceOrAutoSelect(req.DeviceID)
devices/simulator.go (1)

638-640: Consider adding duration validation.

The duration parameter is passed directly to the WDA client without validation. Consider adding bounds checking (e.g., duration > 0 and reasonable upper limit) to catch invalid values early and provide clearer error messages.

🔎 Suggested validation
 func (s SimulatorDevice) LongPress(x, y, duration int) error {
+	if duration <= 0 {
+		return fmt.Errorf("duration must be positive, got %d", duration)
+	}
+	if duration > 60000 {
+		return fmt.Errorf("duration %d ms exceeds maximum of 60000 ms", duration)
+	}
 	return s.wdaClient.LongPress(x, y, duration)
 }
devices/android.go (1)

322-329: Consider adding duration validation.

The duration parameter is passed directly to the adb command without validation. Consider adding bounds checking (e.g., duration > 0 and reasonable upper limit) to prevent invalid adb commands and provide clearer error messages.

🔎 Suggested validation
 func (d *AndroidDevice) LongPress(x, y, duration int) error {
+	if duration <= 0 {
+		return fmt.Errorf("duration must be positive, got %d", duration)
+	}
+	if duration > 60000 {
+		return fmt.Errorf("duration %d ms exceeds maximum of 60000 ms", duration)
+	}
 	_, err := d.runAdbCommand("shell", "input", "swipe", fmt.Sprintf("%d", x), fmt.Sprintf("%d", y), fmt.Sprintf("%d", x), fmt.Sprintf("%d", y), fmt.Sprintf("%d", duration))
 	if err != nil {
 		return err
 	}

 	return nil
 }
devices/wda/longpress.go (1)

7-37: Consider adding duration validation and documentation.

The implementation correctly uses the duration parameter in the pause action. However, consider:

  1. Adding bounds checking for the duration parameter (e.g., positive value, reasonable upper limit)
  2. Adding a comment documenting that duration is in milliseconds
🔎 Suggested improvements
+// LongPress performs a long press at the specified coordinates for the given duration (in milliseconds).
 func (c *WdaClient) LongPress(x, y, duration int) error {
+	if duration <= 0 {
+		return fmt.Errorf("duration must be positive, got %d", duration)
+	}
+	if duration > 60000 {
+		return fmt.Errorf("duration %d ms exceeds maximum of 60000 ms", duration)
+	}

 	sessionId, err := c.GetOrCreateSession()
 	if err != nil {
 		return err
 	}
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b09091 and db2a3d9.

📒 Files selected for processing (8)
  • cli/io.go
  • commands/input.go
  • devices/android.go
  • devices/common.go
  • devices/ios.go
  • devices/simulator.go
  • devices/wda/longpress.go
  • server/server.go
🧰 Additional context used
🧬 Code graph analysis (3)
server/server.go (1)
commands/input.go (1)
  • LongPressRequest (19-24)
devices/wda/longpress.go (1)
devices/wda/types.go (1)
  • WdaClient (10-15)
commands/input.go (1)
commands/commands.go (2)
  • NewErrorResponse (26-31)
  • NewSuccessResponse (18-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lint
🔇 Additional comments (4)
cli/io.go (1)

56-56: LGTM! Duration parameter properly wired through CLI.

The duration flag is well-integrated with a sensible default of 500ms and clear documentation. The implementation follows the existing pattern used for other flags.

Also applies to: 85-85, 192-192

server/server.go (1)

281-281: LGTM! Good backward compatibility with default duration.

The defaulting logic ensures backward compatibility for API clients that don't provide a duration parameter, falling back to 500ms. This is a solid approach that maintains existing behavior while enabling the new functionality.

Also applies to: 326-337

devices/ios.go (1)

142-144: LGTM! Clean pass-through implementation.

The LongPress implementation correctly accepts the duration parameter and delegates to the WDA client. The implementation is straightforward and consistent with the updated interface.

devices/common.go (1)

54-54: All ControllableDevice implementations have been correctly updated to match the new LongPress signature. Verified implementations in SimulatorDevice, IOSDevice, AndroidDevice, and the underlying WdaClient all use the signature LongPress(x, y, duration int) error. The interface change is complete and consistent across all implementations.

@gmegidish gmegidish merged commit dc34245 into main Jan 1, 2026
14 checks passed
@gmegidish gmegidish deleted the feat-add-duration-to-longpress branch January 1, 2026 18:41
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.

2 participants