empty_entity

Function empty_entity 

Source
pub fn empty_entity() -> WindowInfo
Examples found in repository?
examples/subscribe_active_window.rs (line 18)
11fn subscribe_active_window<F>(interval: u64, callback: F) -> mpsc::Sender<()>
12where
13  F: Fn(Result<WindowInfo, String>) + Send + 'static,
14{
15  let (sender, receiver) = mpsc::channel::<()>();
16
17  thread::spawn(move || {
18    let mut current_window = empty_entity();
19
20    loop {
21      match receiver.try_recv() {
22        Ok(_) | Err(TryRecvError::Disconnected) => {
23          break;
24        }
25        _ => {
26          match get_active_window() {
27            Ok(new_window) => {
28              if new_window.id.ne(&current_window.id)
29                || new_window.title.ne(&current_window.title)
30                || new_window
31                  .info
32                  .process_id
33                  .ne(&current_window.info.process_id)
34              {
35                current_window = new_window.clone();
36                callback(Ok(new_window));
37              }
38            }
39            Err(e) => {
40              eprintln!("Err: {:?}", e);
41            }
42          }
43          thread::sleep(Duration::from_millis(interval));
44        }
45      }
46    }
47  });
48
49  sender
50}