Skip to content

fix(ui): sync tray menu with connection state and add Stop Listening - #192

Open
ID-VerNe wants to merge 2 commits into
teamclouday:mainfrom
ID-VerNe:fix/tray-menu-state
Open

ID-VerNe wants to merge 2 commits into
teamclouday:mainfrom
ID-VerNe:fix/tray-menu-state

Conversation

@ID-VerNe

Copy link
Copy Markdown

Problem

The tray menu is driven by a single disconnected boolean passed to update_menu_state() from several call sites, so it can drift away from the real connection state:

  • StreamerMsg::Error resets connection_state to Default but never updates the tray; the menu keeps Connect disabled and Disconnect enabled while the app is idle.
  • Listening and Connected are both encoded as disconnected = false. While the app is only waiting for a phone, the menu therefore offers Disconnect; clicking it does send StreamerCommand::Stop, but the label does not describe the state.
  • The current state is only visible in the tray tooltip. The menu has no status entry, so waiting, listening and connected cannot be told apart at a glance.

Changes

  • Add a pure mapping from ConnectionState to a menu model:
ConnectionState Connect stop item stop label
Default enabled disabled Disconnect
WaitingOnStatus disabled disabled Disconnect
Listening disabled enabled Stop Listening
Connected disabled enabled Disconnect
  • Add a disabled status row at the top of the menu, in both the tray-icon (Windows/macOS) and ksni (Linux) backends.
  • Route every transition through sync_tray(): connect, disconnect, StreamerMsg::Listening, StreamerMsg::Connected, and now StreamerMsg::Error, which previously left the menu stale.
  • Change SystemTray::update_menu_state() to take status, connect_enabled, stop_enabled and stop_label instead of disconnected.
  • Add the tray_stop_listening string to en / fr / zh-CN.
  • Add a unit test covering the state to menu mapping.

Screenshots (Windows 11, zh-CN)

Default state — Connect enabled, Disconnect disabled:

default

Listening — Connect disabled, the last item reads Stop Listening (停止监听) and is enabled:

listening

Connected — Connect disabled, the last item reads Disconnect (断开连接) and is enabled:

connected

Scope / risk

  • No new dependency. Both tray backends are updated behind the same API.
  • The only user-visible behavior change is the tray menu: during Listening the last item now reads Stop Listening instead of Disconnect, and it still performs the same action (StreamerCommand::Stop).
  • Nothing in the streamer or the window lifecycle is touched; those changes are tracked separately.

Verification

  • cargo fmt --all -- --check
  • Windows 11 (tray-icon backend): Default / Listening / Connected match the screenshots above; Stop Listening returns the app to Default.
  • Linux (ksni backend): shares the same state model, not exercised manually in this environment.
  • Note: cargo build / cargo test were not run locally (protoc is not installed on this machine); CI builds Linux / Windows / macOS.

The tray menu was updated by scattered update_menu_state() calls, so the
StreamerMsg::Error path (device dropped) and the connect -> WaitingOnStatus
path never refreshed it: the menu kept Disconnect enabled and Connect
disabled while the main window was already back to Connect.

Add a sync_tray() helper that derives the connect/disconnect items and
tooltip from connection_state, the same source the main window uses, and
call it on every state transition. Default/WaitingOnStatus enable Connect
and disable Disconnect; Listening/Connected do the reverse.

Refs #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant