computeruse-rs 2.0.0

A Playwright-style SDK for automating desktop GUI applications
// Test if we can maximize Calculator (UWP app) using UI Automation

use computeruse::Desktop;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("๐Ÿงช Testing UWP window maximize...\n");

    // Initialize desktop
    let desktop = Desktop::new(false, true)?; // use_background_apps=false, activate_app=true
    println!("โœ… Desktop initialized");

    // Open Calculator
    println!("๐Ÿ“ฑ Opening Calculator...");
    let ui_element = desktop.open_application("Calculator")?;
    println!("โœ… Calculator opened");

    // Get process info
    let pid = ui_element.process_id().unwrap_or(0);
    let window_title = ui_element.window_title();
    println!("   PID: {pid}");
    println!("   Window: {window_title}");

    // Get initial bounds
    if let Ok((x, y, width, height)) = ui_element.bounds() {
        println!("\n๐Ÿ“ Initial bounds:");
        println!("   x: {x}, y: {y}, width: {width}, height: {height}");
    }

    // Try to maximize using UI Automation
    println!("\n๐Ÿ”„ Attempting to maximize via UI Automation...");
    match ui_element.maximize_window() {
        Ok(_) => {
            println!("โœ… maximize_window() call succeeded");
        }
        Err(e) => {
            println!("โŒ maximize_window() failed: {e}");
            return Err(e.into());
        }
    }

    // Wait a moment for window to update
    std::thread::sleep(std::time::Duration::from_millis(500));

    // Get final bounds
    if let Ok((x, y, width, height)) = ui_element.bounds() {
        println!("\n๐Ÿ“ Final bounds:");
        println!("   x: {x}, y: {y}, width: {width}, height: {height}");
    }

    println!("\nโœจ Test complete! Check if Calculator is maximized.");

    Ok(())
}