-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.rs
47 lines (32 loc) · 1.11 KB
/
commands.rs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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.ipc();
let ipc_thread = std::thread::spawn(move || setup_commands(&ipc));
window.clear_profile().unwrap_or_default();
std::thread::spawn(move || {
});
window.create()?;
ipc_thread.join().expect("Failed to join IPC thread").expect("IPC thread panicked");
Ok(())
}
fn setup_commands(ipc: &crowser::WindowIpc) -> Result<(), CrowserError> {
ipc.block_until_initialized()?;
ipc
.register_command("hello", |_| {
println!("Got hello command");
Ok(serde_json::json!("Hello from Crowser!"))
})?;
std::thread::sleep(std::time::Duration::from_secs(1));
println!("Waiting for result...");
// Eval some JS that calls that command
let result = ipc
.eval("window.__CROWSER.ipc.invoke('hello')")?;
println!("Result: {:?}", result);
Ok(())
}