-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdispatch.go
More file actions
60 lines (54 loc) · 2.29 KB
/
Copy pathdispatch.go
File metadata and controls
60 lines (54 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package server
import (
"encoding/json"
"fmt"
)
// HandlerFunc is the signature for non-streaming JSON-RPC method handlers
type HandlerFunc func(params json.RawMessage) (any, error)
// GetMethodRegistry returns a map of method names to handler functions
// This is used by both the HTTP server and embedded clients
func GetMethodRegistry() map[string]HandlerFunc {
return map[string]HandlerFunc{
"devices.list": handleDevicesList,
"device.screenshot": handleScreenshot,
"device.screencapture": handleScreenCaptureSession,
"device.io.tap": handleIoTap,
"device.io.longpress": handleIoLongPress,
"device.io.text": handleIoText,
"device.io.button": handleIoButton,
"device.io.swipe": handleIoSwipe,
"device.io.gesture": handleIoGesture,
"device.url": handleURL,
"device.info": handleDeviceInfo,
"device.io.orientation.get": handleIoOrientationGet,
"device.io.orientation.set": handleIoOrientationSet,
"device.io.animation-scales.get": handleIoAnimationScalesGet,
"device.io.animation-scales.set": handleIoAnimationScalesSet,
"device.boot": handleDeviceBoot,
"device.shutdown": handleDeviceShutdown,
"device.reboot": handleDeviceReboot,
"device.dump.ui": handleDumpUI,
"device.apps.launch": handleAppsLaunch,
"device.apps.terminate": handleAppsTerminate,
"device.apps.list": handleAppsList,
"device.apps.foreground": handleAppsForeground,
"device.apps.install": handleAppsInstall,
"device.apps.uninstall": handleAppsUninstall,
"device.screenrecord": handleScreenRecord,
"device.screenrecord.stop": handleScreenRecordStop,
"device.crashes.list": handleCrashesList,
"device.crashes.get": handleCrashesGet,
"server.info": handleServerInfo,
"server.shutdown": handleServerShutdown,
}
}
// Execute dispatches a method call using the registry
// This is the main entry point for embedded clients
func Execute(method string, params json.RawMessage) (any, error) {
registry := GetMethodRegistry()
handler, exists := registry[method]
if !exists {
return nil, fmt.Errorf("method not found: %s", method)
}
return handler(params)
}