pub struct Tasker { /* private fields */ }Expand description
Task manager for executing pipelines.
Tasker is the central component that coordinates:
- Resource binding (images, models)
- Controller binding (device connection)
- Task execution (pipelines)
- Event handling (callbacks)
Implementations§
Source§impl Tasker
impl Tasker
Sourcepub fn new() -> MaaResult<Self>
pub fn new() -> MaaResult<Self>
Create a new Tasker instance.
Examples found in repository?
201fn main() -> Result<(), Box<dyn std::error::Error>> {
202 println!("=== MaaFramework Rust SDK Demo ===\n");
203
204 // -------------------------------------------------------------------------
205 // 1. Initialize Toolkit
206 // -------------------------------------------------------------------------
207 let user_path = "./";
208 Toolkit::init_option(user_path, "{}")?;
209 println!("[1] Toolkit initialized with user_path: {}", user_path);
210
211 // -------------------------------------------------------------------------
212 // 2. Device Discovery
213 // -------------------------------------------------------------------------
214
215 // ADB devices
216 println!("\n[2] Scanning for ADB devices...");
217 let adb_devices = Toolkit::find_adb_devices()?;
218 if adb_devices.is_empty() {
219 println!(" No ADB device found.");
220 } else {
221 for device in &adb_devices {
222 println!(" Found: {} ({})", device.name, device.address);
223 }
224 }
225
226 // Win32 windows (Windows only)
227 #[cfg(target_os = "windows")]
228 {
229 println!("\n Scanning for desktop windows...");
230 match Toolkit::find_desktop_windows() {
231 Ok(windows) => {
232 if windows.is_empty() {
233 println!(" No window found.");
234 } else {
235 for (i, win) in windows.iter().take(3).enumerate() {
236 println!(" [{}] hwnd={:?}, class={}", i, win.hwnd, win.class_name);
237 }
238 if windows.len() > 3 {
239 println!(" ... and {} more", windows.len() - 3);
240 }
241 }
242 }
243 Err(e) => println!(" Failed to find windows: {}", e),
244 }
245 }
246
247 // -------------------------------------------------------------------------
248 // 3. Create Controller (choose one)
249 // -------------------------------------------------------------------------
250 println!("\n[3] Creating controller...");
251
252 let controller: Option<Controller>;
253
254 // Option A: ADB Controller
255 #[cfg(feature = "adb")]
256 if let Some(device) = adb_devices.first() {
257 println!(" Using ADB device: {}", device.name);
258 let config_str = serde_json::to_string(&device.config)?;
259 controller = Some(Controller::new_adb(
260 device.adb_path.to_str().unwrap(),
261 &device.address,
262 &config_str,
263 None,
264 )?);
265 } else {
266 controller = None;
267 }
268
269 #[cfg(not(feature = "adb"))]
270 {
271 controller = None;
272 }
273
274 // Option B: Win32 Controller (uncomment to use)
275 // #[cfg(target_os = "windows")]
276 // if let Some(window) = windows.first() {
277 // controller = Some(Controller::new_win32(
278 // window.hwnd as isize,
279 // common::Win32ScreencapMethod::FramePool as i32,
280 // common::Win32InputMethod::PostMessage as i32,
281 // common::Win32InputMethod::PostMessage as i32,
282 // )?);
283 // }
284
285 // -------------------------------------------------------------------------
286 // 4. Controller Operations
287 // -------------------------------------------------------------------------
288 if let Some(ref ctrl) = controller {
289 println!("\n[4] Controller operations...");
290
291 // Connect
292 let conn_id = ctrl.post_connection()?;
293 ctrl.wait(conn_id);
294 println!(" Connected: {}", ctrl.connected());
295
296 // Screenshot
297 let cap_id = ctrl.post_screencap()?;
298 ctrl.wait(cap_id);
299 println!(" Screenshot captured");
300
301 // Click (sync)
302 let click_id = ctrl.post_click(114, 514)?;
303 ctrl.wait(click_id);
304 println!(" Clicked at (114, 514)");
305
306 // Click (async) - post now, wait later
307 let click_id2 = ctrl.post_click(514, 114)?;
308 // ... do other work here ...
309 ctrl.wait(click_id2);
310 println!(" Async click completed");
311
312 // Input text
313 let input_id = ctrl.post_input_text("Hello MAA!")?;
314 ctrl.wait(input_id);
315 println!(" Text input sent");
316
317 // Get resolution
318 if let Ok((w, h)) = ctrl.resolution() {
319 println!(" Resolution: {}x{}", w, h);
320 }
321 } else {
322 println!("\n[4] Skipping controller operations (no device available)");
323 }
324
325 // -------------------------------------------------------------------------
326 // 5. Resource Setup
327 // -------------------------------------------------------------------------
328 println!("\n[5] Setting up resource...");
329
330 let resource = Resource::new()?;
331
332 // Register custom recognition and action
333 resource.register_custom_recognition("MyRecognition", Box::new(MyRecognition))?;
334 resource.register_custom_action("MyAction", Box::new(MyAction))?;
335 println!(" Registered: MyRecognition, MyAction");
336
337 // List registered components
338 let reco_list = resource.custom_recognition_list()?;
339 let action_list = resource.custom_action_list()?;
340 println!(" Recognition list: {:?}", reco_list);
341 println!(" Action list: {:?}", action_list);
342
343 // Load resource bundle
344 let resource_path = "sample/resource";
345 println!(" Loading resource from: {}", resource_path);
346 match resource.post_bundle(resource_path) {
347 Ok(job) => {
348 let status = job.wait();
349 println!(" Load status: {:?}", status);
350 }
351 Err(e) => println!(" Load failed: {} (OK for demo)", e),
352 }
353
354 // Add event sink
355 resource.add_sink(|msg, details| {
356 println!(
357 " [ResourceEvent] {}: {}",
358 msg,
359 &details[..details.len().min(50)]
360 );
361 })?;
362
363 // -------------------------------------------------------------------------
364 // 6. Tasker Setup and Execution
365 // -------------------------------------------------------------------------
366 println!("\n[6] Setting up tasker...");
367
368 let tasker = Tasker::new()?;
369
370 // Bind resource
371 tasker.bind_resource(&resource)?;
372 println!(" Resource bound");
373
374 // Bind controller (if available)
375 if let Some(ref ctrl) = controller {
376 tasker.bind_controller(ctrl)?;
377 println!(" Controller bound");
378 }
379
380 // Check initialization
381 if tasker.inited() {
382 println!(" Tasker initialized successfully!");
383
384 // Add event sink
385 tasker.add_sink(|msg, details| {
386 println!(
387 " [TaskerEvent] {}: {}",
388 msg,
389 &details[..details.len().min(50)]
390 );
391 })?;
392
393 // Execute task with pipeline override
394 let pipeline_override = r#"{
395 "MyCustomEntry": {
396 "recognition": "Custom",
397 "custom_recognition": "MyRecognition",
398 "action": "Custom",
399 "custom_action": "MyAction"
400 }
401 }"#;
402
403 println!("\n[7] Executing task...");
404 match tasker.post_task("MyCustomEntry", pipeline_override) {
405 Ok(job) => {
406 let status = job.wait();
407 println!(" Task status: {:?}", status);
408
409 if let Ok(Some(detail)) = job.get(false) {
410 println!(" Entry: {}", detail.entry);
411 println!(" Nodes executed: {}", detail.nodes.len());
412
413 for node_opt in detail.nodes {
414 if let Some(node) = node_opt {
415 if let Some(reco) = node.recognition {
416 println!(
417 " Node: {}, Algo: {:?}",
418 node.node_name, reco.algorithm
419 );
420 }
421 }
422 }
423 }
424 }
425 Err(e) => println!(" Task failed: {}", e),
426 }
427 } else {
428 println!(" Tasker not fully initialized (missing controller binding)");
429 }
430
431 // -------------------------------------------------------------------------
432 // 8. Cleanup
433 // -------------------------------------------------------------------------
434 println!("\n[8] Demo completed!");
435 println!(" - Toolkit, Controller, Resource, Tasker all demonstrated");
436 println!(" - Custom Recognition and Action registered and explained");
437 println!(" - Context API documented in custom component implementations");
438
439 Ok(())
440}Sourcepub unsafe fn from_raw(ptr: *mut MaaTasker, owns: bool) -> MaaResult<Self>
pub unsafe fn from_raw(ptr: *mut MaaTasker, owns: bool) -> MaaResult<Self>
Create a Tasker from a raw pointer.
§Safety
The pointer must be valid.
If owns is true, the Tasker will destroy the handle when dropped.
Sourcepub fn bind_resource(&self, res: &Resource) -> MaaResult<()>
pub fn bind_resource(&self, res: &Resource) -> MaaResult<()>
Bind a resource to this tasker.
Examples found in repository?
201fn main() -> Result<(), Box<dyn std::error::Error>> {
202 println!("=== MaaFramework Rust SDK Demo ===\n");
203
204 // -------------------------------------------------------------------------
205 // 1. Initialize Toolkit
206 // -------------------------------------------------------------------------
207 let user_path = "./";
208 Toolkit::init_option(user_path, "{}")?;
209 println!("[1] Toolkit initialized with user_path: {}", user_path);
210
211 // -------------------------------------------------------------------------
212 // 2. Device Discovery
213 // -------------------------------------------------------------------------
214
215 // ADB devices
216 println!("\n[2] Scanning for ADB devices...");
217 let adb_devices = Toolkit::find_adb_devices()?;
218 if adb_devices.is_empty() {
219 println!(" No ADB device found.");
220 } else {
221 for device in &adb_devices {
222 println!(" Found: {} ({})", device.name, device.address);
223 }
224 }
225
226 // Win32 windows (Windows only)
227 #[cfg(target_os = "windows")]
228 {
229 println!("\n Scanning for desktop windows...");
230 match Toolkit::find_desktop_windows() {
231 Ok(windows) => {
232 if windows.is_empty() {
233 println!(" No window found.");
234 } else {
235 for (i, win) in windows.iter().take(3).enumerate() {
236 println!(" [{}] hwnd={:?}, class={}", i, win.hwnd, win.class_name);
237 }
238 if windows.len() > 3 {
239 println!(" ... and {} more", windows.len() - 3);
240 }
241 }
242 }
243 Err(e) => println!(" Failed to find windows: {}", e),
244 }
245 }
246
247 // -------------------------------------------------------------------------
248 // 3. Create Controller (choose one)
249 // -------------------------------------------------------------------------
250 println!("\n[3] Creating controller...");
251
252 let controller: Option<Controller>;
253
254 // Option A: ADB Controller
255 #[cfg(feature = "adb")]
256 if let Some(device) = adb_devices.first() {
257 println!(" Using ADB device: {}", device.name);
258 let config_str = serde_json::to_string(&device.config)?;
259 controller = Some(Controller::new_adb(
260 device.adb_path.to_str().unwrap(),
261 &device.address,
262 &config_str,
263 None,
264 )?);
265 } else {
266 controller = None;
267 }
268
269 #[cfg(not(feature = "adb"))]
270 {
271 controller = None;
272 }
273
274 // Option B: Win32 Controller (uncomment to use)
275 // #[cfg(target_os = "windows")]
276 // if let Some(window) = windows.first() {
277 // controller = Some(Controller::new_win32(
278 // window.hwnd as isize,
279 // common::Win32ScreencapMethod::FramePool as i32,
280 // common::Win32InputMethod::PostMessage as i32,
281 // common::Win32InputMethod::PostMessage as i32,
282 // )?);
283 // }
284
285 // -------------------------------------------------------------------------
286 // 4. Controller Operations
287 // -------------------------------------------------------------------------
288 if let Some(ref ctrl) = controller {
289 println!("\n[4] Controller operations...");
290
291 // Connect
292 let conn_id = ctrl.post_connection()?;
293 ctrl.wait(conn_id);
294 println!(" Connected: {}", ctrl.connected());
295
296 // Screenshot
297 let cap_id = ctrl.post_screencap()?;
298 ctrl.wait(cap_id);
299 println!(" Screenshot captured");
300
301 // Click (sync)
302 let click_id = ctrl.post_click(114, 514)?;
303 ctrl.wait(click_id);
304 println!(" Clicked at (114, 514)");
305
306 // Click (async) - post now, wait later
307 let click_id2 = ctrl.post_click(514, 114)?;
308 // ... do other work here ...
309 ctrl.wait(click_id2);
310 println!(" Async click completed");
311
312 // Input text
313 let input_id = ctrl.post_input_text("Hello MAA!")?;
314 ctrl.wait(input_id);
315 println!(" Text input sent");
316
317 // Get resolution
318 if let Ok((w, h)) = ctrl.resolution() {
319 println!(" Resolution: {}x{}", w, h);
320 }
321 } else {
322 println!("\n[4] Skipping controller operations (no device available)");
323 }
324
325 // -------------------------------------------------------------------------
326 // 5. Resource Setup
327 // -------------------------------------------------------------------------
328 println!("\n[5] Setting up resource...");
329
330 let resource = Resource::new()?;
331
332 // Register custom recognition and action
333 resource.register_custom_recognition("MyRecognition", Box::new(MyRecognition))?;
334 resource.register_custom_action("MyAction", Box::new(MyAction))?;
335 println!(" Registered: MyRecognition, MyAction");
336
337 // List registered components
338 let reco_list = resource.custom_recognition_list()?;
339 let action_list = resource.custom_action_list()?;
340 println!(" Recognition list: {:?}", reco_list);
341 println!(" Action list: {:?}", action_list);
342
343 // Load resource bundle
344 let resource_path = "sample/resource";
345 println!(" Loading resource from: {}", resource_path);
346 match resource.post_bundle(resource_path) {
347 Ok(job) => {
348 let status = job.wait();
349 println!(" Load status: {:?}", status);
350 }
351 Err(e) => println!(" Load failed: {} (OK for demo)", e),
352 }
353
354 // Add event sink
355 resource.add_sink(|msg, details| {
356 println!(
357 " [ResourceEvent] {}: {}",
358 msg,
359 &details[..details.len().min(50)]
360 );
361 })?;
362
363 // -------------------------------------------------------------------------
364 // 6. Tasker Setup and Execution
365 // -------------------------------------------------------------------------
366 println!("\n[6] Setting up tasker...");
367
368 let tasker = Tasker::new()?;
369
370 // Bind resource
371 tasker.bind_resource(&resource)?;
372 println!(" Resource bound");
373
374 // Bind controller (if available)
375 if let Some(ref ctrl) = controller {
376 tasker.bind_controller(ctrl)?;
377 println!(" Controller bound");
378 }
379
380 // Check initialization
381 if tasker.inited() {
382 println!(" Tasker initialized successfully!");
383
384 // Add event sink
385 tasker.add_sink(|msg, details| {
386 println!(
387 " [TaskerEvent] {}: {}",
388 msg,
389 &details[..details.len().min(50)]
390 );
391 })?;
392
393 // Execute task with pipeline override
394 let pipeline_override = r#"{
395 "MyCustomEntry": {
396 "recognition": "Custom",
397 "custom_recognition": "MyRecognition",
398 "action": "Custom",
399 "custom_action": "MyAction"
400 }
401 }"#;
402
403 println!("\n[7] Executing task...");
404 match tasker.post_task("MyCustomEntry", pipeline_override) {
405 Ok(job) => {
406 let status = job.wait();
407 println!(" Task status: {:?}", status);
408
409 if let Ok(Some(detail)) = job.get(false) {
410 println!(" Entry: {}", detail.entry);
411 println!(" Nodes executed: {}", detail.nodes.len());
412
413 for node_opt in detail.nodes {
414 if let Some(node) = node_opt {
415 if let Some(reco) = node.recognition {
416 println!(
417 " Node: {}, Algo: {:?}",
418 node.node_name, reco.algorithm
419 );
420 }
421 }
422 }
423 }
424 }
425 Err(e) => println!(" Task failed: {}", e),
426 }
427 } else {
428 println!(" Tasker not fully initialized (missing controller binding)");
429 }
430
431 // -------------------------------------------------------------------------
432 // 8. Cleanup
433 // -------------------------------------------------------------------------
434 println!("\n[8] Demo completed!");
435 println!(" - Toolkit, Controller, Resource, Tasker all demonstrated");
436 println!(" - Custom Recognition and Action registered and explained");
437 println!(" - Context API documented in custom component implementations");
438
439 Ok(())
440}Sourcepub fn bind_controller(&self, ctrl: &Controller) -> MaaResult<()>
pub fn bind_controller(&self, ctrl: &Controller) -> MaaResult<()>
Bind a controller to this tasker.
Examples found in repository?
201fn main() -> Result<(), Box<dyn std::error::Error>> {
202 println!("=== MaaFramework Rust SDK Demo ===\n");
203
204 // -------------------------------------------------------------------------
205 // 1. Initialize Toolkit
206 // -------------------------------------------------------------------------
207 let user_path = "./";
208 Toolkit::init_option(user_path, "{}")?;
209 println!("[1] Toolkit initialized with user_path: {}", user_path);
210
211 // -------------------------------------------------------------------------
212 // 2. Device Discovery
213 // -------------------------------------------------------------------------
214
215 // ADB devices
216 println!("\n[2] Scanning for ADB devices...");
217 let adb_devices = Toolkit::find_adb_devices()?;
218 if adb_devices.is_empty() {
219 println!(" No ADB device found.");
220 } else {
221 for device in &adb_devices {
222 println!(" Found: {} ({})", device.name, device.address);
223 }
224 }
225
226 // Win32 windows (Windows only)
227 #[cfg(target_os = "windows")]
228 {
229 println!("\n Scanning for desktop windows...");
230 match Toolkit::find_desktop_windows() {
231 Ok(windows) => {
232 if windows.is_empty() {
233 println!(" No window found.");
234 } else {
235 for (i, win) in windows.iter().take(3).enumerate() {
236 println!(" [{}] hwnd={:?}, class={}", i, win.hwnd, win.class_name);
237 }
238 if windows.len() > 3 {
239 println!(" ... and {} more", windows.len() - 3);
240 }
241 }
242 }
243 Err(e) => println!(" Failed to find windows: {}", e),
244 }
245 }
246
247 // -------------------------------------------------------------------------
248 // 3. Create Controller (choose one)
249 // -------------------------------------------------------------------------
250 println!("\n[3] Creating controller...");
251
252 let controller: Option<Controller>;
253
254 // Option A: ADB Controller
255 #[cfg(feature = "adb")]
256 if let Some(device) = adb_devices.first() {
257 println!(" Using ADB device: {}", device.name);
258 let config_str = serde_json::to_string(&device.config)?;
259 controller = Some(Controller::new_adb(
260 device.adb_path.to_str().unwrap(),
261 &device.address,
262 &config_str,
263 None,
264 )?);
265 } else {
266 controller = None;
267 }
268
269 #[cfg(not(feature = "adb"))]
270 {
271 controller = None;
272 }
273
274 // Option B: Win32 Controller (uncomment to use)
275 // #[cfg(target_os = "windows")]
276 // if let Some(window) = windows.first() {
277 // controller = Some(Controller::new_win32(
278 // window.hwnd as isize,
279 // common::Win32ScreencapMethod::FramePool as i32,
280 // common::Win32InputMethod::PostMessage as i32,
281 // common::Win32InputMethod::PostMessage as i32,
282 // )?);
283 // }
284
285 // -------------------------------------------------------------------------
286 // 4. Controller Operations
287 // -------------------------------------------------------------------------
288 if let Some(ref ctrl) = controller {
289 println!("\n[4] Controller operations...");
290
291 // Connect
292 let conn_id = ctrl.post_connection()?;
293 ctrl.wait(conn_id);
294 println!(" Connected: {}", ctrl.connected());
295
296 // Screenshot
297 let cap_id = ctrl.post_screencap()?;
298 ctrl.wait(cap_id);
299 println!(" Screenshot captured");
300
301 // Click (sync)
302 let click_id = ctrl.post_click(114, 514)?;
303 ctrl.wait(click_id);
304 println!(" Clicked at (114, 514)");
305
306 // Click (async) - post now, wait later
307 let click_id2 = ctrl.post_click(514, 114)?;
308 // ... do other work here ...
309 ctrl.wait(click_id2);
310 println!(" Async click completed");
311
312 // Input text
313 let input_id = ctrl.post_input_text("Hello MAA!")?;
314 ctrl.wait(input_id);
315 println!(" Text input sent");
316
317 // Get resolution
318 if let Ok((w, h)) = ctrl.resolution() {
319 println!(" Resolution: {}x{}", w, h);
320 }
321 } else {
322 println!("\n[4] Skipping controller operations (no device available)");
323 }
324
325 // -------------------------------------------------------------------------
326 // 5. Resource Setup
327 // -------------------------------------------------------------------------
328 println!("\n[5] Setting up resource...");
329
330 let resource = Resource::new()?;
331
332 // Register custom recognition and action
333 resource.register_custom_recognition("MyRecognition", Box::new(MyRecognition))?;
334 resource.register_custom_action("MyAction", Box::new(MyAction))?;
335 println!(" Registered: MyRecognition, MyAction");
336
337 // List registered components
338 let reco_list = resource.custom_recognition_list()?;
339 let action_list = resource.custom_action_list()?;
340 println!(" Recognition list: {:?}", reco_list);
341 println!(" Action list: {:?}", action_list);
342
343 // Load resource bundle
344 let resource_path = "sample/resource";
345 println!(" Loading resource from: {}", resource_path);
346 match resource.post_bundle(resource_path) {
347 Ok(job) => {
348 let status = job.wait();
349 println!(" Load status: {:?}", status);
350 }
351 Err(e) => println!(" Load failed: {} (OK for demo)", e),
352 }
353
354 // Add event sink
355 resource.add_sink(|msg, details| {
356 println!(
357 " [ResourceEvent] {}: {}",
358 msg,
359 &details[..details.len().min(50)]
360 );
361 })?;
362
363 // -------------------------------------------------------------------------
364 // 6. Tasker Setup and Execution
365 // -------------------------------------------------------------------------
366 println!("\n[6] Setting up tasker...");
367
368 let tasker = Tasker::new()?;
369
370 // Bind resource
371 tasker.bind_resource(&resource)?;
372 println!(" Resource bound");
373
374 // Bind controller (if available)
375 if let Some(ref ctrl) = controller {
376 tasker.bind_controller(ctrl)?;
377 println!(" Controller bound");
378 }
379
380 // Check initialization
381 if tasker.inited() {
382 println!(" Tasker initialized successfully!");
383
384 // Add event sink
385 tasker.add_sink(|msg, details| {
386 println!(
387 " [TaskerEvent] {}: {}",
388 msg,
389 &details[..details.len().min(50)]
390 );
391 })?;
392
393 // Execute task with pipeline override
394 let pipeline_override = r#"{
395 "MyCustomEntry": {
396 "recognition": "Custom",
397 "custom_recognition": "MyRecognition",
398 "action": "Custom",
399 "custom_action": "MyAction"
400 }
401 }"#;
402
403 println!("\n[7] Executing task...");
404 match tasker.post_task("MyCustomEntry", pipeline_override) {
405 Ok(job) => {
406 let status = job.wait();
407 println!(" Task status: {:?}", status);
408
409 if let Ok(Some(detail)) = job.get(false) {
410 println!(" Entry: {}", detail.entry);
411 println!(" Nodes executed: {}", detail.nodes.len());
412
413 for node_opt in detail.nodes {
414 if let Some(node) = node_opt {
415 if let Some(reco) = node.recognition {
416 println!(
417 " Node: {}, Algo: {:?}",
418 node.node_name, reco.algorithm
419 );
420 }
421 }
422 }
423 }
424 }
425 Err(e) => println!(" Task failed: {}", e),
426 }
427 } else {
428 println!(" Tasker not fully initialized (missing controller binding)");
429 }
430
431 // -------------------------------------------------------------------------
432 // 8. Cleanup
433 // -------------------------------------------------------------------------
434 println!("\n[8] Demo completed!");
435 println!(" - Toolkit, Controller, Resource, Tasker all demonstrated");
436 println!(" - Custom Recognition and Action registered and explained");
437 println!(" - Context API documented in custom component implementations");
438
439 Ok(())
440}Sourcepub fn get_recognition_detail(
&self,
reco_id: MaaId,
) -> MaaResult<Option<RecognitionDetail>>
pub fn get_recognition_detail( &self, reco_id: MaaId, ) -> MaaResult<Option<RecognitionDetail>>
Get recognition details by ID.
Sourcepub fn get_action_detail(
&self,
act_id: MaaId,
) -> MaaResult<Option<ActionDetail>>
pub fn get_action_detail( &self, act_id: MaaId, ) -> MaaResult<Option<ActionDetail>>
Get action details by ID.
Sourcepub fn get_node_detail(&self, node_id: MaaId) -> MaaResult<Option<NodeDetail>>
pub fn get_node_detail(&self, node_id: MaaId) -> MaaResult<Option<NodeDetail>>
Get node details by ID.
Sourcepub fn get_task_detail(&self, task_id: MaaId) -> MaaResult<Option<TaskDetail>>
pub fn get_task_detail(&self, task_id: MaaId) -> MaaResult<Option<TaskDetail>>
Get task details by ID.
Sourcepub fn post_task(
&self,
entry: &str,
pipeline_override: &str,
) -> MaaResult<TaskJob<'static, TaskDetail>>
pub fn post_task( &self, entry: &str, pipeline_override: &str, ) -> MaaResult<TaskJob<'static, TaskDetail>>
Post a task for execution.
§Arguments
entry- The task entry point namepipeline_override- JSON string for parameter overrides
§Returns
A TaskJob that can be used to wait for completion and get results.
Examples found in repository?
201fn main() -> Result<(), Box<dyn std::error::Error>> {
202 println!("=== MaaFramework Rust SDK Demo ===\n");
203
204 // -------------------------------------------------------------------------
205 // 1. Initialize Toolkit
206 // -------------------------------------------------------------------------
207 let user_path = "./";
208 Toolkit::init_option(user_path, "{}")?;
209 println!("[1] Toolkit initialized with user_path: {}", user_path);
210
211 // -------------------------------------------------------------------------
212 // 2. Device Discovery
213 // -------------------------------------------------------------------------
214
215 // ADB devices
216 println!("\n[2] Scanning for ADB devices...");
217 let adb_devices = Toolkit::find_adb_devices()?;
218 if adb_devices.is_empty() {
219 println!(" No ADB device found.");
220 } else {
221 for device in &adb_devices {
222 println!(" Found: {} ({})", device.name, device.address);
223 }
224 }
225
226 // Win32 windows (Windows only)
227 #[cfg(target_os = "windows")]
228 {
229 println!("\n Scanning for desktop windows...");
230 match Toolkit::find_desktop_windows() {
231 Ok(windows) => {
232 if windows.is_empty() {
233 println!(" No window found.");
234 } else {
235 for (i, win) in windows.iter().take(3).enumerate() {
236 println!(" [{}] hwnd={:?}, class={}", i, win.hwnd, win.class_name);
237 }
238 if windows.len() > 3 {
239 println!(" ... and {} more", windows.len() - 3);
240 }
241 }
242 }
243 Err(e) => println!(" Failed to find windows: {}", e),
244 }
245 }
246
247 // -------------------------------------------------------------------------
248 // 3. Create Controller (choose one)
249 // -------------------------------------------------------------------------
250 println!("\n[3] Creating controller...");
251
252 let controller: Option<Controller>;
253
254 // Option A: ADB Controller
255 #[cfg(feature = "adb")]
256 if let Some(device) = adb_devices.first() {
257 println!(" Using ADB device: {}", device.name);
258 let config_str = serde_json::to_string(&device.config)?;
259 controller = Some(Controller::new_adb(
260 device.adb_path.to_str().unwrap(),
261 &device.address,
262 &config_str,
263 None,
264 )?);
265 } else {
266 controller = None;
267 }
268
269 #[cfg(not(feature = "adb"))]
270 {
271 controller = None;
272 }
273
274 // Option B: Win32 Controller (uncomment to use)
275 // #[cfg(target_os = "windows")]
276 // if let Some(window) = windows.first() {
277 // controller = Some(Controller::new_win32(
278 // window.hwnd as isize,
279 // common::Win32ScreencapMethod::FramePool as i32,
280 // common::Win32InputMethod::PostMessage as i32,
281 // common::Win32InputMethod::PostMessage as i32,
282 // )?);
283 // }
284
285 // -------------------------------------------------------------------------
286 // 4. Controller Operations
287 // -------------------------------------------------------------------------
288 if let Some(ref ctrl) = controller {
289 println!("\n[4] Controller operations...");
290
291 // Connect
292 let conn_id = ctrl.post_connection()?;
293 ctrl.wait(conn_id);
294 println!(" Connected: {}", ctrl.connected());
295
296 // Screenshot
297 let cap_id = ctrl.post_screencap()?;
298 ctrl.wait(cap_id);
299 println!(" Screenshot captured");
300
301 // Click (sync)
302 let click_id = ctrl.post_click(114, 514)?;
303 ctrl.wait(click_id);
304 println!(" Clicked at (114, 514)");
305
306 // Click (async) - post now, wait later
307 let click_id2 = ctrl.post_click(514, 114)?;
308 // ... do other work here ...
309 ctrl.wait(click_id2);
310 println!(" Async click completed");
311
312 // Input text
313 let input_id = ctrl.post_input_text("Hello MAA!")?;
314 ctrl.wait(input_id);
315 println!(" Text input sent");
316
317 // Get resolution
318 if let Ok((w, h)) = ctrl.resolution() {
319 println!(" Resolution: {}x{}", w, h);
320 }
321 } else {
322 println!("\n[4] Skipping controller operations (no device available)");
323 }
324
325 // -------------------------------------------------------------------------
326 // 5. Resource Setup
327 // -------------------------------------------------------------------------
328 println!("\n[5] Setting up resource...");
329
330 let resource = Resource::new()?;
331
332 // Register custom recognition and action
333 resource.register_custom_recognition("MyRecognition", Box::new(MyRecognition))?;
334 resource.register_custom_action("MyAction", Box::new(MyAction))?;
335 println!(" Registered: MyRecognition, MyAction");
336
337 // List registered components
338 let reco_list = resource.custom_recognition_list()?;
339 let action_list = resource.custom_action_list()?;
340 println!(" Recognition list: {:?}", reco_list);
341 println!(" Action list: {:?}", action_list);
342
343 // Load resource bundle
344 let resource_path = "sample/resource";
345 println!(" Loading resource from: {}", resource_path);
346 match resource.post_bundle(resource_path) {
347 Ok(job) => {
348 let status = job.wait();
349 println!(" Load status: {:?}", status);
350 }
351 Err(e) => println!(" Load failed: {} (OK for demo)", e),
352 }
353
354 // Add event sink
355 resource.add_sink(|msg, details| {
356 println!(
357 " [ResourceEvent] {}: {}",
358 msg,
359 &details[..details.len().min(50)]
360 );
361 })?;
362
363 // -------------------------------------------------------------------------
364 // 6. Tasker Setup and Execution
365 // -------------------------------------------------------------------------
366 println!("\n[6] Setting up tasker...");
367
368 let tasker = Tasker::new()?;
369
370 // Bind resource
371 tasker.bind_resource(&resource)?;
372 println!(" Resource bound");
373
374 // Bind controller (if available)
375 if let Some(ref ctrl) = controller {
376 tasker.bind_controller(ctrl)?;
377 println!(" Controller bound");
378 }
379
380 // Check initialization
381 if tasker.inited() {
382 println!(" Tasker initialized successfully!");
383
384 // Add event sink
385 tasker.add_sink(|msg, details| {
386 println!(
387 " [TaskerEvent] {}: {}",
388 msg,
389 &details[..details.len().min(50)]
390 );
391 })?;
392
393 // Execute task with pipeline override
394 let pipeline_override = r#"{
395 "MyCustomEntry": {
396 "recognition": "Custom",
397 "custom_recognition": "MyRecognition",
398 "action": "Custom",
399 "custom_action": "MyAction"
400 }
401 }"#;
402
403 println!("\n[7] Executing task...");
404 match tasker.post_task("MyCustomEntry", pipeline_override) {
405 Ok(job) => {
406 let status = job.wait();
407 println!(" Task status: {:?}", status);
408
409 if let Ok(Some(detail)) = job.get(false) {
410 println!(" Entry: {}", detail.entry);
411 println!(" Nodes executed: {}", detail.nodes.len());
412
413 for node_opt in detail.nodes {
414 if let Some(node) = node_opt {
415 if let Some(reco) = node.recognition {
416 println!(
417 " Node: {}, Algo: {:?}",
418 node.node_name, reco.algorithm
419 );
420 }
421 }
422 }
423 }
424 }
425 Err(e) => println!(" Task failed: {}", e),
426 }
427 } else {
428 println!(" Tasker not fully initialized (missing controller binding)");
429 }
430
431 // -------------------------------------------------------------------------
432 // 8. Cleanup
433 // -------------------------------------------------------------------------
434 println!("\n[8] Demo completed!");
435 println!(" - Toolkit, Controller, Resource, Tasker all demonstrated");
436 println!(" - Custom Recognition and Action registered and explained");
437 println!(" - Context API documented in custom component implementations");
438
439 Ok(())
440}Sourcepub fn post_task_json(
&self,
entry: &str,
pipeline_override: &Value,
) -> MaaResult<TaskJob<'static, TaskDetail>>
pub fn post_task_json( &self, entry: &str, pipeline_override: &Value, ) -> MaaResult<TaskJob<'static, TaskDetail>>
Sourcepub fn inited(&self) -> bool
pub fn inited(&self) -> bool
Check if the tasker has been initialized (resource and controller bound).
Examples found in repository?
201fn main() -> Result<(), Box<dyn std::error::Error>> {
202 println!("=== MaaFramework Rust SDK Demo ===\n");
203
204 // -------------------------------------------------------------------------
205 // 1. Initialize Toolkit
206 // -------------------------------------------------------------------------
207 let user_path = "./";
208 Toolkit::init_option(user_path, "{}")?;
209 println!("[1] Toolkit initialized with user_path: {}", user_path);
210
211 // -------------------------------------------------------------------------
212 // 2. Device Discovery
213 // -------------------------------------------------------------------------
214
215 // ADB devices
216 println!("\n[2] Scanning for ADB devices...");
217 let adb_devices = Toolkit::find_adb_devices()?;
218 if adb_devices.is_empty() {
219 println!(" No ADB device found.");
220 } else {
221 for device in &adb_devices {
222 println!(" Found: {} ({})", device.name, device.address);
223 }
224 }
225
226 // Win32 windows (Windows only)
227 #[cfg(target_os = "windows")]
228 {
229 println!("\n Scanning for desktop windows...");
230 match Toolkit::find_desktop_windows() {
231 Ok(windows) => {
232 if windows.is_empty() {
233 println!(" No window found.");
234 } else {
235 for (i, win) in windows.iter().take(3).enumerate() {
236 println!(" [{}] hwnd={:?}, class={}", i, win.hwnd, win.class_name);
237 }
238 if windows.len() > 3 {
239 println!(" ... and {} more", windows.len() - 3);
240 }
241 }
242 }
243 Err(e) => println!(" Failed to find windows: {}", e),
244 }
245 }
246
247 // -------------------------------------------------------------------------
248 // 3. Create Controller (choose one)
249 // -------------------------------------------------------------------------
250 println!("\n[3] Creating controller...");
251
252 let controller: Option<Controller>;
253
254 // Option A: ADB Controller
255 #[cfg(feature = "adb")]
256 if let Some(device) = adb_devices.first() {
257 println!(" Using ADB device: {}", device.name);
258 let config_str = serde_json::to_string(&device.config)?;
259 controller = Some(Controller::new_adb(
260 device.adb_path.to_str().unwrap(),
261 &device.address,
262 &config_str,
263 None,
264 )?);
265 } else {
266 controller = None;
267 }
268
269 #[cfg(not(feature = "adb"))]
270 {
271 controller = None;
272 }
273
274 // Option B: Win32 Controller (uncomment to use)
275 // #[cfg(target_os = "windows")]
276 // if let Some(window) = windows.first() {
277 // controller = Some(Controller::new_win32(
278 // window.hwnd as isize,
279 // common::Win32ScreencapMethod::FramePool as i32,
280 // common::Win32InputMethod::PostMessage as i32,
281 // common::Win32InputMethod::PostMessage as i32,
282 // )?);
283 // }
284
285 // -------------------------------------------------------------------------
286 // 4. Controller Operations
287 // -------------------------------------------------------------------------
288 if let Some(ref ctrl) = controller {
289 println!("\n[4] Controller operations...");
290
291 // Connect
292 let conn_id = ctrl.post_connection()?;
293 ctrl.wait(conn_id);
294 println!(" Connected: {}", ctrl.connected());
295
296 // Screenshot
297 let cap_id = ctrl.post_screencap()?;
298 ctrl.wait(cap_id);
299 println!(" Screenshot captured");
300
301 // Click (sync)
302 let click_id = ctrl.post_click(114, 514)?;
303 ctrl.wait(click_id);
304 println!(" Clicked at (114, 514)");
305
306 // Click (async) - post now, wait later
307 let click_id2 = ctrl.post_click(514, 114)?;
308 // ... do other work here ...
309 ctrl.wait(click_id2);
310 println!(" Async click completed");
311
312 // Input text
313 let input_id = ctrl.post_input_text("Hello MAA!")?;
314 ctrl.wait(input_id);
315 println!(" Text input sent");
316
317 // Get resolution
318 if let Ok((w, h)) = ctrl.resolution() {
319 println!(" Resolution: {}x{}", w, h);
320 }
321 } else {
322 println!("\n[4] Skipping controller operations (no device available)");
323 }
324
325 // -------------------------------------------------------------------------
326 // 5. Resource Setup
327 // -------------------------------------------------------------------------
328 println!("\n[5] Setting up resource...");
329
330 let resource = Resource::new()?;
331
332 // Register custom recognition and action
333 resource.register_custom_recognition("MyRecognition", Box::new(MyRecognition))?;
334 resource.register_custom_action("MyAction", Box::new(MyAction))?;
335 println!(" Registered: MyRecognition, MyAction");
336
337 // List registered components
338 let reco_list = resource.custom_recognition_list()?;
339 let action_list = resource.custom_action_list()?;
340 println!(" Recognition list: {:?}", reco_list);
341 println!(" Action list: {:?}", action_list);
342
343 // Load resource bundle
344 let resource_path = "sample/resource";
345 println!(" Loading resource from: {}", resource_path);
346 match resource.post_bundle(resource_path) {
347 Ok(job) => {
348 let status = job.wait();
349 println!(" Load status: {:?}", status);
350 }
351 Err(e) => println!(" Load failed: {} (OK for demo)", e),
352 }
353
354 // Add event sink
355 resource.add_sink(|msg, details| {
356 println!(
357 " [ResourceEvent] {}: {}",
358 msg,
359 &details[..details.len().min(50)]
360 );
361 })?;
362
363 // -------------------------------------------------------------------------
364 // 6. Tasker Setup and Execution
365 // -------------------------------------------------------------------------
366 println!("\n[6] Setting up tasker...");
367
368 let tasker = Tasker::new()?;
369
370 // Bind resource
371 tasker.bind_resource(&resource)?;
372 println!(" Resource bound");
373
374 // Bind controller (if available)
375 if let Some(ref ctrl) = controller {
376 tasker.bind_controller(ctrl)?;
377 println!(" Controller bound");
378 }
379
380 // Check initialization
381 if tasker.inited() {
382 println!(" Tasker initialized successfully!");
383
384 // Add event sink
385 tasker.add_sink(|msg, details| {
386 println!(
387 " [TaskerEvent] {}: {}",
388 msg,
389 &details[..details.len().min(50)]
390 );
391 })?;
392
393 // Execute task with pipeline override
394 let pipeline_override = r#"{
395 "MyCustomEntry": {
396 "recognition": "Custom",
397 "custom_recognition": "MyRecognition",
398 "action": "Custom",
399 "custom_action": "MyAction"
400 }
401 }"#;
402
403 println!("\n[7] Executing task...");
404 match tasker.post_task("MyCustomEntry", pipeline_override) {
405 Ok(job) => {
406 let status = job.wait();
407 println!(" Task status: {:?}", status);
408
409 if let Ok(Some(detail)) = job.get(false) {
410 println!(" Entry: {}", detail.entry);
411 println!(" Nodes executed: {}", detail.nodes.len());
412
413 for node_opt in detail.nodes {
414 if let Some(node) = node_opt {
415 if let Some(reco) = node.recognition {
416 println!(
417 " Node: {}, Algo: {:?}",
418 node.node_name, reco.algorithm
419 );
420 }
421 }
422 }
423 }
424 }
425 Err(e) => println!(" Task failed: {}", e),
426 }
427 } else {
428 println!(" Tasker not fully initialized (missing controller binding)");
429 }
430
431 // -------------------------------------------------------------------------
432 // 8. Cleanup
433 // -------------------------------------------------------------------------
434 println!("\n[8] Demo completed!");
435 println!(" - Toolkit, Controller, Resource, Tasker all demonstrated");
436 println!(" - Custom Recognition and Action registered and explained");
437 println!(" - Context API documented in custom component implementations");
438
439 Ok(())
440}Sourcepub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
pub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
Add a tasker event sink callback.
This registers a callback that will be invoked for all tasker events including task start, task completion, and status changes.
§Arguments
callback- Closure that receives (message, detail_json) for each event
§Returns
Sink ID for later removal via remove_sink()
Examples found in repository?
201fn main() -> Result<(), Box<dyn std::error::Error>> {
202 println!("=== MaaFramework Rust SDK Demo ===\n");
203
204 // -------------------------------------------------------------------------
205 // 1. Initialize Toolkit
206 // -------------------------------------------------------------------------
207 let user_path = "./";
208 Toolkit::init_option(user_path, "{}")?;
209 println!("[1] Toolkit initialized with user_path: {}", user_path);
210
211 // -------------------------------------------------------------------------
212 // 2. Device Discovery
213 // -------------------------------------------------------------------------
214
215 // ADB devices
216 println!("\n[2] Scanning for ADB devices...");
217 let adb_devices = Toolkit::find_adb_devices()?;
218 if adb_devices.is_empty() {
219 println!(" No ADB device found.");
220 } else {
221 for device in &adb_devices {
222 println!(" Found: {} ({})", device.name, device.address);
223 }
224 }
225
226 // Win32 windows (Windows only)
227 #[cfg(target_os = "windows")]
228 {
229 println!("\n Scanning for desktop windows...");
230 match Toolkit::find_desktop_windows() {
231 Ok(windows) => {
232 if windows.is_empty() {
233 println!(" No window found.");
234 } else {
235 for (i, win) in windows.iter().take(3).enumerate() {
236 println!(" [{}] hwnd={:?}, class={}", i, win.hwnd, win.class_name);
237 }
238 if windows.len() > 3 {
239 println!(" ... and {} more", windows.len() - 3);
240 }
241 }
242 }
243 Err(e) => println!(" Failed to find windows: {}", e),
244 }
245 }
246
247 // -------------------------------------------------------------------------
248 // 3. Create Controller (choose one)
249 // -------------------------------------------------------------------------
250 println!("\n[3] Creating controller...");
251
252 let controller: Option<Controller>;
253
254 // Option A: ADB Controller
255 #[cfg(feature = "adb")]
256 if let Some(device) = adb_devices.first() {
257 println!(" Using ADB device: {}", device.name);
258 let config_str = serde_json::to_string(&device.config)?;
259 controller = Some(Controller::new_adb(
260 device.adb_path.to_str().unwrap(),
261 &device.address,
262 &config_str,
263 None,
264 )?);
265 } else {
266 controller = None;
267 }
268
269 #[cfg(not(feature = "adb"))]
270 {
271 controller = None;
272 }
273
274 // Option B: Win32 Controller (uncomment to use)
275 // #[cfg(target_os = "windows")]
276 // if let Some(window) = windows.first() {
277 // controller = Some(Controller::new_win32(
278 // window.hwnd as isize,
279 // common::Win32ScreencapMethod::FramePool as i32,
280 // common::Win32InputMethod::PostMessage as i32,
281 // common::Win32InputMethod::PostMessage as i32,
282 // )?);
283 // }
284
285 // -------------------------------------------------------------------------
286 // 4. Controller Operations
287 // -------------------------------------------------------------------------
288 if let Some(ref ctrl) = controller {
289 println!("\n[4] Controller operations...");
290
291 // Connect
292 let conn_id = ctrl.post_connection()?;
293 ctrl.wait(conn_id);
294 println!(" Connected: {}", ctrl.connected());
295
296 // Screenshot
297 let cap_id = ctrl.post_screencap()?;
298 ctrl.wait(cap_id);
299 println!(" Screenshot captured");
300
301 // Click (sync)
302 let click_id = ctrl.post_click(114, 514)?;
303 ctrl.wait(click_id);
304 println!(" Clicked at (114, 514)");
305
306 // Click (async) - post now, wait later
307 let click_id2 = ctrl.post_click(514, 114)?;
308 // ... do other work here ...
309 ctrl.wait(click_id2);
310 println!(" Async click completed");
311
312 // Input text
313 let input_id = ctrl.post_input_text("Hello MAA!")?;
314 ctrl.wait(input_id);
315 println!(" Text input sent");
316
317 // Get resolution
318 if let Ok((w, h)) = ctrl.resolution() {
319 println!(" Resolution: {}x{}", w, h);
320 }
321 } else {
322 println!("\n[4] Skipping controller operations (no device available)");
323 }
324
325 // -------------------------------------------------------------------------
326 // 5. Resource Setup
327 // -------------------------------------------------------------------------
328 println!("\n[5] Setting up resource...");
329
330 let resource = Resource::new()?;
331
332 // Register custom recognition and action
333 resource.register_custom_recognition("MyRecognition", Box::new(MyRecognition))?;
334 resource.register_custom_action("MyAction", Box::new(MyAction))?;
335 println!(" Registered: MyRecognition, MyAction");
336
337 // List registered components
338 let reco_list = resource.custom_recognition_list()?;
339 let action_list = resource.custom_action_list()?;
340 println!(" Recognition list: {:?}", reco_list);
341 println!(" Action list: {:?}", action_list);
342
343 // Load resource bundle
344 let resource_path = "sample/resource";
345 println!(" Loading resource from: {}", resource_path);
346 match resource.post_bundle(resource_path) {
347 Ok(job) => {
348 let status = job.wait();
349 println!(" Load status: {:?}", status);
350 }
351 Err(e) => println!(" Load failed: {} (OK for demo)", e),
352 }
353
354 // Add event sink
355 resource.add_sink(|msg, details| {
356 println!(
357 " [ResourceEvent] {}: {}",
358 msg,
359 &details[..details.len().min(50)]
360 );
361 })?;
362
363 // -------------------------------------------------------------------------
364 // 6. Tasker Setup and Execution
365 // -------------------------------------------------------------------------
366 println!("\n[6] Setting up tasker...");
367
368 let tasker = Tasker::new()?;
369
370 // Bind resource
371 tasker.bind_resource(&resource)?;
372 println!(" Resource bound");
373
374 // Bind controller (if available)
375 if let Some(ref ctrl) = controller {
376 tasker.bind_controller(ctrl)?;
377 println!(" Controller bound");
378 }
379
380 // Check initialization
381 if tasker.inited() {
382 println!(" Tasker initialized successfully!");
383
384 // Add event sink
385 tasker.add_sink(|msg, details| {
386 println!(
387 " [TaskerEvent] {}: {}",
388 msg,
389 &details[..details.len().min(50)]
390 );
391 })?;
392
393 // Execute task with pipeline override
394 let pipeline_override = r#"{
395 "MyCustomEntry": {
396 "recognition": "Custom",
397 "custom_recognition": "MyRecognition",
398 "action": "Custom",
399 "custom_action": "MyAction"
400 }
401 }"#;
402
403 println!("\n[7] Executing task...");
404 match tasker.post_task("MyCustomEntry", pipeline_override) {
405 Ok(job) => {
406 let status = job.wait();
407 println!(" Task status: {:?}", status);
408
409 if let Ok(Some(detail)) = job.get(false) {
410 println!(" Entry: {}", detail.entry);
411 println!(" Nodes executed: {}", detail.nodes.len());
412
413 for node_opt in detail.nodes {
414 if let Some(node) = node_opt {
415 if let Some(reco) = node.recognition {
416 println!(
417 " Node: {}, Algo: {:?}",
418 node.node_name, reco.algorithm
419 );
420 }
421 }
422 }
423 }
424 }
425 Err(e) => println!(" Task failed: {}", e),
426 }
427 } else {
428 println!(" Tasker not fully initialized (missing controller binding)");
429 }
430
431 // -------------------------------------------------------------------------
432 // 8. Cleanup
433 // -------------------------------------------------------------------------
434 println!("\n[8] Demo completed!");
435 println!(" - Toolkit, Controller, Resource, Tasker all demonstrated");
436 println!(" - Custom Recognition and Action registered and explained");
437 println!(" - Context API documented in custom component implementations");
438
439 Ok(())
440}Sourcepub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>
pub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>
Register a strongly-typed event sink.
This method registers an implementation of the EventSink trait
to receive structured notifications from this tasker.
§Arguments
sink- The event sink implementation (must be boxed).
§Returns
A MaaSinkId which can be used to manually remove the sink later via remove_sink.
The sink will be automatically unregistered and dropped when the Tasker is dropped.
Sourcepub fn remove_sink(&self, sink_id: MaaSinkId)
pub fn remove_sink(&self, sink_id: MaaSinkId)
Sourcepub fn clear_sinks(&self)
pub fn clear_sinks(&self)
Clear all tasker sinks.
pub fn register_callback<F>(&self, callback: F) -> MaaResult<MaaId>
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the tasker is currently running.
Sourcepub fn add_context_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
pub fn add_context_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
Add a context event sink callback. Returns a sink ID for later removal.
Sourcepub fn add_context_event_sink(
&self,
sink: Box<dyn EventSink>,
) -> MaaResult<MaaSinkId>
pub fn add_context_event_sink( &self, sink: Box<dyn EventSink>, ) -> MaaResult<MaaSinkId>
Register a strongly-typed context event sink.
This receives detailed execution events like Node.Recognition, Node.Action, etc.
§Arguments
sink- The event sink implementation (must be boxed).
§Returns
A MaaSinkId which can be used to manually remove the sink later via remove_context_sink.
Sourcepub fn remove_context_sink(&self, sink_id: MaaSinkId)
pub fn remove_context_sink(&self, sink_id: MaaSinkId)
Remove a context sink by ID.
Sourcepub fn clear_context_sinks(&self)
pub fn clear_context_sinks(&self)
Clear all context sinks.
Sourcepub fn clear_cache(&self) -> MaaResult<()>
pub fn clear_cache(&self) -> MaaResult<()>
Clear all cached data.
Sourcepub fn override_pipeline(
&self,
task_id: MaaId,
pipeline_override: &str,
) -> MaaResult<bool>
pub fn override_pipeline( &self, task_id: MaaId, pipeline_override: &str, ) -> MaaResult<bool>
Override pipeline configuration for a specific task.
§Arguments
task_id- The ID of the task to update.pipeline_override- The JSON string containing the new configuration.
Sourcepub fn get_latest_node(&self, node_name: &str) -> MaaResult<Option<MaaId>>
pub fn get_latest_node(&self, node_name: &str) -> MaaResult<Option<MaaId>>
Get the latest node ID for a given node name.
Sourcepub fn bind(
&self,
resource: &Resource,
controller: &Controller,
) -> MaaResult<()>
pub fn bind( &self, resource: &Resource, controller: &Controller, ) -> MaaResult<()>
Convenience method to bind both resource and controller at once.
Sourcepub fn resource(&self) -> Option<ResourceRef<'_>>
pub fn resource(&self) -> Option<ResourceRef<'_>>
Sourcepub fn controller(&self) -> Option<ControllerRef<'_>>
pub fn controller(&self) -> Option<ControllerRef<'_>>
Sourcepub fn resource_handle(&self) -> *mut MaaResource
pub fn resource_handle(&self) -> *mut MaaResource
Get the bound resource handle (raw pointer).
Returns the raw pointer to the resource. The caller should not destroy this handle.
Sourcepub fn controller_handle(&self) -> *mut MaaController
pub fn controller_handle(&self) -> *mut MaaController
Get the bound controller handle (raw pointer).
Returns the raw pointer to the controller. The caller should not destroy this handle.
Sourcepub fn post_recognition(
&self,
reco_type: &str,
reco_param: &str,
image: &MaaImageBuffer,
) -> MaaResult<TaskJob<'static, RecognitionDetail>>
pub fn post_recognition( &self, reco_type: &str, reco_param: &str, image: &MaaImageBuffer, ) -> MaaResult<TaskJob<'static, RecognitionDetail>>
Post a recognition task directly without executing through a pipeline.
§Arguments
reco_type- Recognition type (e.g., “TemplateMatch”, “OCR”)reco_param- Recognition parameters as JSON stringimage- The image to perform recognition on
Sourcepub fn post_action(
&self,
action_type: &str,
action_param: &str,
box_rect: &Rect,
reco_detail: &str,
) -> MaaResult<TaskJob<'static, ActionDetail>>
pub fn post_action( &self, action_type: &str, action_param: &str, box_rect: &Rect, reco_detail: &str, ) -> MaaResult<TaskJob<'static, ActionDetail>>
Post an action task directly without executing through a pipeline.
§Arguments
action_type- Action type (e.g., “Click”, “Swipe”)action_param- Action parameters as JSON stringbox_rect- The target rectangle for the actionreco_detail- Recognition detail from previous recognition (can be empty)
Sourcepub fn set_save_draw(save: bool) -> MaaResult<()>
pub fn set_save_draw(save: bool) -> MaaResult<()>
Set whether to save debug drawings.
Sourcepub fn set_stdout_level(level: MaaLoggingLevel) -> MaaResult<()>
pub fn set_stdout_level(level: MaaLoggingLevel) -> MaaResult<()>
Set the stdout logging level.
Sourcepub fn set_debug_mode(debug: bool) -> MaaResult<()>
pub fn set_debug_mode(debug: bool) -> MaaResult<()>
Enable or disable debug mode (raw image capture, etc).
Sourcepub fn set_save_on_error(save: bool) -> MaaResult<()>
pub fn set_save_on_error(save: bool) -> MaaResult<()>
Set whether to save screenshots on error.
Sourcepub fn set_draw_quality(quality: i32) -> MaaResult<()>
pub fn set_draw_quality(quality: i32) -> MaaResult<()>
Set the JPEG quality for debug drawings (0-100).
Sourcepub fn set_reco_image_cache_limit(limit: usize) -> MaaResult<()>
pub fn set_reco_image_cache_limit(limit: usize) -> MaaResult<()>
Set the limit for recognition image cache.