Skip to main content

agentmux_srv/server/service/
window.rs

1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `window` service handler (GetWindow, CreateWindow, CloseWindow, …).
5//!
6//! The dispatcher below just routes each method to its handler; the
7//! handler bodies live in sibling modules:
8//! * [`super::window_query`] — `GetWindow` / `FindWindowByLabel`.
9//! * [`super::window_create`] — `CreateWindow`.
10//! * [`super::window_close`] — `CloseWindow`.
11//! * [`super::window_mutate`] — `SwitchWorkspace` / `SetWindowPosAndSize` /
12//!   `SetWindowOpacity` / `SetWindowTopology`.
13
14use crate::backend::service::{WebCallType, WebReturnType};
15
16use super::super::AppState;
17use super::window_close::handle_close_window;
18use super::window_create::handle_create_window;
19use super::window_mutate::{
20    handle_set_window_opacity, handle_set_window_pos_and_size, handle_set_window_topology,
21    handle_switch_workspace,
22};
23use super::window_query::{handle_find_window_by_label, handle_get_window};
24
25pub(super) async fn handle_window_service(state: &AppState, call: &WebCallType) -> WebReturnType {
26    match call.method.as_str() {
27        "GetWindow" => handle_get_window(state, call).await,
28        "FindWindowByLabel" => handle_find_window_by_label(state, call).await,
29        "CreateWindow" => handle_create_window(state, call).await,
30        "CloseWindow" => handle_close_window(state, call).await,
31        // OS-shutdown flush (SPEC_CONTINUOUS_SESSION_PERSISTENCE_2026_09_08
32        // Phase 0). Snapshot-only: never tears the workspace down, because
33        // the OS is about to reclaim everything and delete_workspace's
34        // per-shell grace does not fit the shutdown budget.
35        "SaveSessionSnapshot" => {
36            super::session_restore::handle_save_session_snapshot(state, call).await
37        }
38        "SwitchWorkspace" => handle_switch_workspace(state, call).await,
39        "SetWindowPosAndSize" => handle_set_window_pos_and_size(state, call).await,
40        "SetWindowOpacity" => handle_set_window_opacity(state, call).await,
41        "SetWindowTopology" => handle_set_window_topology(state, call).await,
42        "MarkWindowOpen" => super::window_inherit::handle_mark_window_open(state, call).await,
43        "InheritWindowAppearance" => {
44            super::window_inherit::handle_inherit_window_appearance(state, call).await
45        }
46        _ => WebReturnType::error(format!("unknown window method: {}", call.method)),
47    }
48}