Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
client_state.h File Reference

Declares client state models and transitions. More...

#include <cstddef>
#include <string>
#include <vector>
#include <hal/video.h>
#include "src/app/host_records.h"
#include "src/app/pairing_flow.h"
#include "src/input/navigation_input.h"
#include "src/logging/logger.h"
#include "src/startup/saved_files.h"
#include "src/ui/menu_model.h"
Include dependency graph for client_state.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  app::AddHostDraft
 Controller-friendly draft state for manual host entry. More...
 
struct  app::AddHostKeypadState
 Controller selection state for the add-host keypad modal. More...
 
struct  app::AppNavigationUpdate
 Navigation and modal effects emitted by one command update. More...
 
struct  app::AppPersistenceUpdate
 Persistence and cleanup side effects emitted by one command update. More...
 
struct  app::AppRequestUpdate
 Network and browsing requests emitted by one command update. More...
 
struct  app::AppsState
 State owned by the per-host apps browser. More...
 
struct  app::AppUpdate
 Result of updating the client shell with a UI command. More...
 
struct  app::ClientState
 Serializable app state for the menu-driven client shell. More...
 
struct  app::ConfirmationDialogState
 Content shown by the destructive-action confirmation dialog. More...
 
struct  app::HostsState
 State owned by the saved-host browser and retained host snapshot. More...
 
struct  app::ModalState
 Context modal state shared by the hosts and apps pages. More...
 
struct  app::SettingsState
 State owned by the settings, log viewer, and saved-file workflows. More...
 
struct  app::ShellState
 Shell-wide state that is not owned by a specific workflow screen. More...
 

Enumerations

enum class  app::AddHostField { address , port }
 Active field for keypad-based host entry. More...
 
enum class  app::ConfirmationAction { none , delete_saved_file , factory_reset }
 Destructive confirmation requests surfaced in a modal popup. More...
 
enum class  app::HostsFocusArea { toolbar , grid }
 Focus areas on the hosts page. More...
 
enum class  app::LogViewerPlacement { full , left , right }
 Layout options for the embedded log viewer. More...
 
enum class  app::ModalId {
  none , support , host_actions , host_details ,
  app_actions , app_details , confirmation , log_viewer
}
 Active modal surfaced on top of the current page. More...
 
enum class  app::ScreenId {
  home , hosts , apps , add_host ,
  pair_host , settings
}
 Top-level screens used by the Moonlight client shell. More...
 
enum class  app::SettingsCategory { logging , display , input , reset }
 Top-level categories shown on the left side of the settings screen. More...
 
enum class  app::SettingsFocusArea { categories , options }
 Focus areas used by the two-pane settings screen. More...
 

Functions

void app::apply_app_list_result (ClientState &state, const std::string &address, uint16_t port, std::vector< HostAppRecord > apps, uint64_t appListContentHash, bool success, std::string message)
 Apply a fetched app list to a saved host.
 
void app::apply_connection_test_result (ClientState &state, bool success, std::string message)
 Apply the result of a host connection test to the current shell state.
 
void app::apply_log_viewer_contents (ClientState &state, std::vector< std::string > lines, std::string statusMessage)
 Replace the loaded log viewer contents.
 
bool app::apply_pairing_result (ClientState &state, const std::string &address, uint16_t port, bool success, std::string message)
 Apply the result of a pairing attempt to the current shell state.
 
const HostRecordapp::apps_host (const ClientState &state)
 Return the host currently shown by the Apps screen.
 
bool app::begin_selected_host_app_browse (ClientState &state, bool showHiddenApps)
 Enter the apps screen for the currently selected host after authorization has been refreshed.
 
ClientState app::create_initial_state ()
 Create the initial app state shown after startup.
 
std::string app::current_add_host_address (const ClientState &state)
 Return the current host address shown in the add-host flow.
 
uint16_t app::current_add_host_port (const ClientState &state)
 Return the effective TCP port for the current add-host draft.
 
std::string app::current_pairing_pin (const ClientState &state)
 Return the current pairing PIN shown in the pairing flow.
 
AppUpdate app::handle_command (ClientState &state, input::UiCommand command)
 Apply a UI command to the client shell.
 
bool app::host_requires_manual_pairing (const ClientState &state, const std::string &address, uint16_t port)
 Return whether a saved host still requires a manual pairing flow.
 
void app::mark_cover_art_cached (ClientState &state, const std::string &address, uint16_t port, int appId)
 Mark one cached cover-art entry as available for a host app.
 
bool app::merge_discovered_host (ClientState &state, std::string displayName, const std::string &address, uint16_t port)
 Add or refresh one auto-discovered host in the current host list.
 
