1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crowser::{error::CrowserError, RemoteConfig, Window};

fn main() -> Result<(), CrowserError> {
  let mut profile_dir = std::env::current_dir()?;
  profile_dir.push("example_profiles");

  let config = RemoteConfig {
    url: "https://example.com".to_string(),
  };

  let mut window = Window::new(config, None, profile_dir)?;
  let ipc = window.get_ipc();

  window.clear_profile().unwrap_or_default();

  std::thread::spawn(move || {
    std::thread::sleep(std::time::Duration::from_secs(10));

    if let Some(ipc) = ipc.lock().unwrap().as_mut() {
      ipc.eval("alert('Hello from Crowser!')").unwrap_or_default();
    }
  });

  window.create()?;

  Ok(())
}