use super::common::list_windows;
use crate::{
DriverCallback, DriverCategory, DriverContext, DriverError, DriverResult,
types::{Driver, DriverParameter},
};
use serde_json::{Value, json};
use std::collections::HashMap;
use tracing::{debug, info};
#[derive(Debug)]
pub struct WindowControlListDriver;
#[async_trait::async_trait]
impl Driver for WindowControlListDriver {
fn name(&self) -> &str {
"window_control_list"
}
fn description(&self) -> &str {
"List all open windows"
}
fn usage_hint(&self) -> &str {
"Use this skill to see what windows are currently open"
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![];
}
fn example_call(&self) -> DriverResult<Value> {
return Ok(json!({
"action": "window_control_list"
}));
}
fn example_output(&self) -> String {
return "Found 5 windows:\n1. 微信 (WeChat.exe, PID: 12345)\n2. Visual Studio Code (Code.exe, PID: 23456)\n3. Chrome (chrome.exe, PID: 34567)".to_string();
}
fn category(&self) -> DriverCategory {
return DriverCategory::Window;
}
async fn execute(
&self,
_parameters: &HashMap<String, Value>,
_callback: Option<&dyn DriverCallback>,
_context: Option<&DriverContext>,
) -> DriverResult<String> {
debug!("Executing window_control_list driver");
let windows = list_windows()?;
if windows.is_empty() {
info!("No windows found");
return Ok("No windows found".to_string());
}
info!("Found {} windows", windows.len());
let mut result = format!("Found {} windows:\n", windows.len());
for (i, window) in windows.iter().enumerate() {
result.push_str(&format!(
"{}. {} ({} [{}], PID: {})\n",
i + 1,
window.title,
window.process_name,
if window.is_minimized { "minimized" } else { "visible" },
window.pid
));
}
return Ok(result);
}
}