-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add --duration to io longpress #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis 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
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this 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 > 0and 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 > 0and 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:
- Adding bounds checking for the duration parameter (e.g., positive value, reasonable upper limit)
- 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
📒 Files selected for processing (8)
cli/io.gocommands/input.godevices/android.godevices/common.godevices/ios.godevices/simulator.godevices/wda/longpress.goserver/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: AllControllableDeviceimplementations have been correctly updated to match the newLongPresssignature. Verified implementations inSimulatorDevice,IOSDevice,AndroidDevice, and the underlyingWdaClientall use the signatureLongPress(x, y, duration int) error. The interface change is complete and consistent across all implementations.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.