| 1 | use std::path::PathBuf; |
| 2 | use std::time::{Duration, Instant}; |
| 3 | |
| 4 | use session::{App, Method, Scope, Session, SessionConfig}; |
| 5 | |
| 6 | #[tokio::main] |
| 7 | async fn main() { |
| 8 | let folder = std::env::args().nth(1).map(PathBuf::from).expect("usage: probe <user-data-folder> [hold-seconds]"); |
| 9 | let hold = std::env::args().nth(2).and_then(|value| value.parse().ok()).unwrap_or(0); |
| 10 | let started = Instant::now(); |
| 11 | let transport = webview::start(webview::HostConfig { |
| 12 | user_data_folder: folder, |
| 13 | window_title: "Rusty Teams probe - Anmeldung".into(), |
| 14 | }); |
| 15 | let session = match Session::with_transport(transport, SessionConfig::default()).await { |
| 16 | Ok(session) => session, |
| 17 | Err(error) => return println!("connect failed after {:?}: {error}", started.elapsed()), |
| 18 | }; |
| 19 | println!("webviews ready after {:?}", started.elapsed()); |
| 20 | graph_calls(&session, "loaded").await; |
| 21 | match session.subscribe(App::Teams).await { |
| 22 | Ok((control, _events)) => match control.enable_events().await { |
| 23 | Ok(()) => println!("teams events: enabled"), |
| 24 | Err(error) => println!("teams events: {error}"), |
| 25 | }, |
| 26 | Err(error) => println!("teams subscribe: {error}"), |
| 27 | } |
| 28 | println!("holding {hold} s"); |
| 29 | tokio::time::sleep(Duration::from_secs(hold)).await; |
| 30 | graph_calls(&session, "after hold").await; |
| 31 | } |
| 32 | |
| 33 | async fn graph_calls(session: &Session, phase: &str) { |
| 34 | for (label, url, scope) in [ |
| 35 | ("graph me", "https://graph.microsoft.com/v1.0/me?$select=id", Scope::graph("User.Read")), |
| 36 | ("graph chats", "https://graph.microsoft.com/v1.0/me/chats?$top=1&$select=id", Scope::graph("Chat.Read")), |
| 37 | ] { |
| 38 | let call = Instant::now(); |
| 39 | match session.request(Method::Get, url, &scope, None).await { |
| 40 | Ok(response) => println!("{phase} {label}: HTTP {} after {:?}", response.status, call.elapsed()), |
| 41 | Err(error) => println!("{phase} {label}: failed after {:?}: {}", call.elapsed(), error.to_string().chars().take(160).collect::<String>()), |
| 42 | } |
| 43 | } |
| 44 | } |