BlueGit

ict rusty-teams

fix(linux): Outlook tab, GIFs and window id from issue 8

- Requests without a token go to the Teams tab first (Outlook mail CSP blocked Giphy GIFs)
- A failed image load is logged with its host
- Over the debug port the app opens Outlook on the web next to a signed-in Teams when missing
- Main window sets the Wayland app_id / X11 WM_CLASS rusty-teams

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
c5287e41fe8a88922f0fc5449fe630b657489f0a
Parent
ae072b7d
6 files changed +75 −5
README.md +1 −1
@@ -84,7 +84,7 @@
84 84 | Platform | State |
85 85 |---|---|
86 86 | 🪟 Windows | Main target. Login through an embedded WebView2 |
87 | 🐧 Linux | Connects to a Chrome started with `--remote-debugging-port=9222`. Built-in login is planned |
87 | 🐧 Linux | Connects to a Chrome started with `--remote-debugging-port=9222` and signed in to Teams on the web. The app opens an Outlook on the web tab next to it when missing (some tenants grant chat scopes only to Outlook). Built-in login is planned |
88 88 | 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |
89 89
90 90 The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).
@@ -84,7 +84,7 @@
84| Platform | State |
84| Platform | State |
85|---|---|
85|---|---|
86| 🪟 Windows | Main target. Login through an embedded WebView2 |
86| 🪟 Windows | Main target. Login through an embedded WebView2 |
87| 🐧 Linux | Connects to a Chrome started with `--remote-debugging-port=9222`. Built-in login is planned |
87| 🐧 Linux | Connects to a Chrome started with `--remote-debugging-port=9222` and signed in to Teams on the web. The app opens an Outlook on the web tab next to it when missing (some tenants grant chat scopes only to Outlook). Built-in login is planned |
88| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |
88| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |
89
89
90The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).
90The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).
crates/app-state/src/app_state.rs +8 −1
@@ -629,7 +629,14 @@ impl AppState {
629 629 None => {
630 630 let done = data::fetch_image(&engine, image.clone());
631 631 cx.spawn(async move |this, cx| {
632 if !matches!(done.await, Ok(Ok(()))) {
632 let failure = match done.await {
633 Ok(Ok(())) => None,
634 Ok(Err(error)) => Some(error),
635 Err(_) => Some("cancelled".to_owned()),
636 };
637 if let Some(failure) = failure {
638 let host = image.url.split("://").nth(1).and_then(|rest| rest.split('/').next()).unwrap_or_default();
639 log::warn!("image from {host} not loaded: {failure}");
633 640 this.update(cx, |state, cx| {
634 641 state.directory.mark_image_failed(&image.url);
635 642 cx.notify();
@@ -629,7 +629,14 @@ impl AppState {
629 None => {
629 None => {
630 let done = data::fetch_image(&engine, image.clone());
630 let done = data::fetch_image(&engine, image.clone());
631 cx.spawn(async move |this, cx| {
631 cx.spawn(async move |this, cx| {
632 if !matches!(done.await, Ok(Ok(()))) {
632 let failure = match done.await {
633 Ok(Ok(())) => None,
634 Ok(Err(error)) => Some(error),
635 Err(_) => Some("cancelled".to_owned()),
636 };
637 if let Some(failure) = failure {
638 let host = image.url.split("://").nth(1).and_then(|rest| rest.split('/').next()).unwrap_or_default();
639 log::warn!("image from {host} not loaded: {failure}");
633 this.update(cx, |state, cx| {
640 this.update(cx, |state, cx| {
634 state.directory.mark_image_failed(&image.url);
641 state.directory.mark_image_failed(&image.url);
635 cx.notify();
642 cx.notify();
crates/app/src/main.rs +2 −0
@@ -27,6 +27,7 @@ use store::Store;
27 27 use crate::app_state::{AppState, Mode};
28 28 use views::shell::{AppShell, OpenTarget, Startup, bind_keys};
29 29
30 const LINUX_APP_ID: &str = "rusty-teams";
30 31 const VERSION_MARKER: &str = concat!("teams-build:", env!("TEAMS_BUILD_VERSION"));
31 32 const HTTP_USER_AGENT: &str = "teams-linux";
32 33 const WINDOW_WIDTH: f32 = 1240.;
@@ -240,6 +241,7 @@ fn main() {
240 241 let mut options = TitleBar::window_options();
241 242 options.window_bounds = Some(WindowBounds::Windowed(bounds));
242 243 options.window_min_size = Some(size(px(WINDOW_MIN_WIDTH), px(WINDOW_MIN_HEIGHT)));
244 options.app_id = Some(LINUX_APP_ID.to_owned());
243 245 if let Some(titlebar) = options.titlebar.as_mut() {
244 246 titlebar.title = Some(APP_NAME.into());
245 247 }
@@ -27,6 +27,7 @@ use store::Store;
27use crate::app_state::{AppState, Mode};
27use crate::app_state::{AppState, Mode};
28use views::shell::{AppShell, OpenTarget, Startup, bind_keys};
28use views::shell::{AppShell, OpenTarget, Startup, bind_keys};
29
29
30const LINUX_APP_ID: &str = "rusty-teams";
30const VERSION_MARKER: &str = concat!("teams-build:", env!("TEAMS_BUILD_VERSION"));
31const VERSION_MARKER: &str = concat!("teams-build:", env!("TEAMS_BUILD_VERSION"));
31const HTTP_USER_AGENT: &str = "teams-linux";
32const HTTP_USER_AGENT: &str = "teams-linux";
32const WINDOW_WIDTH: f32 = 1240.;
33const WINDOW_WIDTH: f32 = 1240.;
@@ -240,6 +241,7 @@ fn main() {
240 let mut options = TitleBar::window_options();
241 let mut options = TitleBar::window_options();
241 options.window_bounds = Some(WindowBounds::Windowed(bounds));
242 options.window_bounds = Some(WindowBounds::Windowed(bounds));
242 options.window_min_size = Some(size(px(WINDOW_MIN_WIDTH), px(WINDOW_MIN_HEIGHT)));
243 options.window_min_size = Some(size(px(WINDOW_MIN_WIDTH), px(WINDOW_MIN_HEIGHT)));
244 options.app_id = Some(LINUX_APP_ID.to_owned());
243 if let Some(titlebar) = options.titlebar.as_mut() {
245 if let Some(titlebar) = options.titlebar.as_mut() {
244 titlebar.title = Some(APP_NAME.into());
246 titlebar.title = Some(APP_NAME.into());
245 }
247 }
crates/session/src/http.rs +13 −1
@@ -10,12 +10,16 @@ use crate::error::{Error, Result};
10 10 const HTTP_TIMEOUT: Duration = Duration::from_secs(5);
11 11
12 12 async fn get(endpoint: &str, path: &str) -> std::result::Result<Vec<u8>, String> {
13 exchange(endpoint, "GET", path).await
14 }
15
16 async fn exchange(endpoint: &str, method: &str, path: &str) -> std::result::Result<Vec<u8>, String> {
13 17 let parsed = Url::parse(endpoint).map_err(|error| error.to_string())?;
14 18 let host = parsed.host_str().ok_or("endpoint has no host")?;
15 19 let port = parsed.port_or_known_default().unwrap_or(80);
16 20 let exchange = async {
17 21 let mut stream = TcpStream::connect((host, port)).await.map_err(|error| error.to_string())?;
18 let request = format!("GET {path} HTTP/1.1\r\nHost: {host}:{port}\r\nConnection: close\r\n\r\n");
22 let request = format!("{method} {path} HTTP/1.1\r\nHost: {host}:{port}\r\nConnection: close\r\n\r\n");
19 23 stream.write_all(request.as_bytes()).await.map_err(|error| error.to_string())?;
20 24 read_response(&mut stream).await
21 25 };
@@ -76,6 +80,14 @@ pub async fn list_targets(endpoint: &str) -> Result<Vec<Target>> {
76 80 serde_json::from_slice(&body).map_err(|error| no_browser(error.to_string()))
77 81 }
78 82
83 /// Opens a background tab; Chrome 111+ only accepts PUT here.
84 pub async fn new_tab(endpoint: &str, url: &str) -> Result<()> {
85 exchange(endpoint, "PUT", &format!("/json/new?{url}"))
86 .await
87 .map(drop)
88 .map_err(|reason| Error::NoBrowser { endpoint: endpoint.to_owned(), reason })
89 }
90
79 91 #[cfg(test)]
80 92 mod tests {
81 93 use super::*;
@@ -10,12 +10,16 @@ use crate::error::{Error, Result};
10const HTTP_TIMEOUT: Duration = Duration::from_secs(5);
10const HTTP_TIMEOUT: Duration = Duration::from_secs(5);
11
11
12async fn get(endpoint: &str, path: &str) -> std::result::Result<Vec<u8>, String> {
12async fn get(endpoint: &str, path: &str) -> std::result::Result<Vec<u8>, String> {
13 exchange(endpoint, "GET", path).await
14}
15
16async fn exchange(endpoint: &str, method: &str, path: &str) -> std::result::Result<Vec<u8>, String> {
13 let parsed = Url::parse(endpoint).map_err(|error| error.to_string())?;
17 let parsed = Url::parse(endpoint).map_err(|error| error.to_string())?;
14 let host = parsed.host_str().ok_or("endpoint has no host")?;
18 let host = parsed.host_str().ok_or("endpoint has no host")?;
15 let port = parsed.port_or_known_default().unwrap_or(80);
19 let port = parsed.port_or_known_default().unwrap_or(80);
16 let exchange = async {
20 let exchange = async {
17 let mut stream = TcpStream::connect((host, port)).await.map_err(|error| error.to_string())?;
21 let mut stream = TcpStream::connect((host, port)).await.map_err(|error| error.to_string())?;
18 let request = format!("GET {path} HTTP/1.1\r\nHost: {host}:{port}\r\nConnection: close\r\n\r\n");
22 let request = format!("{method} {path} HTTP/1.1\r\nHost: {host}:{port}\r\nConnection: close\r\n\r\n");
19 stream.write_all(request.as_bytes()).await.map_err(|error| error.to_string())?;
23 stream.write_all(request.as_bytes()).await.map_err(|error| error.to_string())?;
20 read_response(&mut stream).await
24 read_response(&mut stream).await
21 };
25 };
@@ -76,6 +80,14 @@ pub async fn list_targets(endpoint: &str) -> Result<Vec<Target>> {
76 serde_json::from_slice(&body).map_err(|error| no_browser(error.to_string()))
80 serde_json::from_slice(&body).map_err(|error| no_browser(error.to_string()))
77}
81}
78
82
83/// Opens a background tab; Chrome 111+ only accepts PUT here.
84pub async fn new_tab(endpoint: &str, url: &str) -> Result<()> {
85 exchange(endpoint, "PUT", &format!("/json/new?{url}"))
86 .await
87 .map(drop)
88 .map_err(|reason| Error::NoBrowser { endpoint: endpoint.to_owned(), reason })
89}
90
79#[cfg(test)]
91#[cfg(test)]
80mod tests {
92mod tests {
81 use super::*;
93 use super::*;
crates/session/src/session.rs +19 −1
@@ -200,7 +200,7 @@ impl Session {
200 200 let payload = self.payload(requests, scope);
201 201 let expression = format!("({FETCH_SCRIPT})({payload})");
202 202 let has_write = requests.iter().any(|request| request.method != Method::Get);
203 for app in scope.tab_order() {
203 for app in tab_order(requests, scope) {
204 204 let outcome = match self.evaluate_in(app, &expression).await {
205 205 Ok(Some(value)) => value,
206 206 Ok(None) => continue,
@@ -299,6 +299,15 @@ pub(crate) fn retry_wait(header: Option<&str>, default: Duration) -> Duration {
299 299 .unwrap_or(default)
300 300 }
301 301
302 /// Requests without a token go to the Teams tab first: the Outlook mail page's CSP blocks cross-origin fetches.
303 fn tab_order(requests: &[&Request], scope: &Scope) -> [App; 2] {
304 if requests.iter().all(|request| request.anonymous) {
305 [App::Teams, App::Outlook]
306 } else {
307 scope.tab_order()
308 }
309 }
310
302 311 #[cfg(test)]
303 312 mod tests {
304 313 use std::sync::Mutex as StdMutex;
@@ -357,4 +366,13 @@ mod tests {
357 366 assert_eq!(retry_wait(Some("Wed, 21 Oct 2026 07:28:00 GMT"), default), default);
358 367 assert_eq!(retry_wait(Some("-3"), default), default);
359 368 }
369
370 #[test]
371 fn anonymous_requests_try_the_teams_tab_first() {
372 let chat_scope = Scope::graph("Chat.Read");
373 let image = Request::anonymous_binary_get("https://media.giphy.com/media/x/giphy.gif", Vec::new());
374 let chats = Request::get("https://graph.microsoft.com/v1.0/me/chats");
375 assert_eq!(tab_order(&[&image], &chat_scope), [App::Teams, App::Outlook]);
376 assert_eq!(tab_order(&[&chats], &chat_scope), [App::Outlook, App::Teams]);
377 }
360 378 }
@@ -200,7 +200,7 @@ impl Session {
200 let payload = self.payload(requests, scope);
200 let payload = self.payload(requests, scope);
201 let expression = format!("({FETCH_SCRIPT})({payload})");
201 let expression = format!("({FETCH_SCRIPT})({payload})");
202 let has_write = requests.iter().any(|request| request.method != Method::Get);
202 let has_write = requests.iter().any(|request| request.method != Method::Get);
203 for app in scope.tab_order() {
203 for app in tab_order(requests, scope) {
204 let outcome = match self.evaluate_in(app, &expression).await {
204 let outcome = match self.evaluate_in(app, &expression).await {
205 Ok(Some(value)) => value,
205 Ok(Some(value)) => value,
206 Ok(None) => continue,
206 Ok(None) => continue,
@@ -299,6 +299,15 @@ pub(crate) fn retry_wait(header: Option<&str>, default: Duration) -> Duration {
299 .unwrap_or(default)
299 .unwrap_or(default)
300}
300}
301
301
302/// Requests without a token go to the Teams tab first: the Outlook mail page's CSP blocks cross-origin fetches.
303fn tab_order(requests: &[&Request], scope: &Scope) -> [App; 2] {
304 if requests.iter().all(|request| request.anonymous) {
305 [App::Teams, App::Outlook]
306 } else {
307 scope.tab_order()
308 }
309}
310
302#[cfg(test)]
311#[cfg(test)]
303mod tests {
312mod tests {
304 use std::sync::Mutex as StdMutex;
313 use std::sync::Mutex as StdMutex;
@@ -357,4 +366,13 @@ mod tests {
357 assert_eq!(retry_wait(Some("Wed, 21 Oct 2026 07:28:00 GMT"), default), default);
366 assert_eq!(retry_wait(Some("Wed, 21 Oct 2026 07:28:00 GMT"), default), default);
358 assert_eq!(retry_wait(Some("-3"), default), default);
367 assert_eq!(retry_wait(Some("-3"), default), default);
359 }
368 }
369
370 #[test]
371 fn anonymous_requests_try_the_teams_tab_first() {
372 let chat_scope = Scope::graph("Chat.Read");
373 let image = Request::anonymous_binary_get("https://media.giphy.com/media/x/giphy.gif", Vec::new());
374 let chats = Request::get("https://graph.microsoft.com/v1.0/me/chats");
375 assert_eq!(tab_order(&[&image], &chat_scope), [App::Teams, App::Outlook]);
376 assert_eq!(tab_order(&[&chats], &chat_scope), [App::Outlook, App::Teams]);
377 }
360}
378}
crates/session/src/transport.rs +32 −1
@@ -1,12 +1,13 @@
1 1 use std::future::Future;
2 2 use std::pin::Pin;
3 use std::sync::atomic::{AtomicBool, Ordering};
3 4
4 5 use serde_json::json;
5 6
6 7 use crate::app::{App, find_app_tab, has_login_tab};
7 8 use crate::error::Result;
8 9 use crate::events::{TabControl, TabEvents, open};
9 use crate::http::list_targets;
10 use crate::http::{list_targets, new_tab};
10 11
11 12 pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
12 13 pub type OpenedTab = (TabControl, Option<TabEvents>);
@@ -35,16 +36,23 @@ pub trait Transport: Send + Sync {
35 36
36 37 pub struct CdpTransport {
37 38 endpoint: String,
39 outlook_requested: AtomicBool,
38 40 }
39 41
40 42 impl CdpTransport {
41 43 pub fn new(endpoint: &str) -> Self {
42 44 CdpTransport {
43 45 endpoint: endpoint.trim_end_matches('/').to_owned(),
46 outlook_requested: AtomicBool::new(false),
44 47 }
45 48 }
46 49 }
47 50
51 /// Some tenants grant the Teams web client no Graph chat scopes; Outlook on the web has them and signs in silently next to a signed-in Teams.
52 fn wants_outlook_tab(targets: &[crate::app::Target], app: App) -> bool {
53 app == App::Outlook && find_app_tab(targets, App::Teams).is_some() && !has_login_tab(targets)
54 }
55
48 56 impl Transport for CdpTransport {
49 57 fn check(&self) -> BoxFuture<'_, Result<()>> {
50 58 Box::pin(async move { list_targets(&self.endpoint).await.map(drop) })
@@ -54,6 +62,9 @@ impl Transport for CdpTransport {
54 62 Box::pin(async move {
55 63 let targets = list_targets(&self.endpoint).await?;
56 64 let Some(websocket_url) = find_app_tab(&targets, app).and_then(|target| target.websocket_url.clone()) else {
65 if wants_outlook_tab(&targets, app) && !self.outlook_requested.swap(true, Ordering::SeqCst) {
66 new_tab(&self.endpoint, App::Outlook.start_url()).await?;
67 }
57 68 return Ok(None);
58 69 };
59 70 open(&websocket_url, with_events).await.map(Some)
@@ -87,3 +98,23 @@ impl Transport for CdpTransport {
87 98 })
88 99 }
89 100 }
101
102 #[cfg(test)]
103 mod tests {
104 use super::*;
105 use crate::app::Target;
106
107 fn page(url: &str) -> Target {
108 Target { kind: "page".to_owned(), url: url.to_owned(), websocket_url: Some("ws://tab".to_owned()) }
109 }
110
111 #[test]
112 fn outlook_opens_only_next_to_a_signed_in_teams_tab() {
113 let teams = page("https://teams.cloud.microsoft/");
114 let login = page("https://login.microsoftonline.com/common/oauth2");
115 assert!(wants_outlook_tab(&[teams.clone()], App::Outlook));
116 assert!(!wants_outlook_tab(&[teams.clone()], App::Teams));
117 assert!(!wants_outlook_tab(&[], App::Outlook));
118 assert!(!wants_outlook_tab(&[teams, login], App::Outlook));
119 }
120 }
@@ -1,12 +1,13 @@
1use std::future::Future;
1use std::future::Future;
2use std::pin::Pin;
2use std::pin::Pin;
3use std::sync::atomic::{AtomicBool, Ordering};
3
4
4use serde_json::json;
5use serde_json::json;
5
6
6use crate::app::{App, find_app_tab, has_login_tab};
7use crate::app::{App, find_app_tab, has_login_tab};
7use crate::error::Result;
8use crate::error::Result;
8use crate::events::{TabControl, TabEvents, open};
9use crate::events::{TabControl, TabEvents, open};
9use crate::http::list_targets;
10use crate::http::{list_targets, new_tab};
10
11
11pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
12pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
12pub type OpenedTab = (TabControl, Option<TabEvents>);
13pub type OpenedTab = (TabControl, Option<TabEvents>);
@@ -35,16 +36,23 @@ pub trait Transport: Send + Sync {
35
36
36pub struct CdpTransport {
37pub struct CdpTransport {
37 endpoint: String,
38 endpoint: String,
39 outlook_requested: AtomicBool,
38}
40}
39
41
40impl CdpTransport {
42impl CdpTransport {
41 pub fn new(endpoint: &str) -> Self {
43 pub fn new(endpoint: &str) -> Self {
42 CdpTransport {
44 CdpTransport {
43 endpoint: endpoint.trim_end_matches('/').to_owned(),
45 endpoint: endpoint.trim_end_matches('/').to_owned(),
46 outlook_requested: AtomicBool::new(false),
44 }
47 }
45 }
48 }
46}
49}
47
50
51/// Some tenants grant the Teams web client no Graph chat scopes; Outlook on the web has them and signs in silently next to a signed-in Teams.
52fn wants_outlook_tab(targets: &[crate::app::Target], app: App) -> bool {
53 app == App::Outlook && find_app_tab(targets, App::Teams).is_some() && !has_login_tab(targets)
54}
55
48impl Transport for CdpTransport {
56impl Transport for CdpTransport {
49 fn check(&self) -> BoxFuture<'_, Result<()>> {
57 fn check(&self) -> BoxFuture<'_, Result<()>> {
50 Box::pin(async move { list_targets(&self.endpoint).await.map(drop) })
58 Box::pin(async move { list_targets(&self.endpoint).await.map(drop) })
@@ -54,6 +62,9 @@ impl Transport for CdpTransport {
54 Box::pin(async move {
62 Box::pin(async move {
55 let targets = list_targets(&self.endpoint).await?;
63 let targets = list_targets(&self.endpoint).await?;
56 let Some(websocket_url) = find_app_tab(&targets, app).and_then(|target| target.websocket_url.clone()) else {
64 let Some(websocket_url) = find_app_tab(&targets, app).and_then(|target| target.websocket_url.clone()) else {
65 if wants_outlook_tab(&targets, app) && !self.outlook_requested.swap(true, Ordering::SeqCst) {
66 new_tab(&self.endpoint, App::Outlook.start_url()).await?;
67 }
57 return Ok(None);
68 return Ok(None);
58 };
69 };
59 open(&websocket_url, with_events).await.map(Some)
70 open(&websocket_url, with_events).await.map(Some)
@@ -87,3 +98,23 @@ impl Transport for CdpTransport {
87 })
98 })
88 }
99 }
89}
100}
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105 use crate::app::Target;
106
107 fn page(url: &str) -> Target {
108 Target { kind: "page".to_owned(), url: url.to_owned(), websocket_url: Some("ws://tab".to_owned()) }
109 }
110
111 #[test]
112 fn outlook_opens_only_next_to_a_signed_in_teams_tab() {
113 let teams = page("https://teams.cloud.microsoft/");
114 let login = page("https://login.microsoftonline.com/common/oauth2");
115 assert!(wants_outlook_tab(&[teams.clone()], App::Outlook));
116 assert!(!wants_outlook_tab(&[teams.clone()], App::Teams));
117 assert!(!wants_outlook_tab(&[], App::Outlook));
118 assert!(!wants_outlook_tab(&[teams, login], App::Outlook));
119 }
120}