|
| 1 | +part of '../server.dart'; |
| 2 | + |
| 3 | +extension _BfBatch on FlutterMcpServer { |
| 4 | + Future<dynamic> _handleBatchCoordTool(String name, Map<String, dynamic> args, AppDriver? client) async { |
| 5 | + switch (name) { |
| 6 | + case 'execute_batch': |
| 7 | + if (client is BridgeDriver) { |
| 8 | + final actions = args['actions'] as List? ?? []; |
| 9 | + final results = <Map<String, dynamic>>[]; |
| 10 | + for (final action in actions) { |
| 11 | + if (action is Map<String, dynamic>) { |
| 12 | + final toolName = action['tool'] as String?; |
| 13 | + final toolArgs = Map<String, dynamic>.from(action['args'] as Map? ?? {}); |
| 14 | + if (toolName != null) { |
| 15 | + try { |
| 16 | + final result = await client.callMethod(toolName, toolArgs); |
| 17 | + results.add({'tool': toolName, 'success': true, 'result': result}); |
| 18 | + } catch (e) { |
| 19 | + results.add({'tool': toolName, 'success': false, 'error': e.toString()}); |
| 20 | + } |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | + return {"success": true, "results": results, "count": results.length}; |
| 25 | + } |
| 26 | + final fc = _asFlutterClient(client!, 'execute_batch'); |
| 27 | + return await _executeBatch(args, fc); |
| 28 | + |
| 29 | + // === NEW: Coordinate-based Actions === |
| 30 | + case 'tap_at': |
| 31 | + if (client is BridgeDriver) { |
| 32 | + await client.callMethod('tap_at', {'x': (args['x'] as num).toDouble(), 'y': (args['y'] as num).toDouble()}); |
| 33 | + return {"success": true, "action": "tap_at", "x": args['x'], "y": args['y']}; |
| 34 | + } |
| 35 | + final fc = _asFlutterClient(client!, 'tap_at'); |
| 36 | + final x = (args['x'] as num).toDouble(); |
| 37 | + final y = (args['y'] as num).toDouble(); |
| 38 | + await fc.tapAt(x, y); |
| 39 | + return {"success": true, "action": "tap_at", "x": x, "y": y}; |
| 40 | + |
| 41 | + case 'long_press_at': |
| 42 | + if (client is BridgeDriver) { |
| 43 | + await client.callMethod('long_press_at', {'x': (args['x'] as num).toDouble(), 'y': (args['y'] as num).toDouble(), 'duration': args['duration'] ?? 500}); |
| 44 | + return {"success": true, "action": "long_press_at", "x": args['x'], "y": args['y']}; |
| 45 | + } |
| 46 | + final fc = _asFlutterClient(client!, 'long_press_at'); |
| 47 | + final x = (args['x'] as num).toDouble(); |
| 48 | + final y = (args['y'] as num).toDouble(); |
| 49 | + final duration = args['duration'] ?? 500; |
| 50 | + await fc.longPressAt(x, y, duration: duration); |
| 51 | + return {"success": true, "action": "long_press_at", "x": x, "y": y}; |
| 52 | + |
| 53 | + case 'swipe_coordinates': |
| 54 | + if (client is BridgeDriver) { |
| 55 | + await client.callMethod('swipe_coordinates', { |
| 56 | + 'start_x': ((args['start_x'] ?? args['startX']) as num).toDouble(), |
| 57 | + 'start_y': ((args['start_y'] ?? args['startY']) as num).toDouble(), |
| 58 | + 'end_x': ((args['end_x'] ?? args['endX']) as num).toDouble(), |
| 59 | + 'end_y': ((args['end_y'] ?? args['endY']) as num).toDouble(), |
| 60 | + 'duration': args['duration'] ?? args['durationMs'] ?? 300, |
| 61 | + }); |
| 62 | + return {"success": true, "action": "swipe_coordinates"}; |
| 63 | + } |
| 64 | + final fc = _asFlutterClient(client!, 'swipe_coordinates'); |
| 65 | + final startX = ((args['start_x'] ?? args['startX']) as num).toDouble(); |
| 66 | + final startY = ((args['start_y'] ?? args['startY']) as num).toDouble(); |
| 67 | + final endX = ((args['end_x'] ?? args['endX']) as num).toDouble(); |
| 68 | + final endY = ((args['end_y'] ?? args['endY']) as num).toDouble(); |
| 69 | + final duration = args['duration'] ?? 300; |
| 70 | + await fc.swipeCoordinates(startX, startY, endX, endY, |
| 71 | + duration: duration); |
| 72 | + return {"success": true, "action": "swipe_coordinates"}; |
| 73 | + |
| 74 | + case 'edge_swipe': |
| 75 | + if (client is BridgeDriver) { |
| 76 | + return await client.callMethod('edge_swipe', {'edge': args['edge'], 'direction': args['direction'], 'distance': (args['distance'] as num?)?.toDouble() ?? 200}); |
| 77 | + } |
| 78 | + final fc = _asFlutterClient(client!, 'edge_swipe'); |
| 79 | + final edge = args['edge'] as String; |
| 80 | + final direction = args['direction'] as String; |
| 81 | + final distance = (args['distance'] as num?)?.toDouble() ?? 200; |
| 82 | + final result = await fc.edgeSwipe( |
| 83 | + edge: edge, direction: direction, distance: distance); |
| 84 | + return result; |
| 85 | + |
| 86 | + case 'gesture': |
| 87 | + if (client is BridgeDriver) { |
| 88 | + return await client.callMethod('gesture', args); |
| 89 | + } |
| 90 | + final fc = _asFlutterClient(client!, 'gesture'); |
| 91 | + return await _performGesture(args, fc); |
| 92 | + |
| 93 | + case 'wait_for_idle': |
| 94 | + if (client is BridgeDriver) { |
| 95 | + return {"success": true, "message": "Bridge platform ready"}; |
| 96 | + } |
| 97 | + final fc = _asFlutterClient(client!, 'wait_for_idle'); |
| 98 | + return await _waitForIdle(args, fc); |
| 99 | + |
| 100 | + // === NEW: Smart Scroll === |
| 101 | + case 'scroll_until_visible': |
| 102 | + if (client is BridgeDriver) { |
| 103 | + return await client.callMethod('scroll_until_visible', {'key': args['key'], 'text': args['text'], 'direction': args['direction'] ?? 'down', 'max_scrolls': args['max_scrolls'] ?? 10}); |
| 104 | + } |
| 105 | + final fc = _asFlutterClient(client!, 'scroll_until_visible'); |
| 106 | + return await _scrollUntilVisible(args, fc); |
| 107 | + |
| 108 | + // === Batch Assertions === |
| 109 | + default: |
| 110 | + return null; |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments