2024-07-28 18:17:52 -04:00
import Logger from '../logger' ;
2024-05-12 15:45:26 -04:00
import { Export , findModuleExport } from '../webpack' ;
2022-06-04 10:33:59 +02:00
export enum SideMenu {
None ,
Main ,
QuickAccess ,
}
2022-06-04 10:54:01 +02:00
export enum QuickAccessTab {
2022-06-04 10:33:59 +02:00
Notifications ,
RemotePlayTogetherControls ,
VoiceChat ,
Friends ,
Settings ,
Perf ,
Help ,
2023-04-28 22:25:56 -04:00
Music ,
Decky = 999 ,
2022-06-04 10:33:59 +02:00
}
2022-07-09 09:34:09 -05:00
export enum DisplayStatus {
Invalid = 0 ,
Launching = 1 ,
Uninstalling = 2 ,
Installing = 3 ,
Running = 4 ,
Validating = 5 ,
Updating = 6 ,
Downloading = 7 ,
Synchronizing = 8 ,
ReadyToInstall = 9 ,
ReadyToPreload = 10 ,
ReadyToLaunch = 11 ,
RegionRestricted = 12 ,
PresaleOnly = 13 ,
InvalidPlatform = 14 ,
PreloadComplete = 16 ,
BorrowerLocked = 17 ,
UpdatePaused = 18 ,
UpdateQueued = 19 ,
UpdateRequired = 20 ,
UpdateDisabled = 21 ,
DownloadPaused = 22 ,
DownloadQueued = 23 ,
DownloadRequired = 24 ,
DownloadDisabled = 25 ,
LicensePending = 26 ,
LicenseExpired = 27 ,
AvailForFree = 28 ,
AvailToBorrow = 29 ,
AvailGuestPass = 30 ,
Purchase = 31 ,
Unavailable = 32 ,
NotLaunchable = 33 ,
CloudError = 34 ,
CloudOutOfDate = 35 ,
Terminating = 36 ,
}
export type AppOverview = {
2022-10-24 20:33:40 -04:00
appid : string ;
display_name : string ;
display_status : DisplayStatus ;
sort_as : string ;
} ;
2022-07-09 09:34:09 -05:00
2022-12-12 16:48:52 -07:00
export interface MenuStore {
OpenSideMenu ( sideMenu : SideMenu ) : void ;
OpenQuickAccessMenu ( quickAccessTab? : QuickAccessTab ) : void ;
OpenMainMenu ( ) : void ;
}
export interface WindowRouter {
BrowserWindow : Window ;
MenuStore : MenuStore ;
Navigate ( path : string ) : void ;
NavigateToChat ( ) : void ;
NavigateToSteamWeb ( url : string ) : void ;
NavigateBack ( ) : void ;
}
export interface WindowStore {
GamepadUIMainWindowInstance? : WindowRouter ; // Current
SteamUIWindows : WindowRouter [ ] ;
OverlayWindows : WindowRouter [ ] ; // Used by desktop GamepadUI
}
2022-06-05 15:07:47 +02:00
export interface Router {
2022-12-12 16:48:52 -07:00
WindowStore? : WindowStore ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-06-04 10:33:59 +02:00
CloseSideMenus ( ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-06-04 13:42:23 -04:00
Navigate ( path : string ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-10-24 20:33:40 -04:00
NavigateToAppProperties ( ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-06-04 10:33:59 +02:00
NavigateToExternalWeb ( url : string ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-10-24 20:33:40 -04:00
NavigateToInvites ( ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-12-12 16:48:52 -07:00
NavigateToChat ( ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-12-12 16:48:52 -07:00
NavigateToLibraryTab ( ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-12-12 16:48:52 -07:00
NavigateToLayoutPreview ( e : unknown ) : void ;
2024-07-28 18:17:52 -04:00
/** @deprecated use {@link Navigation} instead */
2022-06-04 10:33:59 +02:00
OpenPowerMenu ( unknown ? : any ) : void ;
2022-08-17 21:55:50 +02:00
get RunningApps ( ) : AppOverview [ ] ;
2022-07-09 09:34:09 -05:00
get MainRunningApp ( ) : AppOverview | undefined ;
2022-06-04 10:33:59 +02:00
}
2024-05-12 15:45:26 -04:00
export const Router = findModuleExport ( ( e : Export ) = > e . Navigate && e . NavigationManager ) as Router ;
2022-12-12 16:48:52 -07:00
export interface Navigation {
Navigate ( path : string ) : void ;
NavigateBack ( ) : void ;
NavigateToAppProperties ( ) : void ;
NavigateToExternalWeb ( url : string ) : void ;
NavigateToInvites ( ) : void ;
NavigateToChat ( ) : void ;
NavigateToLibraryTab ( ) : void ;
NavigateToLayoutPreview ( e : unknown ) : void ;
NavigateToSteamWeb ( url : string ) : void ;
OpenSideMenu ( sideMenu : SideMenu ) : void ;
OpenQuickAccessMenu ( quickAccessTab? : QuickAccessTab ) : void ;
OpenMainMenu ( ) : void ;
OpenPowerMenu ( unknown ? : any ) : void ;
2024-07-28 18:51:08 -04:00
/** if calling this to perform navigation, call it after Navigate to prevent a race condition in desktop Big Picture mode that hides the overlay unintentionally */
2022-12-12 16:48:52 -07:00
CloseSideMenus ( ) : void ;
}
2023-01-12 21:55:08 -05:00
export let Navigation = { } as Navigation ;
2024-07-28 18:17:52 -04:00
const logger = new Logger ( "Navigation" ) ;
2023-01-12 21:55:08 -05:00
try {
2024-07-28 18:17:52 -04:00
function createNavigationFunction ( fncName : string , handler ? : ( win : any ) = > any ) {
return ( . . . args : any ) = > {
let win : WindowRouter | undefined ;
try {
win = window . SteamUIStore . GetFocusedWindowInstance ( ) ;
} catch ( e ) {
logger . warn ( "Navigation interface failed to call GetFocusedWindowInstance" , e ) ;
}
if ( ! win ) {
logger . warn ( "Navigation interface could not find any focused window. Falling back to GamepadUIMainWindowInstance" ) ;
win = Router . WindowStore ? . GamepadUIMainWindowInstance ;
}
if ( win ) {
2023-01-16 09:12:16 -05:00
try {
2024-07-28 18:17:52 -04:00
const thisObj = handler && handler ( win ) ;
( thisObj || win ) [ fncName ] ( . . . args ) ;
2023-01-16 09:12:16 -05:00
} catch ( e ) {
2024-07-28 18:17:52 -04:00
logger . error ( "Navigation handler failed" , e ) ;
2023-01-16 09:12:16 -05:00
}
2024-07-28 18:17:52 -04:00
} else {
logger . error ( "Navigation interface could not find a window to navigate" ) ;
2023-01-16 09:12:16 -05:00
}
2023-01-15 20:22:54 -05:00
}
2024-07-28 18:17:52 -04:00
}
const newNavigation = {
Navigate : createNavigationFunction ( "Navigate" ) ,
NavigateBack : createNavigationFunction ( "NavigateBack" ) ,
NavigateToAppProperties : createNavigationFunction ( "AppProperties" , win = > win . Navigator ) ,
NavigateToExternalWeb : createNavigationFunction ( "ExternalWeb" , win = > win . Navigator ) ,
NavigateToInvites : createNavigationFunction ( "Invites" , win = > win . Navigator ) ,
NavigateToChat : createNavigationFunction ( "Chat" , win = > win . Navigator ) ,
NavigateToLibraryTab : createNavigationFunction ( "LibraryTab" , win = > win . Navigator ) ,
NavigateToLayoutPreview : Router.NavigateToLayoutPreview?.bind ( Router ) ,
NavigateToSteamWeb : createNavigationFunction ( "NavigateToSteamWeb" ) ,
OpenSideMenu : createNavigationFunction ( "OpenSideMenu" , win = > win . MenuStore ) ,
OpenQuickAccessMenu : createNavigationFunction ( "OpenQuickAccessMenu" , win = > win . MenuStore ) ,
OpenMainMenu : createNavigationFunction ( "OpenMainMenu" , win = > win . MenuStore ) ,
CloseSideMenus : createNavigationFunction ( "CloseSideMenus" , win = > win . MenuStore ) ,
OpenPowerMenu : Router.OpenPowerMenu?.bind ( Router ) ,
} as Navigation ;
2023-01-15 20:22:54 -05:00
2024-07-28 18:17:52 -04:00
Object . assign ( Navigation , newNavigation ) ;
2023-01-12 21:55:08 -05:00
} catch ( e ) {
2024-07-28 18:17:52 -04:00
logger . error ( 'Error initializing Navigation interface' , e ) ;
2023-01-15 20:22:54 -05:00
}