1
1
import './index.scss'
2
2
3
- import React , { useContext , useEffect , useState } from 'react'
3
+ import React , { useContext , useEffect , useRef , useState } from 'react'
4
4
5
5
import {
6
6
BackArrowOutlinedCircled ,
@@ -31,7 +31,8 @@ import {
31
31
HyperPlayInstallInfo ,
32
32
InstallProgress ,
33
33
Runner ,
34
- WineInstallation
34
+ WineInstallation ,
35
+ GamePageActions
35
36
} from 'common/types'
36
37
import { LegendaryInstallInfo } from 'common/types/legendary'
37
38
import { GogInstallInfo } from 'common/types/gog'
@@ -73,6 +74,7 @@ type locationState = {
73
74
fromDM ?: boolean
74
75
gameInfo : GameInfo
75
76
fromQuests ?: boolean
77
+ action : GamePageActions
76
78
}
77
79
78
80
export default observer ( function GamePage ( ) : JSX . Element | null {
@@ -83,7 +85,7 @@ export default observer(function GamePage(): JSX.Element | null {
83
85
const { t } = useTranslation ( 'gamepage' )
84
86
const { t : t2 } = useTranslation ( )
85
87
86
- const { gameInfo : locationGameInfo } = location . state
88
+ const { gameInfo : locationGameInfo , action } = location . state
87
89
88
90
const [ showModal , setShowModal ] = useState ( { game : '' , show : false } )
89
91
@@ -142,6 +144,9 @@ export default observer(function GamePage(): JSX.Element | null {
142
144
const notSupportedGame =
143
145
gameInfo . runner !== 'sideload' && gameInfo . thirdPartyManagedApp === 'Origin'
144
146
const isOffline = connectivity . status !== 'online'
147
+ const installPlatform = gameInfo . install ?. platform
148
+ const isBrowserGame =
149
+ installPlatform === 'Browser' || installPlatform === 'web'
145
150
146
151
const backRoute = getBackRoute ( location . state )
147
152
@@ -153,6 +158,23 @@ export default observer(function GamePage(): JSX.Element | null {
153
158
gameInstallInfo ?. manifest ?. download_size || 0
154
159
)
155
160
161
+ const hasRun = useRef ( false )
162
+ useEffect ( ( ) => {
163
+ if ( ! action || hasRun . current ) return
164
+ hasRun . current = true
165
+
166
+ if ( action === 'install' ) {
167
+ return setShowModal ( { game : appName , show : true } )
168
+ }
169
+ if ( action === 'launch' ) {
170
+ if ( isBrowserGame || gameInfo . is_installed ) {
171
+ handlePlay ( ) ( )
172
+ } else {
173
+ return setShowModal ( { game : appName , show : true } )
174
+ }
175
+ }
176
+ } , [ action ] )
177
+
156
178
// Track the screen view once each time the appName, gameInfo or runner changes
157
179
useEffect ( ( ) => {
158
180
window . api . trackScreen ( 'Game Page' , {
@@ -330,7 +352,6 @@ export default observer(function GamePage(): JSX.Element | null {
330
352
const isLinux = [ 'linux' , 'linux_amd64' , 'linux_arm64' ]
331
353
const isMacNative = isMac . includes ( installPlatform ?? '' )
332
354
const isLinuxNative = isLinux . includes ( installPlatform ?? '' )
333
- const isBrowserGame = gameInfo . browserUrl
334
355
const isNative = isWin || isMacNative || isLinuxNative || isBrowserGame
335
356
const isHyperPlayGame = runner === 'hyperplay'
336
357
@@ -951,6 +972,7 @@ export default observer(function GamePage(): JSX.Element | null {
951
972
} )
952
973
}
953
974
} )
975
+
954
976
function getCurrentProgress (
955
977
progress : InstallProgress ,
956
978
percent : number | undefined ,
0 commit comments