From d9e9ab2fb6ec15457ef3a5ce3c0b09d66bc2183c Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Wed, 15 Apr 2026 10:59:57 -0700 Subject: [PATCH] feat: update state path to muxplex, add MUXPLEX_STATE_DIR env var, add active_view field - Change _default_state_dir from 'tmux-web' to 'muxplex' - Update STATE_DIR to prefer MUXPLEX_STATE_DIR env var with TMUX_WEB_STATE_DIR fallback - Add 'active_view': 'all' to empty_state() between active_remote_id and session_order - Update module docstring schema to document active_view field - Add tests: test_empty_state_has_active_view_key, test_empty_state_active_view_defaults_to_all, test_state_dir_uses_muxplex_name --- muxplex/state.py | 11 +++++++++-- muxplex/tests/test_state.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/muxplex/state.py b/muxplex/state.py index a08bff1..4a6f149 100644 --- a/muxplex/state.py +++ b/muxplex/state.py @@ -5,6 +5,8 @@ State schema (all values are plain JSON-serialisable dicts): { "active_session": str | None, + "active_remote_id": str | None, + "active_view": str, # 'all' | 'hidden' | view name "session_order": list[str], "sessions": { "": { @@ -37,8 +39,12 @@ from pathlib import Path # Paths # --------------------------------------------------------------------------- -_default_state_dir = Path.home() / ".local" / "share" / "tmux-web" -STATE_DIR: Path = Path(os.environ.get("TMUX_WEB_STATE_DIR", _default_state_dir)) +_default_state_dir = Path.home() / ".local" / "share" / "muxplex" +STATE_DIR: Path = Path( + os.environ.get( + "MUXPLEX_STATE_DIR", os.environ.get("TMUX_WEB_STATE_DIR", _default_state_dir) + ) +) STATE_PATH: Path = STATE_DIR / "state.json" # --------------------------------------------------------------------------- @@ -60,6 +66,7 @@ def empty_state() -> dict: return { "active_session": None, "active_remote_id": None, + "active_view": "all", "session_order": [], "sessions": {}, "devices": {}, diff --git a/muxplex/tests/test_state.py b/muxplex/tests/test_state.py index dba6b3d..a6f24cf 100644 --- a/muxplex/tests/test_state.py +++ b/muxplex/tests/test_state.py @@ -92,6 +92,24 @@ def test_empty_state_returns_independent_dicts(): assert s2["devices"] == {} +def test_empty_state_has_active_view_key(): + state = empty_state() + assert "active_view" in state + + +def test_empty_state_active_view_defaults_to_all(): + state = empty_state() + assert state["active_view"] == "all" + + +def test_state_dir_uses_muxplex_name(): + import muxplex.state as state_mod + + path_str = str(state_mod._default_state_dir) + assert "muxplex" in path_str + assert "tmux-web" not in path_str + + # --------------------------------------------------------------------------- # empty_bell() # ---------------------------------------------------------------------------