@@ -7,6 +7,7 @@ var api; // The `api` should only be set if we're in a host-specific screen, on
77var isPlatformVer = parseFloat ( tizen . systeminfo . getCapability ( "http://tizen.org/feature/platform.version" ) ) ; // Retrieve the Tizen platform version
88var isInGame = false ; // Flag indicating whether the game has started, initial value is false
99var isDialogOpen = false ; // Flag indicating whether the dialog is open, initial value is false
10+ var isGamepadActive = false ; // Flag indicating whether the gamepad input is active, initial value is false
1011var isClickPrevented = false ; // Flag indicating whether the click event should be prevented, initial value is false
1112var resFpsWarning = false ; // Flag indicating whether the video resolution and frame rate warning message has shown, initial value is false
1213var bitrateWarning = false ; // Flag indicating whether the video bitrate warning message has shown, initial value is false
@@ -80,33 +81,41 @@ function attachListeners() {
8081
8182 Controller . startWatching ( ) ;
8283 window . addEventListener ( 'gamepadinputchanged' , ( e ) => {
84+ isGamepadActive = true ;
8385 const changes = e . detail . changes ;
8486 // Iterate through each change in the gamepad input
8587 changes . forEach ( ( change ) => {
8688 const { type, index, pressed, value } = change ;
8789 if ( type === 'button' ) {
8890 // Handle button mapping
8991 const buttonMapping = {
90- 0 : ( ) => Navigation . accept ( ) ,
91- 1 : ( ) => Navigation . back ( ) ,
92- 8 : ( ) => Navigation . press ( ) ,
93- 9 : ( ) => Navigation . switch ( ) ,
92+ 0 : ( ) => delayedNavigation ( ( ) => Navigation . accept ( ) ) ,
93+ 1 : ( ) => delayedNavigation ( ( ) => Navigation . back ( ) ) ,
94+ 8 : ( ) => delayedNavigation ( ( ) => Navigation . move ( ) ) ,
95+ } ;
96+ // Handle D-Pad mapping
97+ const dPadMapping = {
9498 12 : ( ) => Navigation . up ( ) ,
9599 13 : ( ) => Navigation . down ( ) ,
96100 14 : ( ) => Navigation . left ( ) ,
97101 15 : ( ) => Navigation . right ( ) ,
98102 } ;
99- // Handle button press
103+ // Handle button presses
100104 if ( pressed ) {
101105 if ( buttonMapping [ index ] ) {
102106 buttonMapping [ index ] ( ) ;
103- // Set repeat action and timeout to the mapped button
104- repeatAction = buttonMapping [ index ] ;
107+ // Clear repeat action and timeout for non-navigation buttons
108+ repeatAction = null ;
109+ clearTimeout ( repeatTimeout ) ;
110+ } else if ( dPadMapping [ index ] ) {
111+ dPadMapping [ index ] ( ) ;
112+ // Set repeat action and timeout to the mapped D-Pad button
113+ repeatAction = dPadMapping [ index ] ;
105114 lastInvokeTime = Date . now ( ) ;
106115 repeatTimeout = setTimeout ( ( ) => requestAnimationFrame ( repeatActionHandler ) , REPEAT_DELAY ) ;
107116 }
108117 } else {
109- // Clear repeat action and timeout if button is released
118+ // Clear repeat action and timeout when button is released
110119 repeatAction = null ;
111120 clearTimeout ( repeatTimeout ) ;
112121 }
@@ -118,16 +127,16 @@ function attachListeners() {
118127 1 : ( value ) => value < - ACTION_THRESHOLD ? ( delayedNavigation ( ( ) => Navigation . up ( ) ) , ( ) => Navigation . up ( ) ) :
119128 value > ACTION_THRESHOLD ? ( delayedNavigation ( ( ) => Navigation . down ( ) ) , ( ) => Navigation . down ( ) ) : null ,
120129 } ;
121- // Handle axis value
130+ // Handle axis movement
122131 if ( axisMapping [ index ] ) {
123132 const axisValue = axisMapping [ index ] ( value ) ;
124133 if ( axisValue && Math . abs ( value ) > ACTION_THRESHOLD ) {
125- // Set repeat action and timeout to the mapped axis
134+ // Set repeat action and timeout to the mapped axis direction
126135 repeatAction = axisValue ;
127136 lastInvokeTime = Date . now ( ) ;
128137 repeatTimeout = setTimeout ( ( ) => requestAnimationFrame ( repeatActionHandler ) , REPEAT_DELAY ) ;
129138 } else {
130- // Clear repeat action and timeout if axis is released
139+ // Clear repeat action and timeout when axis is neutral
131140 repeatAction = null ;
132141 clearTimeout ( repeatTimeout ) ;
133142 }
@@ -138,6 +147,9 @@ function attachListeners() {
138147}
139148
140149function changeUiModeForWasmLoad ( ) {
150+ // Stop navigation before showing the loading screen
151+ Navigation . stop ( ) ;
152+
141153 $ ( '#main-header' ) . hide ( ) ;
142154 $ ( '#main-header' ) . children ( ) . hide ( ) ;
143155 $ ( '#main-content' ) . children ( ) . not ( '#listener, #wasmSpinner' ) . hide ( ) ;
@@ -292,6 +304,9 @@ function showHostsMode() {
292304
293305// Show the Hosts grid
294306function showHosts ( ) {
307+ // Stop navigation before showing the loading screen
308+ Navigation . stop ( ) ;
309+
295310 // Hide the main header and content before showing a loading screen
296311 $ ( '#main-header' ) . children ( ) . hide ( ) ;
297312 $ ( '#main-header' ) . css ( { 'backgroundColor' : 'transparent' , 'boxShadow' : 'none' } ) ;
@@ -315,7 +330,7 @@ function showHosts() {
315330 } , 500 ) ;
316331
317332 // Set focus to current item and/or scroll to the current host row
318- setTimeout ( ( ) => Navigation . switch ( ) , 500 ) ;
333+ setTimeout ( ( ) => Navigation . restore ( ) , 500 ) ;
319334}
320335
321336function restoreUiAfterWasmLoad ( ) {
@@ -328,7 +343,7 @@ function restoreUiAfterWasmLoad() {
328343 Navigation . push ( Views . Hosts ) ;
329344 showHostsMode ( ) ;
330345 // Set focus to current item and/or scroll to the current host row
331- setTimeout ( ( ) => Navigation . switch ( ) , 100 ) ;
346+ setTimeout ( ( ) => Navigation . restore ( ) , 100 ) ;
332347
333348 // Find mDNS host discovered using ServiceFinder (network service discovery)
334349 // findNvService(function(finder, opt_error) {
@@ -386,7 +401,7 @@ function hostChosen(host) {
386401 Navigation . push ( Views . Apps ) ;
387402 setTimeout ( ( ) => {
388403 // Scroll to the current game row
389- Navigation . switch ( ) ;
404+ Navigation . restore ( ) ;
390405 // Switch to Apps view
391406 Navigation . change ( Views . Apps ) ;
392407 } , 1500 ) ;
@@ -400,7 +415,7 @@ function hostChosen(host) {
400415 Navigation . push ( Views . Apps ) ;
401416 setTimeout ( ( ) => {
402417 // Scroll to the current game row
403- Navigation . switch ( ) ;
418+ Navigation . restore ( ) ;
404419 // Switch to Apps view
405420 Navigation . change ( Views . Apps ) ;
406421 } , 1500 ) ;
@@ -474,15 +489,8 @@ function addHostDialog() {
474489 addHostDialog . showModal ( ) ;
475490 isDialogOpen = true ;
476491 Navigation . push ( Views . AddHostDialog ) ;
477-
478- // Checks if the IP address field mode switch is checked
479- if ( $ ( '#ipAddressFieldModeSwitch' ) . prop ( 'checked' ) ) {
480- // Remove focus from any currently focused element
481- document . activeElement . blur ( ) ;
482- } else {
483- // Set focus to the currently active element
484- document . activeElement . focus ( ) ;
485- }
492+ // Remove focus from any current active element
493+ document . activeElement . blur ( ) ;
486494
487495 // Cancel the operation if the Cancel button is pressed
488496 $ ( '#cancelAddHost' ) . off ( 'click' ) ;
@@ -507,11 +515,11 @@ function addHostDialog() {
507515 setTimeout ( ( ) => {
508516 // Add disabled state after 2 seconds
509517 $ ( '#continueAddHost' ) . addClass ( 'mdl-button--disabled' ) . prop ( 'disabled' , true ) ;
510- Navigation . switch ( ) ;
518+ Navigation . restore ( ) ;
511519 // Re-enable the Continue button after 12 seconds
512520 setTimeout ( ( ) => {
513521 $ ( '#continueAddHost' ) . removeClass ( 'mdl-button--disabled' ) . prop ( 'disabled' , false ) ;
514- Navigation . switch ( ) ;
522+ Navigation . restore ( ) ;
515523 } , 12000 ) ;
516524 } , 2000 ) ;
517525 // Get the IP address value from the input field
@@ -890,7 +898,7 @@ function hostMenuDialog(host) {
890898 hostMenuDialog [ 0 ] . showModal ( ) ;
891899 isDialogOpen = true ;
892900 Navigation . push ( Views . HostMenuDialog , host . hostname ) ;
893- setTimeout ( ( ) => Navigation . switch ( ) , 5 ) ;
901+ setTimeout ( ( ) => Navigation . restore ( ) , 100 ) ;
894902}
895903
896904// Show a confirmation with the Delete Host dialog before removing the host object
@@ -971,7 +979,7 @@ function deleteAllHostsDialog() {
971979 deleteHostDialog . close ( ) ;
972980 isDialogOpen = false ;
973981 Navigation . pop ( ) ;
974- Navigation . switch ( ) ;
982+ Navigation . restore ( ) ;
975983 } ) ;
976984
977985 // Remove all existing hosts if the Continue button is pressed
@@ -996,7 +1004,7 @@ function deleteAllHostsDialog() {
9961004 deleteHostDialog . close ( ) ;
9971005 isDialogOpen = false ;
9981006 Navigation . pop ( ) ;
999- Navigation . switch ( ) ;
1007+ Navigation . restore ( ) ;
10001008 } ) ;
10011009 }
10021010}
@@ -1076,7 +1084,7 @@ function hostDetailsDialog(host) {
10761084 hostDetailsDialog [ 0 ] . showModal ( ) ;
10771085 isDialogOpen = true ;
10781086 Navigation . push ( Views . HostDetailsDialog ) ;
1079- setTimeout ( ( ) => Navigation . switch ( ) , 5 ) ;
1087+ setTimeout ( ( ) => Navigation . restore ( ) , 100 ) ;
10801088}
10811089
10821090// Show the Moonlight Support dialog
@@ -1099,7 +1107,7 @@ function appSupportDialog() {
10991107 appSupportDialog . close ( ) ;
11001108 isDialogOpen = false ;
11011109 Navigation . pop ( ) ;
1102- Navigation . switch ( ) ;
1110+ Navigation . restore ( ) ;
11031111 } ) ;
11041112}
11051113
@@ -1130,6 +1138,9 @@ function showSettingsMode() {
11301138
11311139// Show the Settings list
11321140function showSettings ( ) {
1141+ // Stop navigation before showing the loading screen
1142+ Navigation . stop ( ) ;
1143+
11331144 // Hide the main header and content before showing a loading screen
11341145 $ ( '#main-header' ) . children ( ) . hide ( ) ;
11351146 $ ( '#main-header' ) . css ( { 'backgroundColor' : 'transparent' , 'boxShadow' : 'none' } ) ;
@@ -1159,19 +1170,14 @@ function showSettings() {
11591170 } , 500 ) ;
11601171}
11611172
1162- // Reset the current settings view by clearing the selection and hiding the right pane
1173+ // Reset the settings view by clearing the selection and hiding the right pane
11631174function resetSettingsView ( ) {
1164- // Remove the 'hovered' and 'is-focused' classes from all toggle switches
1165- document . querySelectorAll ( '.mdl-switch' ) . forEach ( function ( toggleSwitch ) {
1166- toggleSwitch . classList . remove ( 'hovered' , 'is-focused' ) ;
1167- } ) ;
1168-
1169- // Hide all settings options from the right pane
1175+ // Hide any settings options from the right pane
11701176 document . querySelectorAll ( '.settings-options' ) . forEach ( function ( settingsOption ) {
11711177 settingsOption . style . display = 'none' ;
11721178 } ) ;
11731179
1174- // Remove the 'selected' class from all settings categories
1180+ // Remove the 'selected' class from any settings categories
11751181 document . querySelectorAll ( '.settings-category' ) . forEach ( function ( settingsCategory ) {
11761182 settingsCategory . classList . remove ( 'selected' ) ;
11771183 } ) ;
@@ -1181,7 +1187,7 @@ function resetSettingsView() {
11811187function navigateSettingsView ( view ) {
11821188 Navigation . pop ( ) ;
11831189 Navigation . push ( view ) ;
1184- setTimeout ( ( ) => Navigation . switch ( ) , 5 ) ;
1190+ setTimeout ( ( ) => Navigation . restore ( ) , 250 ) ;
11851191}
11861192
11871193// Handle category selection, display appropriate options, and navigate to the provided settings pane
@@ -1259,7 +1265,7 @@ function navigationGuideDialog() {
12591265 navGuideDialog . close ( ) ;
12601266 isDialogOpen = false ;
12611267 Navigation . pop ( ) ;
1262- Navigation . switch ( ) ;
1268+ Navigation . restore ( ) ;
12631269 } ) ;
12641270}
12651271
@@ -1446,7 +1452,7 @@ function updateAppDialog(latestVersion, releaseNotes) {
14461452 updateAppDialogOverlay . remove ( ) ;
14471453 isDialogOpen = false ;
14481454 Navigation . pop ( ) ;
1449- Navigation . switch ( ) ;
1455+ Navigation . restore ( ) ;
14501456 } ) . appendTo ( updateAppDialogActions ) ;
14511457
14521458 // If the dialog element doesn't support the showModal method, register it with dialogPolyfill
@@ -1459,7 +1465,7 @@ function updateAppDialog(latestVersion, releaseNotes) {
14591465 updateAppDialog [ 0 ] . showModal ( ) ;
14601466 isDialogOpen = true ;
14611467 Navigation . push ( Views . UpdateMoonlightDialog ) ;
1462- setTimeout ( ( ) => Navigation . switch ( ) , 5 ) ;
1468+ setTimeout ( ( ) => Navigation . restore ( ) , 100 ) ;
14631469}
14641470
14651471// Check for updates when the Check for Updates button is pressed
@@ -1556,7 +1562,7 @@ function restoreDefaultsDialog() {
15561562 restoreDefaultsDialog . close ( ) ;
15571563 isDialogOpen = false ;
15581564 Navigation . pop ( ) ;
1559- Navigation . switch ( ) ;
1565+ Navigation . restore ( ) ;
15601566 } ) ;
15611567
15621568 // Restore all default settings if the Continue button is pressed
@@ -1571,7 +1577,7 @@ function restoreDefaultsDialog() {
15711577 restoreDefaultsDialog . close ( ) ;
15721578 isDialogOpen = false ;
15731579 Navigation . pop ( ) ;
1574- Navigation . switch ( ) ;
1580+ Navigation . restore ( ) ;
15751581 // Show the required Restart Moonlight dialog and push the view
15761582 setTimeout ( ( ) => requiredRestartAppDialog ( ) , 2000 ) ;
15771583 } ) ;
@@ -1601,7 +1607,7 @@ function warningDialog(title, message) {
16011607 warningDialog . close ( ) ;
16021608 isDialogOpen = false ;
16031609 Navigation . pop ( ) ;
1604- Navigation . switch ( ) ;
1610+ Navigation . restore ( ) ;
16051611 } ) ;
16061612}
16071613
@@ -1634,7 +1640,7 @@ function restartAppDialog() {
16341640 restartAppDialog . close ( ) ;
16351641 isDialogOpen = false ;
16361642 Navigation . pop ( ) ;
1637- Navigation . switch ( ) ;
1643+ Navigation . restore ( ) ;
16381644 } ) ;
16391645
16401646 // Restart the application if the Restart button is pressed
@@ -1673,7 +1679,7 @@ function requiredRestartAppDialog() {
16731679 restartAppDialog . close ( ) ;
16741680 isDialogOpen = false ;
16751681 Navigation . pop ( ) ;
1676- Navigation . switch ( ) ;
1682+ Navigation . restore ( ) ;
16771683 } ) ;
16781684
16791685 // Restart the application if the Restart button is pressed
@@ -1826,6 +1832,9 @@ function showApps(host) {
18261832 console . log ( '%c[index.js, showApps]' , 'color: green;' , 'Current host object: \n' , host , '\n' + host . toString ( ) ) ; // Logging both object (for console) and toString-ed object (for text logs)
18271833 }
18281834
1835+ // Stop navigation before showing the loading screen
1836+ Navigation . stop ( ) ;
1837+
18291838 // Hide the main header before showing a loading screen
18301839 $ ( '#main-header' ) . children ( ) . hide ( ) ;
18311840 $ ( '#main-header' ) . css ( { 'backgroundColor' : 'transparent' , 'boxShadow' : 'none' } ) ;
@@ -1998,7 +2007,7 @@ function quitAppDialog() {
19982007 quitAppDialog . close ( ) ;
19992008 isDialogOpen = false ;
20002009 Navigation . pop ( ) ;
2001- Navigation . switch ( ) ;
2010+ Navigation . restore ( ) ;
20022011 } ) ;
20032012
20042013 // Quit the running app if the Continue button is pressed
@@ -2011,7 +2020,7 @@ function quitAppDialog() {
20112020 Navigation . pop ( ) ;
20122021 stopGame ( api , function ( ) {
20132022 // After stopping the game, set focus back to the 'Quit Running App' button
2014- setTimeout ( ( ) => Navigation . switch ( ) , 3000 ) ;
2023+ setTimeout ( ( ) => Navigation . restore ( ) , 3000 ) ;
20152024 } ) ;
20162025 } ) ;
20172026 } ) ;
@@ -2106,7 +2115,7 @@ function startGame(host, appID) {
21062115 stopGame ( host , function ( ) {
21072116 setTimeout ( ( ) => {
21082117 // Scroll to the current game row
2109- Navigation . switch ( ) ;
2118+ Navigation . restore ( ) ;
21102119 // Switch to Apps view
21112120 Navigation . change ( Views . Apps ) ;
21122121 } , 1500 ) ;
@@ -2201,7 +2210,7 @@ function startGame(host, appID) {
22012210 showApps ( host ) ;
22022211 setTimeout ( ( ) => {
22032212 // Scroll to the current game row
2204- Navigation . switch ( ) ;
2213+ Navigation . restore ( ) ;
22052214 // Switch to Apps view
22062215 Navigation . change ( Views . Apps ) ;
22072216 } , 1500 ) ;
@@ -2221,7 +2230,7 @@ function startGame(host, appID) {
22212230 showApps ( host ) ;
22222231 setTimeout ( ( ) => {
22232232 // Scroll to the current game row
2224- Navigation . switch ( ) ;
2233+ Navigation . restore ( ) ;
22252234 // Switch to Apps view
22262235 Navigation . change ( Views . Apps ) ;
22272236 } , 1500 ) ;
@@ -2255,7 +2264,7 @@ function startGame(host, appID) {
22552264 showApps ( host ) ;
22562265 setTimeout ( ( ) => {
22572266 // Scroll to the current game row
2258- Navigation . switch ( ) ;
2267+ Navigation . restore ( ) ;
22592268 // Switch to Apps view
22602269 Navigation . change ( Views . Apps ) ;
22612270 } , 1500 ) ;
@@ -2275,7 +2284,7 @@ function startGame(host, appID) {
22752284 showApps ( host ) ;
22762285 setTimeout ( ( ) => {
22772286 // Scroll to the current game row
2278- Navigation . switch ( ) ;
2287+ Navigation . restore ( ) ;
22792288 // Switch to Apps view
22802289 Navigation . change ( Views . Apps ) ;
22812290 } , 1500 ) ;
0 commit comments