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