Skip to main content

agentmux_srv/server/app_api/
open_updates.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Telling every window what an open made: the new objects as they are in the store now, in one batched frame
5//! (`EventBus::broadcast_mux_obj_updates`), so the renderer applies them in a single reactive flush and never
6//! paints a block without its tab or a tab without its layout.
7
8use super::*;
9
10/// The update row of one stored object, as it is now.
11fn row<T: obj::StoreObj>(oid: &str, value: &T) -> obj::MuxObjUpdate {
12    obj::MuxObjUpdate { updatetype: "update".into(), otype: T::get_otype().to_string(), oid: oid.to_string(), obj: Some(obj::mux_obj_to_value(value)) }
13}
14
15/// A block that was opened in a tab: the block, the tab, then the tab's layout. What the store does not have is left out.
16pub(super) fn broadcast_block_in_tab(state: &AppState, block_id: &str, tab_id: &str) {
17    let mstore = &state.mstore;
18    let mut updates = Vec::new();
19    if let Ok(block) = mstore.must_get::<Block>(block_id) {
20        updates.push(row(block_id, &block));
21    }
22    if let Ok(tab) = mstore.must_get::<Tab>(tab_id) {
23        updates.push(row(tab_id, &tab));
24        if let Ok(layout) = mstore.must_get::<obj::LayoutState>(&tab.layoutstate) {
25            updates.push(row(&tab.layoutstate, &layout));
26        }
27    }
28    state.event_bus.broadcast_mux_obj_updates(&updates);
29}
30
31/// A block that was opened floating, in a workspace and tab of its own: the workspace, the tab's layout, the tab,
32/// then the block (the order the tear-off by drag sends).
33pub(super) fn broadcast_new_floater(mstore: &Store, event_bus: &crate::backend::eventbus::EventBus, new_ws_id: &str, new_tab_id: &str, block_id: &str) {
34    let mut updates = Vec::new();
35    if let Ok(workspace) = mstore.must_get::<Workspace>(new_ws_id) {
36        updates.push(row(new_ws_id, &workspace));
37    }
38    if let Ok(tab) = mstore.must_get::<Tab>(new_tab_id) {
39        if let Ok(layout) = mstore.must_get::<obj::LayoutState>(&tab.layoutstate) {
40            updates.push(row(&tab.layoutstate, &layout));
41        }
42        updates.push(row(new_tab_id, &tab));
43    }
44    if let Ok(block) = mstore.must_get::<Block>(block_id) {
45        updates.push(row(block_id, &block));
46    }
47    event_bus.broadcast_mux_obj_updates(&updates);
48}