1use call::ActiveCall;
2use gpui::{
3 color::Color,
4 elements::{MouseEventHandler, Svg},
5 platform::{Appearance, MouseButton},
6 AnyElement, AppContext, Element, Entity, View, ViewContext,
7};
8use settings::Settings;
9
10use crate::ToggleScreenSharing;
11
12pub fn init(cx: &mut AppContext) {
13 let active_call = ActiveCall::global(cx);
14
15 let mut status_indicator = None;
16 cx.observe(&active_call, move |call, cx| {
17 if let Some(room) = call.read(cx).room() {
18 if room.read(cx).is_screen_sharing() {
19 if status_indicator.is_none() && cx.global::<Settings>().show_call_status_icon {
20 status_indicator = Some(cx.add_status_bar_item(|_| SharingStatusIndicator));
21 }
22 } else if let Some((window_id, _)) = status_indicator.take() {
23 cx.remove_status_bar_item(window_id);
24 }
25 } else if let Some((window_id, _)) = status_indicator.take() {
26 cx.remove_status_bar_item(window_id);
27 }
28 })
29 .detach();
30}
31
32pub struct SharingStatusIndicator;
33
34impl Entity for SharingStatusIndicator {
35 type Event = ();
36}
37
38impl View for SharingStatusIndicator {
39 fn ui_name() -> &'static str {
40 "SharingStatusIndicator"
41 }
42
43 fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
44 let color = match cx.window_appearance() {
45 Appearance::Light | Appearance::VibrantLight => Color::black(),
46 Appearance::Dark | Appearance::VibrantDark => Color::white(),
47 };
48
49 MouseEventHandler::<Self, Self>::new(0, cx, |_, _| {
50 Svg::new("icons/disable_screen_sharing_12.svg")
51 .with_color(color)
52 .constrained()
53 .with_width(18.)
54 .aligned()
55 })
56 .on_click(MouseButton::Left, |_, _, cx| {
57 cx.dispatch_action(ToggleScreenSharing);
58 })
59 .into_any()
60 }
61}