2023-02-03 19:17:50 +00:00
|
|
|
use call::ActiveCall;
|
2023-01-31 23:00:49 +00:00
|
|
|
use gpui::{
|
|
|
|
color::Color,
|
|
|
|
elements::{MouseEventHandler, Svg},
|
2023-02-03 19:17:50 +00:00
|
|
|
Appearance, Element, ElementBox, Entity, MouseButton, MutableAppContext, RenderContext, View,
|
2023-01-31 23:00:49 +00:00
|
|
|
};
|
2023-02-03 19:17:50 +00:00
|
|
|
use settings::Settings;
|
2023-01-31 23:00:49 +00:00
|
|
|
|
2023-02-03 20:47:20 +00:00
|
|
|
use crate::ToggleScreenSharing;
|
2023-02-03 19:17:50 +00:00
|
|
|
|
|
|
|
pub fn init(cx: &mut MutableAppContext) {
|
|
|
|
let active_call = ActiveCall::global(cx);
|
|
|
|
|
|
|
|
let mut status_indicator = None;
|
|
|
|
cx.observe(&active_call, move |call, cx| {
|
|
|
|
if let Some(room) = call.read(cx).room() {
|
|
|
|
if room.read(cx).is_screen_sharing() {
|
|
|
|
if status_indicator.is_none() && cx.global::<Settings>().show_call_status_icon {
|
|
|
|
status_indicator = Some(cx.add_status_bar_item(|_| SharingStatusIndicator));
|
|
|
|
}
|
|
|
|
} else if let Some((window_id, _)) = status_indicator.take() {
|
|
|
|
cx.remove_status_bar_item(window_id);
|
|
|
|
}
|
2023-03-22 08:32:27 +00:00
|
|
|
} else if let Some((window_id, _)) = status_indicator.take() {
|
|
|
|
cx.remove_status_bar_item(window_id);
|
2023-02-03 19:17:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.detach();
|
|
|
|
}
|
2023-01-31 23:00:49 +00:00
|
|
|
|
|
|
|
pub struct SharingStatusIndicator;
|
|
|
|
|
|
|
|
impl Entity for SharingStatusIndicator {
|
|
|
|
type Event = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
impl View for SharingStatusIndicator {
|
|
|
|
fn ui_name() -> &'static str {
|
|
|
|
"SharingStatusIndicator"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
|
|
|
let color = match cx.appearance {
|
|
|
|
Appearance::Light | Appearance::VibrantLight => Color::black(),
|
|
|
|
Appearance::Dark | Appearance::VibrantDark => Color::white(),
|
|
|
|
};
|
|
|
|
|
|
|
|
MouseEventHandler::<Self>::new(0, cx, |_, _| {
|
|
|
|
Svg::new("icons/disable_screen_sharing_12.svg")
|
|
|
|
.with_color(color)
|
|
|
|
.constrained()
|
|
|
|
.with_width(18.)
|
|
|
|
.aligned()
|
|
|
|
.boxed()
|
|
|
|
})
|
|
|
|
.on_click(MouseButton::Left, |_, cx| {
|
|
|
|
cx.dispatch_action(ToggleScreenSharing);
|
|
|
|
})
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|