use super::common::get_focus_window;
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 WindowControlGetFocusDriver;
#[async_trait::async_trait]
impl Driver for WindowControlGetFocusDriver {
fn name(&self) -> &str {
"window_control_get_focus"
}
fn description(&self) -> &str {
"Get the currently focused window"
}
fn usage_hint(&self) -> &str {
"Use this skill to find out which window is currently active"
}
fn parameters(&self) -> Vec<DriverParameter> {
return vec![];
}
fn example_call(&self) -> DriverResult<Value> {
return Ok(json!({
"action": "window_control_get_focus"
}));
}
fn example_output(&self) -> String {
return "Focused window: 微信 (WeChat.exe)".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_get_focus driver");
let window_id = get_focus_window()?;
use super::common::list_windows;
let windows = list_windows()?;
let window = windows.iter().find(|w| w.id == window_id).ok_or_else(|| DriverError::execution("Window not found"))?;
info!("Focused window: {} ({})", window.title, window.process_name);
return Ok(format!("Focused window: {} ({})", window.title, window.process_name));
}
}