window_observer/platform_impl/windows/
observer.rs1use wineventhook::WindowEventHook;
2
3use crate::{Error, EventTx};
4
5use super::hook_task::make_wineventhook_task;
6
7pub struct WindowsWindowObserver {
9 hook: WindowEventHook,
10}
11
12impl WindowsWindowObserver {
13 pub async fn start(
15 pid: u32,
16 event_tx: EventTx,
17 event_filter: crate::EventFilter,
18 ) -> Result<Self, Error> {
19 if pid == 0 {
20 return Err(Error::InvalidProcessId(pid));
21 }
22
23 let hook = make_wineventhook_task(pid, event_tx, event_filter).await?;
24
25 Ok(Self { hook })
26 }
27
28 pub async fn stop(self) -> Result<(), Error> {
30 self.hook
31 .unhook()
32 .await
33 .map_err(super::error::WindowsError::from)?;
34
35 Ok(())
36 }
37
38 pub fn hook(&self) -> &WindowEventHook {
40 &self.hook
41 }
42}