void app::replace_hosts (ClientState &state, std::vector< HostRecord > hosts, std::string statusMessage={})
 Replace the in-memory host list from a persisted snapshot.
 
void app::replace_saved_files (ClientState &state, std::vector< startup::SavedFileEntry > savedFiles)
 Replace the in-memory saved-file inventory shown on the settings page.
 
const HostAppRecordapp::selected_app (const ClientState &state)
 Return the currently selected app on the Apps screen.
 
const HostRecordapp::selected_host (const ClientState &state)
 Return the currently selected loaded host for the active screen.
 
void app::set_log_file_path (ClientState &state, std::string logFilePath)
 Update the log file path tracked by the shell.
 
const char * app::to_string (ScreenId screen)
 Return a display label for a screen identifier.
 

Detailed Description

Declares client state models and transitions.

Enumeration Type Documentation

◆ AddHostField

enum class app::AddHostField
strong

Active field for keypad-based host entry.

Enumerator
address 

The host IPv4 address field.

port 

The optional host port override field.

◆ ConfirmationAction

enum class app::ConfirmationAction
strong

Destructive confirmation requests surfaced in a modal popup.

Enumerator
none 

No destructive action is pending confirmation.

delete_saved_file 

Delete one saved file or directory.

factory_reset 

Remove all persisted Moonlight state.

◆ HostsFocusArea

enum class app::HostsFocusArea
strong

Focus areas on the hosts page.

Enumerator
toolbar 

Focus is on the hosts toolbar buttons.

grid 

Focus is on the saved-host tile grid.

◆ LogViewerPlacement

enum class app::LogViewerPlacement
strong

Layout options for the embedded log viewer.

Enumerator
full 

Use the full modal width for the log viewer.

left 

Dock the log viewer on the left side of the split layout.

right 

Dock the log viewer on the right side of the split layout.

◆ ModalId

enum class app::ModalId
strong

Active modal surfaced on top of the current page.

Enumerator
none 

No modal is currently visible.

support 

Support and help modal.

host_actions 

Host action menu for the selected host.

host_details 

Host detail sheet for the selected host.

app_actions 

App action menu for the selected app.

app_details 

App detail sheet for the selected app.

confirmation 

Destructive-action confirmation dialog.

log_viewer 

Dedicated log viewer modal.

◆ ScreenId

enum class app::ScreenId
strong

Top-level screens used by the Moonlight client shell.

Enumerator
home 

Placeholder home screen identifier retained for shared shell logic.

hosts 

Saved-host browser and primary landing screen.

apps 

Per-host application library screen.

add_host 

Manual host entry workflow.

pair_host 

Pairing workflow for an unpaired host.

settings 

Shell settings screen.

◆ SettingsCategory

enum class app::SettingsCategory
strong

Top-level categories shown on the left side of the settings screen.

Enumerator
logging 

Logging and diagnostics options.

display 

Display and video presentation options.

input 

Input and controller options.

reset 

Reset and cleanup actions.

◆ SettingsFocusArea

enum class app::SettingsFocusArea
strong

Focus areas used by the two-pane settings screen.

Enumerator
categories 

Focus is on the settings category list.

options 

Focus is on the options list for the selected category.

Function Documentation

◆ apply_app_list_result()

void app::apply_app_list_result ( ClientState & state,
const std::string & address,
uint16_t port,
std::vector< HostAppRecord > apps,
uint64_t appListContentHash,
bool success,
std::string message )

Apply a fetched app list to a saved host.

Parameters
stateMutable app state.
addressHost address used for the fetch.
portHost port used for the fetch.
appsFresh app records returned by the host.
appListContentHashStable content hash for the returned app list.
successWhether the fetch succeeded.
messageUser-visible status message.

◆ apply_connection_test_result()

void app::apply_connection_test_result ( ClientState & state,
bool success,
std::string message )

Apply the result of a host connection test to the current shell state.

Parameters
stateMutable app state.
successWhether the test succeeded.
messageUser-visible status message.

◆ apply_log_viewer_contents()

void app::apply_log_viewer_contents ( ClientState & state,
std::vector< std::string > lines,
std::string statusMessage )

Replace the loaded log viewer contents.

Parameters
stateMutable app state.
linesLog file lines ready for display.
statusMessageUser-visible status line for the log viewer state.

◆ apply_pairing_result()

bool app::apply_pairing_result ( ClientState & state,
const std::string & address,
uint16_t port,
bool success,
std::string message )

Apply the result of a pairing attempt to the current shell state.

Parameters
stateMutable app state.
addressHost address used for pairing.
portHost port used for pairing.
successWhether the pairing attempt succeeded.
messageUser-visible status message.
Returns
True when the host list changed and should be persisted.

