Skip to content

Commit

Permalink
fix(plugins): handle race when setting plugin selectable (zellij-org#…
Browse files Browse the repository at this point in the history
  • Loading branch information
imsnif authored and Tomcat-42 committed Nov 9, 2024
1 parent e6b7ee5 commit 87e60d1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,7 @@ pub(crate) fn screen_thread_main(
let mut pending_tab_ids: HashSet<usize> = HashSet::new();
let mut pending_tab_switches: HashSet<(usize, ClientId)> = HashSet::new(); // usize is the
// tab_index
let mut pending_events_waiting_for_tab: Vec<ScreenInstruction> = vec![];
let mut pending_events_waiting_for_client: Vec<ScreenInstruction> = vec![];
let mut plugin_loading_message_cache = HashMap::new();
loop {
Expand Down Expand Up @@ -3299,12 +3300,18 @@ pub(crate) fn screen_thread_main(
},
ScreenInstruction::SetSelectable(pid, selectable) => {
let all_tabs = screen.get_tabs_mut();
let mut found_plugin = false;
for tab in all_tabs.values_mut() {
if tab.has_pane_with_pid(&pid) {
tab.set_pane_selectable(pid, selectable);
found_plugin = true;
break;
}
}
if !found_plugin {
pending_events_waiting_for_tab
.push(ScreenInstruction::SetSelectable(pid, selectable));
}
screen.render(None)?;
screen.log_and_report_session_state()?;
},
Expand Down Expand Up @@ -3505,6 +3512,10 @@ pub(crate) fn screen_thread_main(
screen.bus.senders.send_to_screen(event).non_fatal();
}

for event in pending_events_waiting_for_tab.drain(..) {
screen.bus.senders.send_to_screen(event).non_fatal();
}

screen.unblock_input()?;
screen.render(None)?;
// we do this here in order to recover from a race condition on app start
Expand Down

0 comments on commit 87e60d1

Please sign in to comment.