mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 02:37:21 +00:00
Fix flicker due to adding and removing menu bar extra unnecessarily
This commit is contained in:
parent
560d8a8004
commit
96c5bb8c39
1 changed files with 16 additions and 6 deletions
|
@ -16,13 +16,17 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
|
||||||
let mut status_bar_item_id = None;
|
let mut status_bar_item_id = None;
|
||||||
cx.observe(&ActiveCall::global(cx), move |call, cx| {
|
cx.observe(&ActiveCall::global(cx), move |call, cx| {
|
||||||
if let Some(status_bar_item_id) = status_bar_item_id.take() {
|
let had_room = status_bar_item_id.is_some();
|
||||||
cx.remove_status_bar_item(status_bar_item_id);
|
let has_room = call.read(cx).room().is_some();
|
||||||
}
|
if had_room != has_room {
|
||||||
|
if let Some(status_bar_item_id) = status_bar_item_id.take() {
|
||||||
|
cx.remove_status_bar_item(status_bar_item_id);
|
||||||
|
}
|
||||||
|
|
||||||
if call.read(cx).room().is_some() {
|
if has_room {
|
||||||
let (id, _) = cx.add_status_bar_item(|_| MenuBarExtra::new());
|
let (id, _) = cx.add_status_bar_item(|_| MenuBarExtra::new());
|
||||||
status_bar_item_id = Some(id);
|
status_bar_item_id = Some(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
@ -34,6 +38,12 @@ struct MenuBarExtra {
|
||||||
|
|
||||||
impl Entity for MenuBarExtra {
|
impl Entity for MenuBarExtra {
|
||||||
type Event = ();
|
type Event = ();
|
||||||
|
|
||||||
|
fn release(&mut self, cx: &mut MutableAppContext) {
|
||||||
|
if let Some(popover) = self.popover.take() {
|
||||||
|
cx.remove_window(popover.window_id());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View for MenuBarExtra {
|
impl View for MenuBarExtra {
|
||||||
|
|
Loading…
Reference in a new issue