Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
client_state.h
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <cstddef>
9#include <string>
10#include <vector>
11
12// nxdk includes
13#include <hal/video.h>
14
15// standard includes
19#include "src/logging/logger.h"
21#include "src/ui/menu_model.h"
22
23namespace app {
24
28 enum class ScreenId {
29 home,
30 hosts,
31 apps,
32 add_host,
33 pair_host,
34 settings,
35 };
36
40 enum class HostsFocusArea {
41 toolbar,
42 grid,
43 };
44
48 enum class ModalId {
49 none,
50 support,
57 };
58
62 enum class LogViewerPlacement {
63 full,
64 left,
65 right,
66 };
67
71 enum class SettingsFocusArea {
73 options,
74 };
75
79 enum class SettingsCategory {
80 logging,
81 display,
82 input,
83 reset,
84 };
85
89 enum class ConfirmationAction {
90 none,
91 delete_saved_file,
93 };
94
98 enum class AddHostField {
99 address,
100 port,
101 };
102
107 bool visible;
109 std::string stagedInput;
110 };
111
125
129 struct ModalState {
130 ModalId id = ModalId::none;
131 std::size_t selectedActionIndex = 0;
132
138 bool active() const {
139 return id != ModalId::none;
140 }
141 };
142
147 ConfirmationAction action = ConfirmationAction::none;
148 std::string targetPath;
149 std::string title;
150 std::vector<std::string> lines;
151 };
152
156 struct ShellState {
157 ScreenId activeScreen = ScreenId::hosts;
158 bool overlayVisible = false;
159 bool shouldExit = false;
160 std::size_t overlayScrollOffset = 0U;
161 std::string statusMessage;
162 };
163
167 struct HostsState {
168 bool dirty = false;
169 bool loaded = false;
170 HostsFocusArea focusArea = HostsFocusArea::toolbar;
171 std::size_t selectedToolbarButtonIndex = 0U;
172 std::size_t selectedHostIndex = 0U;
173 std::vector<HostRecord> items;
175 bool activeLoaded = false;
176 std::string selectedAddress;
177 uint16_t selectedPort = 0;
178 std::vector<std::string> pairingResetEndpoints;
179
185 bool empty() const {
186 return items.empty();
187 }
188
194 std::size_t size() const {
195 return items.size();
196 }
197
203 auto begin() {
204 return items.begin();
205 }
206
212 auto end() {
213 return items.end();
214 }
215
221 auto begin() const {
222 return items.begin();
223 }
224
230 auto end() const {
231 return items.end();
232 }
233
237 void clear() {
238 items.clear();
239 }
240
247 return items.front();
248 }
249
255 const HostRecord &front() const {
256 return items.front();
257 }
258
265 return items.back();
266 }
267
273 const HostRecord &back() const {
274 return items.back();
275 }
276
283 HostRecord &operator[](std::size_t index) {
284 return items[index];
285 }
286
293 const HostRecord &operator[](std::size_t index) const {
294 return items[index];
295 }
296 };
297
301 struct AppsState {
302 std::size_t selectedAppIndex = 0U;
303 std::size_t scrollPage = 0U;
304 bool showHiddenApps = false;
305 };
306
311 SettingsFocusArea focusArea = SettingsFocusArea::categories;
312 SettingsCategory selectedCategory = SettingsCategory::logging;
313 std::string logFilePath;
314 std::vector<std::string> logViewerLines;
315 std::size_t logViewerScrollOffset = 0U;
316 LogViewerPlacement logViewerPlacement = LogViewerPlacement::full;
317 logging::LogLevel loggingLevel = logging::LogLevel::none;
318 logging::LogLevel xemuConsoleLoggingLevel = logging::LogLevel::none;
319 std::vector<VIDEO_MODE> availableVideoModes;
320 VIDEO_MODE preferredVideoMode {};
323 int streamBitrateKbps = 1000;
324 bool playAudioOnPc = false;
325 bool showPerformanceStats = false;
326 bool playAudioOnXbox = true;
327 bool dirty = false;
328 std::vector<startup::SavedFileEntry> savedFiles;
329 bool savedFilesDirty = true;
330 };
331
347
352 bool screenChanged = false;
353 bool overlayChanged = false;
355 bool exitRequested = false;
356 bool modalOpened = false;
357 bool modalClosed = false;
358 std::string activatedItemId;
359 };
360
367 uint16_t connectionTestPort = 0;
368 bool pairingRequested = false;
370 std::string pairingAddress;
371 uint16_t pairingPort = 0;
372 std::string pairingPin;
373 bool appsBrowseRequested = false;
374 bool appsBrowseShowHidden = false;
376 bool logViewRequested = false;
377 };
378
383 bool hostsChanged = false;
384 bool settingsChanged = false;
389 bool deletedHostWasPaired = false;
390 std::string deletedHostAddress;
391 uint16_t deletedHostPort = 0;
392 std::vector<std::string> deletedHostCoverArtCacheKeys;
393 };
394
403
410
417 const char *to_string(ScreenId screen);
418
426 void replace_hosts(ClientState &state, std::vector<HostRecord> hosts, std::string statusMessage = {});
427
443 bool merge_discovered_host(ClientState &state, std::string displayName, const std::string &address, uint16_t port);
444
451 void replace_saved_files(ClientState &state, std::vector<startup::SavedFileEntry> savedFiles);
452
459 std::string current_add_host_address(const ClientState &state);
460
467 uint16_t current_add_host_port(const ClientState &state);
468
475 std::string current_pairing_pin(const ClientState &state);
476
484 void apply_connection_test_result(ClientState &state, bool success, std::string message);
485
496 bool apply_pairing_result(ClientState &state, const std::string &address, uint16_t port, bool success, std::string message);
497
509 void apply_app_list_result(
510 ClientState &state,
511 const std::string &address,
512 uint16_t port,
513 std::vector<HostAppRecord> apps,
514 uint64_t appListContentHash,
515 bool success,
516 std::string message
517 );
518
527 void mark_cover_art_cached(ClientState &state, const std::string &address, uint16_t port, int appId);
528
535 void set_log_file_path(ClientState &state, std::string logFilePath);
536
544 void apply_log_viewer_contents(ClientState &state, std::vector<std::string> lines, std::string statusMessage);
545
554 bool host_requires_manual_pairing(const ClientState &state, const std::string &address, uint16_t port);
555
563 bool begin_selected_host_app_browse(ClientState &state, bool showHiddenApps);
564
574 const HostRecord *selected_host(const ClientState &state);
575
582 const HostAppRecord *selected_app(const ClientState &state);
583
590 const HostRecord *apps_host(const ClientState &state);
591
599 AppUpdate handle_command(ClientState &state, input::UiCommand command);
600
601} // namespace app
Menu state that supports controller and keyboard navigation.
Definition menu_model.h:45
void replace_hosts(ClientState &state, std::vector< HostRecord > hosts, std::string statusMessage)
Replace the in-memory host list from a persisted snapshot.
Definition client_state.cpp:1434
const char * to_string(ScreenId screen)
Return a display label for a screen identifier.
Definition client_state.cpp:1416
ClientState create_initial_state()
Create the initial app state shown after startup.
Definition client_state.cpp:1377
ModalId
Active modal surfaced on top of the current page.
Definition client_state.h:48
@ log_viewer
Dedicated log viewer modal.
@ none
No modal is currently visible.
@ confirmation
Destructive-action confirmation dialog.
@ support
Support and help modal.
@ app_actions
App action menu for the selected app.
@ host_details
Host detail sheet for the selected host.
@ app_details
App detail sheet for the selected app.
@ host_actions
Host action menu for the selected host.
LogViewerPlacement
Layout options for the embedded log viewer.
Definition client_state.h:62
@ right
Dock the log viewer on the right side of the split layout.
@ left
Dock the log viewer on the left side of the split layout.
@ full
Use the full modal width for the log viewer.
SettingsFocusArea
Focus areas used by the two-pane settings screen.
Definition client_state.h:71
@ options
Focus is on the options list for the selected category.
@ categories
Focus is on the settings category list.
AddHostField
Active field for keypad-based host entry.
Definition client_state.h:98
@ address
The host IPv4 address field.
@ port
The optional host port override field.
ConfirmationAction
Destructive confirmation requests surfaced in a modal popup.
Definition client_state.h:89
@ factory_reset
Remove all persisted Moonlight state.
HostsFocusArea
Focus areas on the hosts page.
Definition client_state.h:40
@ toolbar
Focus is on the hosts toolbar buttons.
@ grid
Focus is on the saved-host tile grid.
SettingsCategory
Top-level categories shown on the left side of the settings screen.
Definition client_state.h:79
@ reset
Reset and cleanup actions.
@ input
Input and controller options.
@ logging
Logging and diagnostics options.
@ display
Display and video presentation options.
ScreenId
Top-level screens used by the Moonlight client shell.
Definition client_state.h:28
@ home
Placeholder home screen identifier retained for shared shell logic.
@ settings
Shell settings screen.
@ hosts
Saved-host browser and primary landing screen.
@ apps
Per-host application library screen.
@ add_host
Manual host entry workflow.
Declares host record models and utilities.
Declares logging configuration and output.
LogLevel
Severity levels used by the Moonlight client logger.
Definition logger.h:22
Declares menu model structures and helpers.
Declares controller navigation input handling.
UiCommand
Abstract UI command emitted by controller or keyboard input.
Definition navigation_input.h:12
Declares the host pairing flow.
Declares saved file loading and cleanup helpers.
Controller-friendly draft state for manual host entry.
Definition client_state.h:115
bool lastConnectionSucceeded
True when the latest connection test succeeded.
Definition client_state.h:123
AddHostField activeField
Field currently targeted by directional input.
Definition client_state.h:118
std::string addressInput
Raw host address text entered by the user.
Definition client_state.h:116
std::string connectionMessage
Result message from the latest host connection test.
Definition client_state.h:122
std::string portInput
Raw port override text entered by the user.
Definition client_state.h:117
std::string validationMessage
Validation feedback for the current address or port text.
Definition client_state.h:121
AddHostKeypadState keypad
Nested keypad-modal selection state.
Definition client_state.h:119
ScreenId returnScreen
Screen to return to when add-host flow completes or cancels.
Definition client_state.h:120
Controller selection state for the add-host keypad modal.
Definition client_state.h:106
std::size_t selectedButtonIndex
Zero-based selection inside the keypad button grid.
Definition client_state.h:108
bool visible
True when the keypad modal is currently shown.
Definition client_state.h:107
std::string stagedInput
Draft text currently assembled inside the keypad modal.
Definition client_state.h:109
Navigation and modal effects emitted by one command update.
Definition client_state.h:351
bool modalOpened
True when a modal became active during the update.
Definition client_state.h:356
bool screenChanged
True when the active screen changed.
Definition client_state.h:352
bool modalClosed
True when the active modal was dismissed during the update.
Definition client_state.h:357
std::string activatedItemId
Stable identifier for the activated menu item, when any.
Definition client_state.h:358
bool overlayVisibilityChanged
True when overlay visibility toggled.
Definition client_state.h:354
bool overlayChanged
True when overlay content changed.
Definition client_state.h:353
bool exitRequested
True when the shell requested application exit.
Definition client_state.h:355
Persistence and cleanup side effects emitted by one command update.
Definition client_state.h:382
bool hostsChanged
True when the host list changed and should be persisted.
Definition client_state.h:383
uint16_t deletedHostPort
Port of the host removed from storage.
Definition client_state.h:391
bool hostDeleteCleanupRequested
True when host deletion follow-up cleanup should run.
Definition client_state.h:388
std::string deletedHostAddress
Address of the host removed from storage.
Definition client_state.h:390
bool deletedHostWasPaired
True when the deleted host previously had pairing credentials.
Definition client_state.h:389
bool settingsChanged
True when persisted TOML-backed settings changed.
Definition client_state.h:384
bool factoryResetRequested
True when a full saved-data reset should run.
Definition client_state.h:387
bool savedFileDeleteRequested
True when one managed file should be deleted.
Definition client_state.h:385
std::string savedFileDeletePath
Managed file path requested for deletion.
Definition client_state.h:386
std::vector< std::string > deletedHostCoverArtCacheKeys
Cover-art cache keys to remove for the deleted host.
Definition client_state.h:392
Network and browsing requests emitted by one command update.
Definition client_state.h:364
bool streamLaunchRequested
True when the selected host app should start or resume streaming.
Definition client_state.h:375
uint16_t pairingPort
Host port targeted by pairing.
Definition client_state.h:371
std::string connectionTestAddress
Host address that should be tested.
Definition client_state.h:366
bool logViewRequested
True when the log viewer should be refreshed from disk.
Definition client_state.h:376
uint16_t connectionTestPort
Host port that should be tested.
Definition client_state.h:367
std::string pairingPin
Generated client PIN that should be shown to the user.
Definition client_state.h:372
bool appsBrowseRequested
True when app browsing for the selected host should begin.
Definition client_state.h:373
std::string pairingAddress
Host address targeted by pairing.
Definition client_state.h:370
bool pairingCancelledRequested
True when an in-progress pairing request should be cancelled.
Definition client_state.h:369
bool connectionTestRequested
True when a manual host connection test should run.
Definition client_state.h:365
bool appsBrowseShowHidden
Hidden-app visibility requested for the app browse action.
Definition client_state.h:374
bool pairingRequested
True when manual pairing should begin.
Definition client_state.h:368
Result of updating the client shell with a UI command.
Definition client_state.h:398
AppRequestUpdate requests
Network and browsing requests emitted by the command.
Definition client_state.h:400
AppNavigationUpdate navigation
Navigation and modal changes emitted by the command.
Definition client_state.h:399
AppPersistenceUpdate persistence
Persistence and cleanup work emitted by the command.
Definition client_state.h:401
State owned by the per-host apps browser.
Definition client_state.h:301
std::size_t selectedAppIndex
Zero-based selection inside the visible app list.
Definition client_state.h:302
std::size_t scrollPage
Horizontal page offset for paged app browsing.
Definition client_state.h:303
bool showHiddenApps
True when hidden apps should remain visible in the apps screen.
Definition client_state.h:304
Serializable app state for the menu-driven client shell.
Definition client_state.h:335
ui::MenuModel detailMenu
Secondary detail or actions menu.
Definition client_state.h:340
HostsState hosts
Saved-host browsing state and retained host snapshot.
Definition client_state.h:337
AddHostDraft addHostDraft
Draft state for the add-host workflow.
Definition client_state.h:341
ConfirmationDialogState confirmation
Confirmation dialog content for destructive actions.
Definition client_state.h:345
ModalState modal
Context modal currently stacked over the shell.
Definition client_state.h:343
ShellState shell
Shell-wide status and overlay state.
Definition client_state.h:336
ui::MenuModel menu
Primary vertical menu model for the active screen.
Definition client_state.h:339
AppsState apps
Apps-screen selection and paging state.
Definition client_state.h:338
PairingDraft pairingDraft
Draft state for the active pairing workflow.
Definition client_state.h:342
SettingsState settings
Settings, log viewer, and saved-file workflow state.
Definition client_state.h:344
Content shown by the destructive-action confirmation dialog.
Definition client_state.h:146
ConfirmationAction action
Requested confirmation action.
Definition client_state.h:147
std::string targetPath
File or directory path targeted by the action, when applicable.
Definition client_state.h:148
std::vector< std::string > lines
Body lines describing the consequence of the action.
Definition client_state.h:150
std::string title
Modal title presented to the user.
Definition client_state.h:149
Manual host record shown in the shell.
Definition host_records.h:61
State owned by the saved-host browser and retained host snapshot.
Definition client_state.h:167
auto end() const
Return a const iterator one past the last saved host.
Definition client_state.h:230
bool activeLoaded
True when active contains a valid host snapshot.
Definition client_state.h:175
std::size_t selectedHostIndex
Zero-based selection inside the saved host list.
Definition client_state.h:172
std::string selectedAddress
Last selected host address used to restore hosts-page selection after reload.
Definition client_state.h:176
const HostRecord & back() const
Return the last saved host.
Definition client_state.h:273
uint16_t selectedPort
Last selected host port override used to restore hosts-page selection after reload.
Definition client_state.h:177
HostRecord & front()
Return the first saved host.
Definition client_state.h:246
HostRecord & operator[](std::size_t index)
Return the saved host at the requested index.
Definition client_state.h:283
std::vector< HostRecord > items
Saved hosts currently tracked by the shell.
Definition client_state.h:173
HostRecord & back()
Return the last saved host.
Definition client_state.h:264
HostsFocusArea focusArea
Focused region on the hosts page.
Definition client_state.h:170
bool loaded
True when the hosts page list is currently loaded in memory.
Definition client_state.h:169
std::vector< std::string > pairingResetEndpoints
Endpoints whose pairing material should be cleared during reset.
Definition client_state.h:178
HostRecord active
Host snapshot kept for host-specific non-host screens after unloading the hosts page.
Definition client_state.h:174
auto begin()
Return an iterator to the first saved host.
Definition client_state.h:203
const HostRecord & operator[](std::size_t index) const
Return the saved host at the requested index.
Definition client_state.h:293
auto end()
Return an iterator one past the last saved host.
Definition client_state.h:212
std::size_t size() const
Return the number of saved hosts currently tracked by the shell.
Definition client_state.h:194
std::size_t selectedToolbarButtonIndex
Zero-based selection inside the hosts toolbar.
Definition client_state.h:171
bool empty() const
Return whether the saved-host collection is empty.
Definition client_state.h:185
void clear()
Remove every saved host from the collection.
Definition client_state.h:237
bool dirty
True when the host list changed and should be saved.
Definition client_state.h:168
const HostRecord & front() const
Return the first saved host.
Definition client_state.h:255
auto begin() const
Return a const iterator to the first saved host.
Definition client_state.h:221
Context modal state shared by the hosts and apps pages.
Definition client_state.h:129
std::size_t selectedActionIndex
Zero-based index of the highlighted modal action.
Definition client_state.h:131
bool active() const
Return whether a modal is currently active.
Definition client_state.h:138
Controller-friendly state for a client-generated pairing PIN.
Definition pairing_flow.h:28
State owned by the settings, log viewer, and saved-file workflows.
Definition client_state.h:310
VIDEO_MODE preferredVideoMode
Preferred stream resolution requested from the host.
Definition client_state.h:320
LogViewerPlacement logViewerPlacement
Log viewer pane placement relative to the shell.
Definition client_state.h:316
bool showPerformanceStats
True when stream telemetry should be shown after streaming ends.
Definition client_state.h:325
std::vector< startup::SavedFileEntry > savedFiles
Saved-file catalog shown on the reset settings page.
Definition client_state.h:328
logging::LogLevel xemuConsoleLoggingLevel
Minimum runtime log level mirrored through DbgPrint() to xemu's serial console.
Definition client_state.h:318
logging::LogLevel loggingLevel
Minimum runtime log level written to the persisted log file.
Definition client_state.h:317
std::size_t logViewerScrollOffset
Zero-based vertical scroll offset inside the log viewer.
Definition client_state.h:315
bool dirty
True when persisted TOML-backed settings changed and should be saved.
Definition client_state.h:327
std::vector< VIDEO_MODE > availableVideoModes
Detected Xbox video modes exposed as stream-resolution choices.
Definition client_state.h:319
bool savedFilesDirty
True when the saved-file catalog should be refreshed.
Definition client_state.h:329
int streamFramerate
Preferred stream frame rate in frames per second.
Definition client_state.h:322
std::vector< std::string > logViewerLines
Loaded log file lines shown in the log viewer.
Definition client_state.h:314
std::string logFilePath
Path currently loaded into the log viewer.
Definition client_state.h:313
SettingsFocusArea focusArea
Focused pane within the settings screen.
Definition client_state.h:311
bool playAudioOnPc
True when the host PC should continue local audio playback during streaming.
Definition client_state.h:324
int streamBitrateKbps
Preferred stream bitrate in kilobits per second.
Definition client_state.h:323
bool playAudioOnXbox
True when the Xbox should decode and play streamed audio locally.
Definition client_state.h:326
bool preferredVideoModeSet
True when preferredVideoMode contains a user-selected or default mode.
Definition client_state.h:321
SettingsCategory selectedCategory
Settings category selected in the left pane.
Definition client_state.h:312
Shell-wide state that is not owned by a specific workflow screen.
Definition client_state.h:156
std::size_t overlayScrollOffset
Scroll offset used by long overlay content.
Definition client_state.h:160
std::string statusMessage
Primary user-visible status line.
Definition client_state.h:161
ScreenId activeScreen
Screen currently shown by the shell.
Definition client_state.h:157
bool shouldExit
True when the application should terminate.
Definition client_state.h:159
bool overlayVisible
True when the diagnostics overlay is visible.
Definition client_state.h:158