rust_droid/config.rs
1use std::net::{Ipv4Addr, SocketAddrV4};
2use std::time::Duration;
3
4/// Configuration for a `Droid` instance.
5#[derive(Debug, Clone)]
6pub struct DroidConfig {
7 /// The address and port of the ADB server.
8 pub adb_server_addr: SocketAddrV4,
9 /// The serial number of the specific device to connect to.
10 /// If `None`, the first available device will be used.
11 pub device_serial: Option<String>,
12 /// The default timeout duration for operations like `wait_for`.
13 pub default_timeout: Duration,
14 /// The default polling interval for `wait_for` operations.
15 pub default_interval: Duration,
16 /// The default confidence threshold for image template matching (0.0 to 1.0).
17 pub default_confidence: f32,
18}
19
20impl Default for DroidConfig {
21 /// Provides a reasonable default configuration.
22 /// - ADB Server: `127.0.0.1:5037`
23 /// - Device: Auto-select first available
24 /// - Timeout: 20 seconds
25 /// - Interval: 0.5 seconds
26 /// - Confidence: 0.8
27 fn default() -> Self {
28 Self {
29 adb_server_addr: SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037),
30 device_serial: None,
31 default_timeout: Duration::from_secs(20),
32 default_interval: Duration::from_millis(500),
33 default_confidence: 0.8,
34 }
35 }
36}
37
38impl DroidConfig {
39 /// Sets the ADB server address (IP and port).
40 pub fn address(mut self, addr: SocketAddrV4) -> Self {
41 self.adb_server_addr = addr;
42 self
43 }
44
45 /// Sets the serial number of the specific device to connect to.
46 pub fn serial(mut self, serial: String) -> Self {
47 self.device_serial = Some(serial);
48 self
49 }
50
51 /// Sets the default timeout duration.
52 pub fn timeout(mut self, timeout: Duration) -> Self {
53 self.default_timeout = timeout;
54 self
55 }
56
57 /// Sets the default confidence threshold for image matching.
58 /// The value will be clamped between 0.0 and 1.0.
59 pub fn confidence(mut self, confidence: f32) -> Self {
60 self.default_confidence = confidence.clamp(0.0, 1.0);
61 self
62 }
63}