feat(calls): option to run calls and meetings in Teams on the web
- Settings > Calls: "Use Teams on the web for calls and meetings" - meetings open the Teams join link, chat calls open the chat in a Teams on the web window - new webview dialog mode Call: real navigation, resizable window, mic and camera allowed for Teams origins only Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -157,6 +157,7 @@ pub struct AppState {
157
157
pub chat_settings: teams_core::ChatSettingsDocument,
158
158
pub markdown_mode: bool,
159
159
pub actions_on_right_click: bool,
160
pub web_calls: bool,
160
161
pub demo_chat_desktop: HashMap<String, teams_core::DesktopNotifications>,
161
162
pub own_tenant: Option<String>,
162
163
pub call_share_motion: bool,
@@ -253,6 +254,7 @@ impl AppState {
253
254
let markdown_mode = crate::chat_settings_actions::stored_markdown_mode(&store);
254
255
let actions_on_right_click =
255
256
crate::chat_settings_actions::stored_actions_on_right_click(&store);
257
let web_calls = crate::call::web_call::stored_web_calls(&store);
256
258
let mut state = AppState {
257
259
store,
258
260
engine: None,
@@ -324,6 +326,7 @@ impl AppState {
324
326
chat_settings,
325
327
markdown_mode,
326
328
actions_on_right_click,
329
web_calls,
327
330
demo_chat_desktop: HashMap::new(),
328
331
own_tenant: None,
329
332
call_share_motion: false,
@@ -157,6 +157,7 @@ pub struct AppState {157
pub chat_settings: teams_core::ChatSettingsDocument,157
pub chat_settings: teams_core::ChatSettingsDocument,158
pub markdown_mode: bool,158
pub markdown_mode: bool,159
pub actions_on_right_click: bool,159
pub actions_on_right_click: bool,160
pub web_calls: bool,160
pub demo_chat_desktop: HashMap<String, teams_core::DesktopNotifications>,161
pub demo_chat_desktop: HashMap<String, teams_core::DesktopNotifications>,161
pub own_tenant: Option<String>,162
pub own_tenant: Option<String>,162
pub call_share_motion: bool,163
pub call_share_motion: bool,@@ -253,6 +254,7 @@ impl AppState {253
let markdown_mode = crate::chat_settings_actions::stored_markdown_mode(&store);254
let markdown_mode = crate::chat_settings_actions::stored_markdown_mode(&store);254
let actions_on_right_click =255
let actions_on_right_click =255
crate::chat_settings_actions::stored_actions_on_right_click(&store);256
crate::chat_settings_actions::stored_actions_on_right_click(&store);257
let web_calls = crate::call::web_call::stored_web_calls(&store);256
let mut state = AppState {258
let mut state = AppState {257
store,259
store,258
engine: None,260
engine: None,@@ -324,6 +326,7 @@ impl AppState {324
chat_settings,326
chat_settings,325
markdown_mode,327
markdown_mode,326
actions_on_right_click,328
actions_on_right_click,329
web_calls,327
demo_chat_desktop: HashMap::new(),330
demo_chat_desktop: HashMap::new(),328
own_tenant: None,331
own_tenant: None,329
call_share_motion: false,332
call_share_motion: false,@@ -148,6 +148,10 @@ impl AppState {
148
148
self.start_test_call(cx);
149
149
return;
150
150
}
151
if self.try_web_call(super::web_call::chat_web_url(conversation_id), cx) {
152
return;
153
}
154
let chat = self.sidebar.chats.iter().find(|chat| chat.id == conversation_id);
151
155
let plan = chat.and_then(|chat| plan_for_chat(chat, self.directory.me.as_ref()));
152
156
let Some(plan) = plan else {
153
157
self.raise_notice(NOT_CALLABLE_NOTICE.to_owned(), None, cx);
@@ -195,6 +199,9 @@ impl AppState {
195
199
self.raise_notice(MEETING_UNAVAILABLE_NOTICE.to_owned(), None, cx);
196
200
return;
197
201
};
202
if self.try_web_call(super::web_call::meeting_web_url(&target), cx) {
203
return;
204
}
198
205
let demo = DemoMeeting {
199
206
guests: if conversation_id == DEMO_LOBBY_MEETING {
200
207
DEMO_SMALL_MEETING
@@ -148,6 +148,10 @@ impl AppState {148
self.start_test_call(cx);148
self.start_test_call(cx);149
return;149
return;150
}150
}151
if self.try_web_call(super::web_call::chat_web_url(conversation_id), cx) {152
return;153
}154
let chat = self.sidebar.chats.iter().find(|chat| chat.id == conversation_id);151
let plan = chat.and_then(|chat| plan_for_chat(chat, self.directory.me.as_ref()));155
let plan = chat.and_then(|chat| plan_for_chat(chat, self.directory.me.as_ref()));152
let Some(plan) = plan else {156
let Some(plan) = plan else {153
self.raise_notice(NOT_CALLABLE_NOTICE.to_owned(), None, cx);157
self.raise_notice(NOT_CALLABLE_NOTICE.to_owned(), None, cx);@@ -195,6 +199,9 @@ impl AppState {195
self.raise_notice(MEETING_UNAVAILABLE_NOTICE.to_owned(), None, cx);199
self.raise_notice(MEETING_UNAVAILABLE_NOTICE.to_owned(), None, cx);196
return;200
return;197
};201
};202
if self.try_web_call(super::web_call::meeting_web_url(&target), cx) {203
return;204
}198
let demo = DemoMeeting {205
let demo = DemoMeeting {199
guests: if conversation_id == DEMO_LOBBY_MEETING {206
guests: if conversation_id == DEMO_LOBBY_MEETING {200
DEMO_SMALL_MEETING207
DEMO_SMALL_MEETING@@ -46,6 +46,9 @@ impl AppState {
46
46
self.show_call(true, cx);
47
47
return;
48
48
}
49
if self.try_web_call(super::web_call::meeting_web_url(&target), cx) {
50
return;
51
}
49
52
let title = selection_for(&self.sidebar, &target.thread_id)
50
53
.map(|selection| selection_title(&self.sidebar, &selection))
51
54
.unwrap_or_else(|| MEETING_TITLE.to_owned());
@@ -46,6 +46,9 @@ impl AppState {46
self.show_call(true, cx);46
self.show_call(true, cx);47
return;47
return;48
}48
}49
if self.try_web_call(super::web_call::meeting_web_url(&target), cx) {50
return;51
}49
let title = selection_for(&self.sidebar, &target.thread_id)52
let title = selection_for(&self.sidebar, &target.thread_id)50
.map(|selection| selection_title(&self.sidebar, &selection))53
.map(|selection| selection_title(&self.sidebar, &selection))51
.unwrap_or_else(|| MEETING_TITLE.to_owned());54
.unwrap_or_else(|| MEETING_TITLE.to_owned());@@ -18,6 +18,7 @@ pub mod share_overlay;
18
18
pub mod schedule;
19
19
pub mod target;
20
20
pub mod view_actions;
21
pub mod web_call;
21
22
22
23
pub use app_call_model::{
23
24
agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,
@@ -18,6 +18,7 @@ pub mod share_overlay;18
pub mod schedule;18
pub mod schedule;19
pub mod target;19
pub mod target;20
pub mod view_actions;20
pub mod view_actions;21
pub mod web_call;21
22
22
pub use app_call_model::{23
pub use app_call_model::{23
agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,24
agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,@@ -0,0 +1,97 @@
1
use calling::MeetingTarget;
2
use gpui_kit::*;
3
use serde_json::json;
4
5
use crate::app_state::AppState;
6
7
pub const META_WEB_CALLS: &str = "calls.teams_web";
8
const TEAMS_WEB: &str = "https://teams.microsoft.com/l";
9
const WEB_CALL_TITLE: &str = "Teams call";
10
11
pub fn stored_web_calls(store: &store::Store) -> bool {
12
store.meta(META_WEB_CALLS).ok().flatten().as_deref() == Some("true")
13
}
14
15
pub fn meeting_web_url(target: &MeetingTarget) -> String {
16
let context = json!({"Tid": target.tenant_id, "Oid": target.organizer_id}).to_string();
17
format!(
18
"{TEAMS_WEB}/meetup-join/{}/0?context={}",
19
encode(&target.thread_id),
20
encode(&context)
21
)
22
}
23
24
/// Teams on the web has no call link for a chat id, so the chat opens and the call starts there.
25
pub fn chat_web_url(thread_id: &str) -> String {
26
format!("{TEAMS_WEB}/chat/{}/0", encode(thread_id))
27
}
28
29
fn encode(text: &str) -> String {
30
text.bytes()
31
.map(|byte| match byte {
32
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
33
(byte as char).to_string()
34
}
35
byte => format!("%{byte:02X}"),
36
})
37
.collect()
38
}
39
40
impl AppState {
41
pub fn set_web_calls(&mut self, enabled: bool, cx: &mut Context<Self>) {
42
self.web_calls = enabled;
43
let _ = self
44
.store
45
.set_meta(META_WEB_CALLS, if enabled { "true" } else { "false" });
46
cx.notify();
47
}
48
49
/// Opens the call in Teams on the web when that setting is on; false leaves it to the own engine.
50
pub(super) fn try_web_call(&mut self, url: String, cx: &mut Context<Self>) -> bool {
51
if !self.web_calls || self.mode.demo {
52
return false;
53
}
54
open_web_call(url, cx)
55
}
56
}
57
58
#[cfg(windows)]
59
fn open_web_call(url: String, cx: &mut App) -> bool {
60
crate::task_dialog::hosted::open_call_window(url, WEB_CALL_TITLE.to_owned(), cx)
61
}
62
63
#[cfg(not(windows))]
64
fn open_web_call(url: String, cx: &mut App) -> bool {
65
let _ = WEB_CALL_TITLE;
66
cx.open_url(&url);
67
true
68
}
69
70
#[cfg(test)]
71
mod tests {
72
use calling::MeetingTarget;
73
74
use super::{chat_web_url, meeting_web_url};
75
76
#[test]
77
fn a_meeting_opens_the_teams_join_link_with_tenant_and_organizer() {
78
let target = MeetingTarget {
79
thread_id: "19:meeting_abc@thread.v2".to_owned(),
80
tenant_id: "tenant-1".to_owned(),
81
organizer_id: "organizer-1".to_owned(),
82
meeting_data: None,
83
};
84
assert_eq!(
85
meeting_web_url(&target),
86
"https://teams.microsoft.com/l/meetup-join/19%3Ameeting_abc%40thread.v2/0?context=%7B%22Tid%22%3A%22tenant-1%22%2C%22Oid%22%3A%22organizer-1%22%7D"
87
);
88
}
89
90
#[test]
91
fn a_chat_opens_its_teams_chat_link() {
92
assert_eq!(
93
chat_web_url("19:abc@thread.v2"),
94
"https://teams.microsoft.com/l/chat/19%3Aabc%40thread.v2/0"
95
);
96
}
97
}
@@ -0,0 +1,97 @@1
use calling::MeetingTarget;2
use gpui_kit::*;3
use serde_json::json;4
5
use crate::app_state::AppState;6
7
pub const META_WEB_CALLS: &str = "calls.teams_web";8
const TEAMS_WEB: &str = "https://teams.microsoft.com/l";9
const WEB_CALL_TITLE: &str = "Teams call";10
11
pub fn stored_web_calls(store: &store::Store) -> bool {12
store.meta(META_WEB_CALLS).ok().flatten().as_deref() == Some("true")13
}14
15
pub fn meeting_web_url(target: &MeetingTarget) -> String {16
let context = json!({"Tid": target.tenant_id, "Oid": target.organizer_id}).to_string();17
format!(18
"{TEAMS_WEB}/meetup-join/{}/0?context={}",19
encode(&target.thread_id),20
encode(&context)21
)22
}23
24
/// Teams on the web has no call link for a chat id, so the chat opens and the call starts there.25
pub fn chat_web_url(thread_id: &str) -> String {26
format!("{TEAMS_WEB}/chat/{}/0", encode(thread_id))27
}28
29
fn encode(text: &str) -> String {30
text.bytes()31
.map(|byte| match byte {32
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {33
(byte as char).to_string()34
}35
byte => format!("%{byte:02X}"),36
})37
.collect()38
}39
40
impl AppState {41
pub fn set_web_calls(&mut self, enabled: bool, cx: &mut Context<Self>) {42
self.web_calls = enabled;43
let _ = self44
.store45
.set_meta(META_WEB_CALLS, if enabled { "true" } else { "false" });46
cx.notify();47
}48
49
/// Opens the call in Teams on the web when that setting is on; false leaves it to the own engine.50
pub(super) fn try_web_call(&mut self, url: String, cx: &mut Context<Self>) -> bool {51
if !self.web_calls || self.mode.demo {52
return false;53
}54
open_web_call(url, cx)55
}56
}57
58
#[cfg(windows)]59
fn open_web_call(url: String, cx: &mut App) -> bool {60
crate::task_dialog::hosted::open_call_window(url, WEB_CALL_TITLE.to_owned(), cx)61
}62
63
#[cfg(not(windows))]64
fn open_web_call(url: String, cx: &mut App) -> bool {65
let _ = WEB_CALL_TITLE;66
cx.open_url(&url);67
true68
}69
70
#[cfg(test)]71
mod tests {72
use calling::MeetingTarget;73
74
use super::{chat_web_url, meeting_web_url};75
76
#[test]77
fn a_meeting_opens_the_teams_join_link_with_tenant_and_organizer() {78
let target = MeetingTarget {79
thread_id: "19:meeting_abc@thread.v2".to_owned(),80
tenant_id: "tenant-1".to_owned(),81
organizer_id: "organizer-1".to_owned(),82
meeting_data: None,83
};84
assert_eq!(85
meeting_web_url(&target),86
"https://teams.microsoft.com/l/meetup-join/19%3Ameeting_abc%40thread.v2/0?context=%7B%22Tid%22%3A%22tenant-1%22%2C%22Oid%22%3A%22organizer-1%22%7D"87
);88
}89
90
#[test]91
fn a_chat_opens_its_teams_chat_link() {92
assert_eq!(93
chat_web_url("19:abc@thread.v2"),94
"https://teams.microsoft.com/l/chat/19%3Aabc%40thread.v2/0"95
);96
}97
}@@ -3,7 +3,7 @@ use std::sync::{Arc, OnceLock};
3
3
use gpui_kit::*;
4
4
use serde_json::json;
5
5
use teams_core::DialogIdentity;
6
use webview::{DialogEvent, DialogHandle, DialogSpec, WebViewTransport};
6
use webview::{DialogEvent, DialogHandle, DialogMode, DialogSpec, WebViewTransport};
7
7
8
8
use super::sdk::{self, Effect, HostContext, HostPage};
9
9
use super::{UrlDialog, UrlDialogNext};
@@ -12,6 +12,8 @@ use crate::backend::Engine;
12
12
use crate::{notify, runtime, theme};
13
13
14
14
static HOST: OnceLock<Arc<WebViewTransport>> = OnceLock::new();
15
const CALL_WINDOW_WIDTH: u32 = 1100;
16
const CALL_WINDOW_HEIGHT: u32 = 760;
15
17
16
18
pub fn install_host(transport: Arc<WebViewTransport>) {
17
19
let _ = HOST.set(transport);
@@ -35,6 +37,35 @@ pub fn open(dialog: UrlDialog, engine: Option<Arc<Engine>>, cx: &mut App) {
35
37
.detach();
36
38
}
37
39
40
/// Teams on the web in its own window, signed in through the shared WebView2 profile.
41
pub fn open_call_window(url: String, title: String, cx: &mut App) -> bool {
42
let Some(host) = HOST.get().cloned() else {
43
return false;
44
};
45
let (_handle, mut events) = host.open_dialog(DialogSpec {
46
mode: DialogMode::Call,
47
title,
48
width: CALL_WINDOW_WIDTH,
49
height: CALL_WINDOW_HEIGHT,
50
background: theme::background_hex(),
51
owner: None,
52
page_url: url,
53
page_html: String::new(),
54
});
55
cx.spawn(async move |cx| {
56
while let Some(DialogEvent::Message(raw)) = events.recv().await {
57
let link = serde_json::from_str::<serde_json::Value>(&raw)
58
.ok()
59
.and_then(|message| message.get("url")?.as_str().map(str::to_owned));
60
if let Some(link) = link {
61
cx.update(|cx| cx.open_url(&link));
62
}
63
}
64
})
65
.detach();
66
true
67
}
68
38
69
async fn run(
39
70
host: Arc<WebViewTransport>,
40
71
dialog: UrlDialog,
@@ -61,6 +92,7 @@ async fn run(
61
92
}
62
93
.html();
63
94
let (handle, mut events) = host.open_dialog(DialogSpec {
95
mode: DialogMode::Hosted,
64
96
title: dialog.title.clone(),
65
97
width: dialog.width,
66
98
height: dialog.height,
@@ -3,7 +3,7 @@ use std::sync::{Arc, OnceLock};3
use gpui_kit::*;3
use gpui_kit::*;4
use serde_json::json;4
use serde_json::json;5
use teams_core::DialogIdentity;5
use teams_core::DialogIdentity;6
use webview::{DialogEvent, DialogHandle, DialogSpec, WebViewTransport};6
use webview::{DialogEvent, DialogHandle, DialogMode, DialogSpec, WebViewTransport};7
7
8
use super::sdk::{self, Effect, HostContext, HostPage};8
use super::sdk::{self, Effect, HostContext, HostPage};9
use super::{UrlDialog, UrlDialogNext};9
use super::{UrlDialog, UrlDialogNext};@@ -12,6 +12,8 @@ use crate::backend::Engine;12
use crate::{notify, runtime, theme};12
use crate::{notify, runtime, theme};13
13
14
static HOST: OnceLock<Arc<WebViewTransport>> = OnceLock::new();14
static HOST: OnceLock<Arc<WebViewTransport>> = OnceLock::new();15
const CALL_WINDOW_WIDTH: u32 = 1100;16
const CALL_WINDOW_HEIGHT: u32 = 760;15
17
16
pub fn install_host(transport: Arc<WebViewTransport>) {18
pub fn install_host(transport: Arc<WebViewTransport>) {17
let _ = HOST.set(transport);19
let _ = HOST.set(transport);@@ -35,6 +37,35 @@ pub fn open(dialog: UrlDialog, engine: Option<Arc<Engine>>, cx: &mut App) {35
.detach();37
.detach();36
}38
}37
39
40
/// Teams on the web in its own window, signed in through the shared WebView2 profile.41
pub fn open_call_window(url: String, title: String, cx: &mut App) -> bool {42
let Some(host) = HOST.get().cloned() else {43
return false;44
};45
let (_handle, mut events) = host.open_dialog(DialogSpec {46
mode: DialogMode::Call,47
title,48
width: CALL_WINDOW_WIDTH,49
height: CALL_WINDOW_HEIGHT,50
background: theme::background_hex(),51
owner: None,52
page_url: url,53
page_html: String::new(),54
});55
cx.spawn(async move |cx| {56
while let Some(DialogEvent::Message(raw)) = events.recv().await {57
let link = serde_json::from_str::<serde_json::Value>(&raw)58
.ok()59
.and_then(|message| message.get("url")?.as_str().map(str::to_owned));60
if let Some(link) = link {61
cx.update(|cx| cx.open_url(&link));62
}63
}64
})65
.detach();66
true67
}68
38
async fn run(69
async fn run(39
host: Arc<WebViewTransport>,70
host: Arc<WebViewTransport>,40
dialog: UrlDialog,71
dialog: UrlDialog,@@ -61,6 +92,7 @@ async fn run(61
}92
}62
.html();93
.html();63
let (handle, mut events) = host.open_dialog(DialogSpec {94
let (handle, mut events) = host.open_dialog(DialogSpec {95
mode: DialogMode::Hosted,64
title: dialog.title.clone(),96
title: dialog.title.clone(),65
width: dialog.width,97
width: dialog.width,66
height: dialog.height,98
height: dialog.height,@@ -1,11 +1,19 @@
1
1
use gpui_kit::component::{h_flex, v_flex};
2
2
use gpui_kit::*;
3
3
4
use super::rows::{Choice, caption, control_row, select, text_button};
4
use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
5
use crate::app_state::AppState;
6
use crate::theme;
5
7
use crate::notify::NotificationCenter;
6
8
use crate::notify::sounds::{Ringtone, RingtoneCallType};
7
9
8
pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
10
const WEB_CALLS_LABEL: &str = "Use Teams on the web for calls and meetings";
11
const WEB_CALLS_DETAIL: &str =
12
"Joins meetings and opens chat calls in a Teams on the web window instead of the built-in call engine.";
13
14
pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
15
let web_calls = app.read(cx).web_calls;
16
let toggle_app = app.clone();
9
17
let ringtones = center.read(cx).settings().sounds.ringtones;
10
18
let rows = RingtoneCallType::ALL
11
19
.into_iter()
@@ -13,7 +21,23 @@ pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
13
21
*call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
14
22
})
15
23
.map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
16
v_flex().w_full().child(caption("RINGTONES")).children(rows)
24
v_flex()
25
.w_full()
26
.child(caption("CALL ENGINE"))
27
.child(
28
toggle_row(
29
"settings-web-calls",
30
WEB_CALLS_LABEL,
31
WEB_CALLS_DETAIL,
32
theme::text_muted(),
33
web_calls,
34
)
35
.on_click(move |_, _, cx| {
36
toggle_app.update(cx, |state, cx| state.set_web_calls(!web_calls, cx))
37
}),
38
)
39
.child(caption("RINGTONES"))
40
.children(rows)
17
41
}
18
42
19
43
fn ringtone_row(
@@ -1,11 +1,19 @@1
use gpui_kit::component::{h_flex, v_flex};1
use gpui_kit::component::{h_flex, v_flex};2
use gpui_kit::*;2
use gpui_kit::*;3
3
4
use super::rows::{Choice, caption, control_row, select, text_button};4
use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};5
use crate::app_state::AppState;6
use crate::theme;5
use crate::notify::NotificationCenter;7
use crate::notify::NotificationCenter;6
use crate::notify::sounds::{Ringtone, RingtoneCallType};8
use crate::notify::sounds::{Ringtone, RingtoneCallType};7
9
8
pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {10
const WEB_CALLS_LABEL: &str = "Use Teams on the web for calls and meetings";11
const WEB_CALLS_DETAIL: &str =12
"Joins meetings and opens chat calls in a Teams on the web window instead of the built-in call engine.";13
14
pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {15
let web_calls = app.read(cx).web_calls;16
let toggle_app = app.clone();9
let ringtones = center.read(cx).settings().sounds.ringtones;17
let ringtones = center.read(cx).settings().sounds.ringtones;10
let rows = RingtoneCallType::ALL18
let rows = RingtoneCallType::ALL11
.into_iter()19
.into_iter()@@ -13,7 +21,23 @@ pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {13
*call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring21
*call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring14
})22
})15
.map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));23
.map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));16
v_flex().w_full().child(caption("RINGTONES")).children(rows)24
v_flex()25
.w_full()26
.child(caption("CALL ENGINE"))27
.child(28
toggle_row(29
"settings-web-calls",30
WEB_CALLS_LABEL,31
WEB_CALLS_DETAIL,32
theme::text_muted(),33
web_calls,34
)35
.on_click(move |_, _, cx| {36
toggle_app.update(cx, |state, cx| state.set_web_calls(!web_calls, cx))37
}),38
)39
.child(caption("RINGTONES"))40
.children(rows)17
}41
}18
42
19
fn ringtone_row(43
fn ringtone_row(@@ -140,7 +140,7 @@ impl SettingsDialog {
140
140
}
141
141
SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),
142
142
SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
143
SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),
143
SettingsSection::Calls => calls::render(&self.center, &self.app, cx).into_any_element(),
144
144
SettingsSection::Devices => self
145
145
.devices
146
146
.clone()
@@ -140,7 +140,7 @@ impl SettingsDialog {140
}140
}141
SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),141
SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),142
SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),142
SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),143
SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),143
SettingsSection::Calls => calls::render(&self.center, &self.app, cx).into_any_element(),144
SettingsSection::Devices => self144
SettingsSection::Devices => self145
.devices145
.devices146
.clone()146
.clone()@@ -2,8 +2,16 @@ use std::sync::{Arc, mpsc};
2
2
3
3
use crate::transport::UiRequest;
4
4
5
/// `Hosted` serves `page_html` at `page_url` for an app dialog; `Call` loads Teams on the web itself.
6
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7
pub enum DialogMode {
8
Hosted,
9
Call,
10
}
11
5
12
#[derive(Debug, Clone)]
6
13
pub struct DialogSpec {
14
pub mode: DialogMode,
7
15
pub title: String,
8
16
pub width: u32,
9
17
pub height: u32,
@@ -2,8 +2,16 @@ use std::sync::{Arc, mpsc};2
2
3
use crate::transport::UiRequest;3
use crate::transport::UiRequest;4
4
5
/// `Hosted` serves `page_html` at `page_url` for an app dialog; `Call` loads Teams on the web itself.6
#[derive(Debug, Clone, Copy, PartialEq, Eq)]7
pub enum DialogMode {8
Hosted,9
Call,10
}11
5
#[derive(Debug, Clone)]12
#[derive(Debug, Clone)]6
pub struct DialogSpec {13
pub struct DialogSpec {14
pub mode: DialogMode,7
pub title: String,15
pub title: String,8
pub width: u32,16
pub width: u32,9
pub height: u32,17
pub height: u32,@@ -4,7 +4,7 @@ use tokio::sync::mpsc::UnboundedSender;
4
4
use webview2_com::Microsoft::Web::WebView2::Win32::*;
5
5
use webview2_com::{
6
6
AcceleratorKeyPressedEventHandler, CreateCoreWebView2ControllerCompletedHandler,
7
NewWindowRequestedEventHandler, WebMessageReceivedEventHandler,
7
NewWindowRequestedEventHandler, PermissionRequestedEventHandler, WebMessageReceivedEventHandler,
8
8
WebResourceRequestedEventHandler, take_pwstr,
9
9
};
10
10
use windows::Win32::Foundation::{COLORREF, HINSTANCE, HWND, LPARAM, LRESULT, RECT, WPARAM};
@@ -18,11 +18,17 @@ use windows::Win32::UI::Shell::SHCreateMemStream;
18
18
use windows::Win32::UI::WindowsAndMessaging::*;
19
19
use windows::core::{HSTRING, Interface, PWSTR, w};
20
20
21
use crate::dialog::{DialogCommand, DialogEvent, DialogSpec};
21
use crate::dialog::{DialogCommand, DialogEvent, DialogMode, DialogSpec};
22
22
use crate::host::{Shared, fit, shared as running_host};
23
23
24
24
const DIALOG_CLASS: windows::core::PCWSTR = w!("RustyTeamsDialog");
25
25
const DIALOG_STYLE: WINDOW_STYLE = WINDOW_STYLE(WS_CAPTION.0 | WS_SYSMENU.0);
26
const CALL_STYLE: WINDOW_STYLE = WS_OVERLAPPEDWINDOW;
27
const MEDIA_ORIGINS: [&str; 3] = [
28
"https://teams.microsoft.com/",
29
"https://teams.cloud.microsoft/",
30
"https://teams.live.com/",
31
];
26
32
const BASE_DPI: u32 = 96;
27
33
const VIRTUAL_KEY_ESCAPE: u32 = 0x1B;
28
34
const PAGE_HEADERS: windows::core::PCWSTR =
@@ -41,6 +47,7 @@ pub(crate) struct Dialog {
41
47
}
42
48
43
49
struct HostPage {
50
mode: DialogMode,
44
51
url: String,
45
52
html: String,
46
53
}
@@ -72,6 +79,7 @@ pub(crate) fn open(
72
79
let _ = SetForegroundWindow(window);
73
80
}
74
81
let page = HostPage {
82
mode: spec.mode,
75
83
url: spec.page_url,
76
84
html: spec.page_html,
77
85
};
@@ -234,7 +242,10 @@ fn create_window(spec: &DialogSpec) -> windows::core::Result<HWND> {
234
242
WINDOW_EX_STYLE::default(),
235
243
DIALOG_CLASS,
236
244
&HSTRING::from(spec.title.as_str()),
237
DIALOG_STYLE,
245
match spec.mode {
246
DialogMode::Hosted => DIALOG_STYLE,
247
DialogMode::Call => CALL_STYLE,
248
},
238
249
left,
239
250
top,
240
251
width,
@@ -302,10 +313,15 @@ fn attach(
302
313
})?;
303
314
webview.Settings()?.SetIsStatusBarEnabled(false)?;
304
315
}
305
serve_host_page(&webview, environment, &page)?;
306
forward_messages(&webview, id, &page.url)?;
316
match page.mode {
317
DialogMode::Hosted => {
318
serve_host_page(&webview, environment, &page)?;
319
forward_messages(&webview, id, &page.url)?;
320
close_on_escape(&controller, window)?;
321
}
322
DialogMode::Call => allow_teams_media(&webview)?,
323
}
307
324
forward_new_windows(&webview, id)?;
308
close_on_escape(&controller, window)?;
309
325
unsafe {
310
326
controller.SetIsVisible(true)?;
311
327
webview.Navigate(&HSTRING::from(page.url.as_str()))?;
@@ -381,6 +397,29 @@ fn forward_messages(webview: &ICoreWebView2, id: u64, page_url: &str) -> windows
381
397
unsafe { webview.add_WebMessageReceived(&handler, &mut token) }
382
398
}
383
399
400
fn allow_teams_media(webview: &ICoreWebView2) -> windows::core::Result<()> {
401
let handler = PermissionRequestedEventHandler::create(Box::new(move |_, arguments| {
402
let Some(arguments) = arguments else {
403
return Ok(());
404
};
405
let mut origin = PWSTR::null();
406
let mut kind = COREWEBVIEW2_PERMISSION_KIND::default();
407
unsafe {
408
arguments.Uri(&mut origin)?;
409
arguments.PermissionKind(&mut kind)?;
410
}
411
let origin = take_pwstr(origin);
412
let media = kind == COREWEBVIEW2_PERMISSION_KIND_MICROPHONE
413
|| kind == COREWEBVIEW2_PERMISSION_KIND_CAMERA;
414
if media && MEDIA_ORIGINS.iter().any(|allowed| origin.starts_with(allowed)) {
415
unsafe { arguments.SetState(COREWEBVIEW2_PERMISSION_STATE_ALLOW) }?;
416
}
417
Ok(())
418
}));
419
let mut token = 0;
420
unsafe { webview.add_PermissionRequested(&handler, &mut token) }
421
}
422
384
423
fn forward_new_windows(webview: &ICoreWebView2, id: u64) -> windows::core::Result<()> {
385
424
let handler = NewWindowRequestedEventHandler::create(Box::new(move |_, arguments| {
386
425
let Some(arguments) = arguments else {
@@ -4,7 +4,7 @@ use tokio::sync::mpsc::UnboundedSender;4
use webview2_com::Microsoft::Web::WebView2::Win32::*;4
use webview2_com::Microsoft::Web::WebView2::Win32::*;5
use webview2_com::{5
use webview2_com::{6
AcceleratorKeyPressedEventHandler, CreateCoreWebView2ControllerCompletedHandler,6
AcceleratorKeyPressedEventHandler, CreateCoreWebView2ControllerCompletedHandler,7
NewWindowRequestedEventHandler, WebMessageReceivedEventHandler,7
NewWindowRequestedEventHandler, PermissionRequestedEventHandler, WebMessageReceivedEventHandler,8
WebResourceRequestedEventHandler, take_pwstr,8
WebResourceRequestedEventHandler, take_pwstr,9
};9
};10
use windows::Win32::Foundation::{COLORREF, HINSTANCE, HWND, LPARAM, LRESULT, RECT, WPARAM};10
use windows::Win32::Foundation::{COLORREF, HINSTANCE, HWND, LPARAM, LRESULT, RECT, WPARAM};@@ -18,11 +18,17 @@ use windows::Win32::UI::Shell::SHCreateMemStream;18
use windows::Win32::UI::WindowsAndMessaging::*;18
use windows::Win32::UI::WindowsAndMessaging::*;19
use windows::core::{HSTRING, Interface, PWSTR, w};19
use windows::core::{HSTRING, Interface, PWSTR, w};20
20
21
use crate::dialog::{DialogCommand, DialogEvent, DialogSpec};21
use crate::dialog::{DialogCommand, DialogEvent, DialogMode, DialogSpec};22
use crate::host::{Shared, fit, shared as running_host};22
use crate::host::{Shared, fit, shared as running_host};23
23
24
const DIALOG_CLASS: windows::core::PCWSTR = w!("RustyTeamsDialog");24
const DIALOG_CLASS: windows::core::PCWSTR = w!("RustyTeamsDialog");25
const DIALOG_STYLE: WINDOW_STYLE = WINDOW_STYLE(WS_CAPTION.0 | WS_SYSMENU.0);25
const DIALOG_STYLE: WINDOW_STYLE = WINDOW_STYLE(WS_CAPTION.0 | WS_SYSMENU.0);26
const CALL_STYLE: WINDOW_STYLE = WS_OVERLAPPEDWINDOW;27
const MEDIA_ORIGINS: [&str; 3] = [28
"https://teams.microsoft.com/",29
"https://teams.cloud.microsoft/",30
"https://teams.live.com/",31
];26
const BASE_DPI: u32 = 96;32
const BASE_DPI: u32 = 96;27
const VIRTUAL_KEY_ESCAPE: u32 = 0x1B;33
const VIRTUAL_KEY_ESCAPE: u32 = 0x1B;28
const PAGE_HEADERS: windows::core::PCWSTR =34
const PAGE_HEADERS: windows::core::PCWSTR =@@ -41,6 +47,7 @@ pub(crate) struct Dialog {41
}47
}42
48
43
struct HostPage {49
struct HostPage {50
mode: DialogMode,44
url: String,51
url: String,45
html: String,52
html: String,46
}53
}@@ -72,6 +79,7 @@ pub(crate) fn open(72
let _ = SetForegroundWindow(window);79
let _ = SetForegroundWindow(window);73
}80
}74
let page = HostPage {81
let page = HostPage {82
mode: spec.mode,75
url: spec.page_url,83
url: spec.page_url,76
html: spec.page_html,84
html: spec.page_html,77
};85
};@@ -234,7 +242,10 @@ fn create_window(spec: &DialogSpec) -> windows::core::Result<HWND> {234
WINDOW_EX_STYLE::default(),242
WINDOW_EX_STYLE::default(),235
DIALOG_CLASS,243
DIALOG_CLASS,236
&HSTRING::from(spec.title.as_str()),244
&HSTRING::from(spec.title.as_str()),237
DIALOG_STYLE,245
match spec.mode {246
DialogMode::Hosted => DIALOG_STYLE,247
DialogMode::Call => CALL_STYLE,248
},238
left,249
left,239
top,250
top,240
width,251
width,@@ -302,10 +313,15 @@ fn attach(302
})?;313
})?;303
webview.Settings()?.SetIsStatusBarEnabled(false)?;314
webview.Settings()?.SetIsStatusBarEnabled(false)?;304
}315
}305
serve_host_page(&webview, environment, &page)?;316
match page.mode {306
forward_messages(&webview, id, &page.url)?;317
DialogMode::Hosted => {318
serve_host_page(&webview, environment, &page)?;319
forward_messages(&webview, id, &page.url)?;320
close_on_escape(&controller, window)?;321
}322
DialogMode::Call => allow_teams_media(&webview)?,323
}307
forward_new_windows(&webview, id)?;324
forward_new_windows(&webview, id)?;308
close_on_escape(&controller, window)?;309
unsafe {325
unsafe {310
controller.SetIsVisible(true)?;326
controller.SetIsVisible(true)?;311
webview.Navigate(&HSTRING::from(page.url.as_str()))?;327
webview.Navigate(&HSTRING::from(page.url.as_str()))?;@@ -381,6 +397,29 @@ fn forward_messages(webview: &ICoreWebView2, id: u64, page_url: &str) -> windows381
unsafe { webview.add_WebMessageReceived(&handler, &mut token) }397
unsafe { webview.add_WebMessageReceived(&handler, &mut token) }382
}398
}383
399
400
fn allow_teams_media(webview: &ICoreWebView2) -> windows::core::Result<()> {401
let handler = PermissionRequestedEventHandler::create(Box::new(move |_, arguments| {402
let Some(arguments) = arguments else {403
return Ok(());404
};405
let mut origin = PWSTR::null();406
let mut kind = COREWEBVIEW2_PERMISSION_KIND::default();407
unsafe {408
arguments.Uri(&mut origin)?;409
arguments.PermissionKind(&mut kind)?;410
}411
let origin = take_pwstr(origin);412
let media = kind == COREWEBVIEW2_PERMISSION_KIND_MICROPHONE413
|| kind == COREWEBVIEW2_PERMISSION_KIND_CAMERA;414
if media && MEDIA_ORIGINS.iter().any(|allowed| origin.starts_with(allowed)) {415
unsafe { arguments.SetState(COREWEBVIEW2_PERMISSION_STATE_ALLOW) }?;416
}417
Ok(())418
}));419
let mut token = 0;420
unsafe { webview.add_PermissionRequested(&handler, &mut token) }421
}422
384
fn forward_new_windows(webview: &ICoreWebView2, id: u64) -> windows::core::Result<()> {423
fn forward_new_windows(webview: &ICoreWebView2, id: u64) -> windows::core::Result<()> {385
let handler = NewWindowRequestedEventHandler::create(Box::new(move |_, arguments| {424
let handler = NewWindowRequestedEventHandler::create(Box::new(move |_, arguments| {386
let Some(arguments) = arguments else {425
let Some(arguments) = arguments else {@@ -19,7 +19,7 @@ mod park;
19
19
mod transport;
20
20
21
21
#[cfg(windows)]
22
pub use dialog::{DialogEvent, DialogHandle, DialogSpec};
22
pub use dialog::{DialogEvent, DialogHandle, DialogMode, DialogSpec};
23
23
#[cfg(windows)]
24
24
pub use embed::{EmbedEvent, EmbedSpec};
25
25
pub use geometry::{EmbedBounds, local_cutouts};
@@ -19,7 +19,7 @@ mod park;19
mod transport;19
mod transport;20
20
21
#[cfg(windows)]21
#[cfg(windows)]22
pub use dialog::{DialogEvent, DialogHandle, DialogSpec};22
pub use dialog::{DialogEvent, DialogHandle, DialogMode, DialogSpec};23
#[cfg(windows)]23
#[cfg(windows)]24
pub use embed::{EmbedEvent, EmbedSpec};24
pub use embed::{EmbedEvent, EmbedSpec};25
pub use geometry::{EmbedBounds, local_cutouts};25
pub use geometry::{EmbedBounds, local_cutouts};