◆ apps_host()

const HostRecord * app::apps_host ( const ClientState & state)

Return the host currently shown by the Apps screen.

Parameters
stateApp state containing the selected host.
Returns
Host record backing the apps page, or nullptr when unavailable.

◆ begin_selected_host_app_browse()

bool app::begin_selected_host_app_browse ( ClientState & state,
bool showHiddenApps )

Enter the apps screen for the currently selected host after authorization has been refreshed.

Parameters
stateMutable app state.
showHiddenAppsWhether hidden apps should still be shown.
Returns
true when the apps page was entered.

◆ create_initial_state()

ClientState app::create_initial_state ( )

Create the initial app state shown after startup.

Returns
The initial client state.

◆ current_add_host_address()

std::string app::current_add_host_address ( const ClientState & state)

Return the current host address shown in the add-host flow.

Parameters
stateApp state containing the add-host draft.
Returns
Current draft IPv4 address text.

◆ current_add_host_port()

uint16_t app::current_add_host_port ( const ClientState & state)

Return the effective TCP port for the current add-host draft.

Parameters
stateApp state containing the add-host draft.
Returns
Effective host port using the default when the field is empty.

◆ current_pairing_pin()

std::string app::current_pairing_pin ( const ClientState & state)

Return the current pairing PIN shown in the pairing flow.

Parameters
stateApp state containing the pairing draft.
Returns
Four-digit PIN string.

◆ handle_command()

AppUpdate app::handle_command ( ClientState & state,
input::UiCommand command )

Apply a UI command to the client shell.

Parameters
stateMutable app state.
commandUI command from controller or keyboard input.
Returns
Summary of the resulting state transition.

◆ host_requires_manual_pairing()

bool app::host_requires_manual_pairing ( const ClientState & state,
const std::string & address,
uint16_t port )

Return whether a saved host still requires a manual pairing flow.

Parameters
stateApp state containing the saved host list.
addressHost address to inspect.
portHost port to inspect.
Returns
true when the matching host exists and is not paired.

◆ mark_cover_art_cached()

void app::mark_cover_art_cached ( ClientState & state,
const std::string & address,
uint16_t port,
int appId )

Mark one cached cover-art entry as available for a host app.

Parameters
stateMutable app state.
addressHost address owning the app.
portHost port owning the app.
appIdApp identifier whose cached art is now available.

◆ merge_discovered_host()

bool app::merge_discovered_host ( ClientState & state,
std::string displayName,
const std::string & address,
uint16_t port )

Add or refresh one auto-discovered host in the current host list.

Discovery results are normalized to the same saved-host conventions used by manual host entry. When a matching host already exists, transient runtime fields such as reachability are refreshed without overwriting a custom saved name. When no host matches, a new host record is appended and marked dirty so it can be persisted.

Parameters
stateMutable app state.
displayNameDiscovered host name, or an empty string to use the default label.
addressDiscovered IPv4 address.
portDiscovered host HTTP port.
Returns
true when persisted host metadata changed or a new host was added.

◆ replace_hosts()

void app::replace_hosts ( ClientState & state,
std::vector< HostRecord > hosts,
std::string statusMessage = {} )

Replace the in-memory host list from a persisted snapshot.

Parameters
stateMutable app state.
hostsLoaded host records.
statusMessageOptional status line shown in the shell.

◆ replace_saved_files()

void app::replace_saved_files ( ClientState & state,
std::vector< startup::SavedFileEntry > savedFiles )

Replace the in-memory saved-file inventory shown on the settings page.

Parameters
stateMutable app state.
savedFilesSaved files currently found on disk.

◆ selected_app()

const HostAppRecord * app::selected_app ( const ClientState & state)

Return the currently selected app on the Apps screen.

Parameters
stateApp state containing the selected host and apps list.
Returns
Selected app record, or nullptr when no visible app is selected.

◆ selected_host()

const HostRecord * app::selected_host ( const ClientState & state)

Return the currently selected loaded host for the active screen.

On the hosts page this returns the selected saved host tile. On host-specific pages such as pairing it may return the lightweight active host snapshot.

Parameters
stateApp state containing the loaded host selection.
Returns
Selected host record, or nullptr when no saved host is selected.

◆ set_log_file_path()

void app::set_log_file_path ( ClientState & state,
std::string logFilePath )

Update the log file path tracked by the shell.

Parameters
stateMutable app state.
logFilePathPath to the log file that should be shown in the viewer.

◆ to_string()

const char * app::to_string ( ScreenId screen)

Return a display label for a screen identifier.

Parameters
screenScreen identifier to stringify.
Returns
Stable lowercase screen name.