Skip to content

Commit 0f5b9e6

Browse files
[FEAT] Add support for Actions when navigating to GamePage (#1086)
* feat: add support for actions when navigating to gamepage * feat: update download manager action buttons * types: update all types with actions * fix: import * fix: double launching * fix: pr comments * fix: type * Update src/frontend/screens/Game/GamePage/index.tsx Co-authored-by: Brett <27568879+BrettCleary@users.noreply.github.com> * fix: installPLatform undefined * types: export/import from common/types * reverte before merge: add test url --------- Co-authored-by: Flavio F Lima <flavioislima@users.noreply.github.com> Co-authored-by: Brett <27568879+BrettCleary@users.noreply.github.com>
1 parent ad4d8b5 commit 0f5b9e6

File tree

14 files changed

+70
-31
lines changed

14 files changed

+70
-31
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
"@hyperplay/check-disk-space": "^3.5.2",
172172
"@hyperplay/quests-ui": "^0.0.21",
173173
"@hyperplay/ui": "^1.7.18",
174-
"@hyperplay/utils": "^0.0.16",
174+
"@hyperplay/utils": "^0.2.4",
175175
"@mantine/carousel": "^7.12.0",
176176
"@mantine/core": "^7.12.0",
177177
"@mantine/dropzone": "^7.12.0",

src/backend/api/library.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
LaunchParams,
66
ImportGameArgs,
77
GameStatus,
8-
GameInfo
8+
GameInfo,
9+
GamePageActions
910
} from 'common/types'
1011

1112
export const openDialog = async (args: Electron.OpenDialogOptions) =>
@@ -58,7 +59,11 @@ export const handleGameStatus = (
5859
}
5960

6061
export const handleGoToGamePage = (
61-
onChange: (e: Electron.IpcRendererEvent, gameId: string) => void
62+
onChange: (
63+
e: Electron.IpcRendererEvent,
64+
gameId: string,
65+
action: GamePageActions
66+
) => void
6267
) => {
6368
ipcRenderer.on('goToGamePage', onChange)
6469
return () => {

src/backend/hyperplay_store_preload.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GamePageActions } from 'common/types'
12
import { contextBridge, ipcRenderer } from 'electron'
23

34
contextBridge.exposeInMainWorld('api', {
@@ -18,6 +19,7 @@ contextBridge.exposeInMainWorld('api', {
1819
apiVersion: 1,
1920
appIsInLibrary: async (gameId: string) =>
2021
ipcRenderer.invoke('appIsInLibrary', gameId, 'hyperplay'),
21-
goToGamePage: (gameId: string) => ipcRenderer.send('goToGamePage', gameId),
22+
goToGamePage: (gameId: string, action: GamePageActions) =>
23+
ipcRenderer.send('goToGamePage', gameId, action),
2224
navigate: (route: string) => ipcRenderer.send('navigate', route)
2325
})

src/backend/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ ipcMain.handle('appIsInLibrary', async (event, appName, runner) => {
904904
return HyperPlayGameManager.appIsInLibrary(appName)
905905
})
906906

907-
ipcMain.on('goToGamePage', async (event, appName) => {
908-
return sendFrontendMessage('goToGamePage', appName)
907+
ipcMain.on('goToGamePage', async (event, gameId, action) => {
908+
return sendFrontendMessage('goToGamePage', gameId, action)
909909
})
910910

911911
ipcMain.on('navigate', async (event, appName) => {

src/backend/storeManagers/hyperplay/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ export function refreshGameInfoFromHpRelease(
219219
: data.project_name
220220
}
221221
],
222-
storeUrl: `https://store.hyperplay.xyz/game/${data.project_name}`
222+
storeUrl: `https://hyperplay-store-git-feat-gamepageactions-hyperplay.vercel.app/game/${data.project_name}`
223223
},
224224
art_square: newArtSquare !== undefined ? newArtSquare : 'fallback',
225225
art_cover: newArtCover !== undefined ? newArtCover : 'fallback',
226226
developer: data.account_meta.name || data.account_name,
227227
version: latestVersion,
228228
is_windows_native: hasWindowsNativeBuild,
229229
channels: channelsMap,
230-
store_url: `https://store.hyperplay.xyz/game/${data.project_name}`,
230+
store_url: `https://hyperplay-store-git-feat-gamepageactions-hyperplay.vercel.app/game/${data.project_name}`,
231231
wineSupport: data.project_meta.wine_support,
232232
description: newDescription,
233233
v: '1',

src/common/typedefs/ipcBridge.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ interface HyperPlaySyncIPCFunctions {
9595
killOverlay: () => void
9696
toggleOverlay: () => void
9797
authConnected: () => void
98-
goToGamePage: (appName: string) => void
98+
goToGamePage: (gameId: string, action: GamePageActions) => void
9999
authDisconnected: () => void
100100
otp: (otp: string) => void
101101
navigate: (route: string) => void

src/common/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -993,3 +993,5 @@ export interface PointsCollection {
993993
symbol: string
994994
image: string
995995
}
996+
997+
export type { GamePageActions } from '@hyperplay/utils'

src/frontend/components/UI/DownloadToastManager/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export default function DownloadToastManager() {
117117
}, [isExtracting])
118118

119119
if (currentElement === undefined) {
120-
console.debug('no downloads active in download toast manager')
121120
return <></>
122121
}
123122

src/frontend/components/UI/WebviewControls/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ export default function WebviewControls({
8686
)
8787

8888
const _url = url !== '' ? new URL(url) : null
89-
const allowList = ['store.hyperplay.xyz', 'docs.hyperplay.xyz']
89+
const allowList = [
90+
'hyperplay-store-git-feat-gamepageactions-hyperplay.vercel.app',
91+
'docs.hyperplay.xyz'
92+
]
9093

9194
if (_url && allowList.includes(_url.host)) return null
9295

src/frontend/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const EPIC_LOGIN_URL = 'https://legendary.gl/epiclogin'
2-
export const HYPERPLAY_STORE_URL = 'https://store.hyperplay.xyz?isLauncher=true'
2+
export const HYPERPLAY_STORE_URL =
3+
'https://hyperplay-store-git-feat-gamepageactions-hyperplay.vercel.app?isLauncher=true'
34
export const EPIC_STORE_URL = 'https://www.epicgames.com/store'
45
export const GOG_STORE_URL = `https://gog.com`
56
export const WIKI_URL = 'https://docs.hyperplay.xyz/'

src/frontend/screens/DownloadManager/components/DownloadManagerItem/index.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
DMQueueElement,
77
DownloadManagerState,
88
GameInfo,
9-
HyperPlayInstallInfo
9+
HyperPlayInstallInfo,
10+
GamePageActions
1011
} from 'common/types'
1112
import { CachedImage, SvgButton } from 'frontend/components/UI'
1213
import {
@@ -130,20 +131,21 @@ const DownloadManagerItem = observer(({ element, current, state }: Props) => {
130131
const canceled = status === 'error' || (status === 'abort' && !current)
131132
const isExtracting = gameProgressStatus === 'extracting'
132133

133-
const goToGamePage = () => {
134+
const goToGamePage = (action?: GamePageActions) => {
134135
if (is_dlc) {
135136
return
136137
}
137138
return navigate(`/gamepage/${runner}/${appName}`, {
138-
state: { fromDM: true, gameInfo: gameInfo }
139+
state: { fromDM: true, gameInfo: gameInfo, action }
139140
})
140141
}
141142

142143
// using one element for the different states so it doesn't
143144
// lose focus from the button when using a game controller
144-
const handleMainActionClick = () => {
145+
const handleMainActionClick = async () => {
146+
const action = finished ? 'launch' : 'install'
145147
if (finished || canceled) {
146-
return goToGamePage()
148+
return goToGamePage(action)
147149
}
148150

149151
// gameInfo must be defined in order to get folder name for stop installation modal

src/frontend/screens/Game/GamePage/index.tsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './index.scss'
22

3-
import React, { useContext, useEffect, useState } from 'react'
3+
import React, { useContext, useEffect, useRef, useState } from 'react'
44

55
import {
66
BackArrowOutlinedCircled,
@@ -31,7 +31,8 @@ import {
3131
HyperPlayInstallInfo,
3232
InstallProgress,
3333
Runner,
34-
WineInstallation
34+
WineInstallation,
35+
GamePageActions
3536
} from 'common/types'
3637
import { LegendaryInstallInfo } from 'common/types/legendary'
3738
import { GogInstallInfo } from 'common/types/gog'
@@ -73,6 +74,7 @@ type locationState = {
7374
fromDM?: boolean
7475
gameInfo: GameInfo
7576
fromQuests?: boolean
77+
action: GamePageActions
7678
}
7779

7880
export default observer(function GamePage(): JSX.Element | null {
@@ -83,7 +85,7 @@ export default observer(function GamePage(): JSX.Element | null {
8385
const { t } = useTranslation('gamepage')
8486
const { t: t2 } = useTranslation()
8587

86-
const { gameInfo: locationGameInfo } = location.state
88+
const { gameInfo: locationGameInfo, action } = location.state
8789

8890
const [showModal, setShowModal] = useState({ game: '', show: false })
8991

@@ -142,6 +144,9 @@ export default observer(function GamePage(): JSX.Element | null {
142144
const notSupportedGame =
143145
gameInfo.runner !== 'sideload' && gameInfo.thirdPartyManagedApp === 'Origin'
144146
const isOffline = connectivity.status !== 'online'
147+
const installPlatform = gameInfo.install?.platform
148+
const isBrowserGame =
149+
installPlatform === 'Browser' || installPlatform === 'web'
145150

146151
const backRoute = getBackRoute(location.state)
147152

@@ -153,6 +158,23 @@ export default observer(function GamePage(): JSX.Element | null {
153158
gameInstallInfo?.manifest?.download_size || 0
154159
)
155160

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+
156178
// Track the screen view once each time the appName, gameInfo or runner changes
157179
useEffect(() => {
158180
window.api.trackScreen('Game Page', {
@@ -330,7 +352,6 @@ export default observer(function GamePage(): JSX.Element | null {
330352
const isLinux = ['linux', 'linux_amd64', 'linux_arm64']
331353
const isMacNative = isMac.includes(installPlatform ?? '')
332354
const isLinuxNative = isLinux.includes(installPlatform ?? '')
333-
const isBrowserGame = gameInfo.browserUrl
334355
const isNative = isWin || isMacNative || isLinuxNative || isBrowserGame
335356
const isHyperPlayGame = runner === 'hyperplay'
336357

@@ -951,6 +972,7 @@ export default observer(function GamePage(): JSX.Element | null {
951972
})
952973
}
953974
})
975+
954976
function getCurrentProgress(
955977
progress: InstallProgress,
956978
percent: number | undefined,

src/frontend/screens/WebView/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import { getGameInfo } from 'frontend/helpers'
3232

3333
function urlIsHpUrl(url: string) {
3434
const urlToTest = new URL(url)
35-
return urlToTest.hostname === 'store.hyperplay.xyz'
35+
return (
36+
urlToTest.hostname ===
37+
'hyperplay-store-git-feat-gamepageactions-hyperplay.vercel.app'
38+
)
3639
}
3740

3841
function shouldInjectProvider(url: string) {
@@ -131,10 +134,10 @@ function WebView() {
131134
}
132135

133136
const removeHandleGoToGamePage = window.api.handleGoToGamePage(
134-
async (_, gameId) => {
137+
async (_, gameId, action) => {
135138
const gameInfo = await getGameInfo(gameId, 'hyperplay')
136139
navigate(`/gamepage/hyperplay/${gameId}`, {
137-
state: { gameInfo, fromDM: false }
140+
state: { gameInfo, fromDM: false, action }
138141
})
139142
}
140143
)

yarn.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -1335,20 +1335,20 @@
13351335
dependencies:
13361336
bignumber.js "^9.1.2"
13371337

1338-
"@hyperplay/utils@^0.0.16":
1339-
version "0.0.16"
1340-
resolved "https://registry.yarnpkg.com/@hyperplay/utils/-/utils-0.0.16.tgz#92520b12b2870260c34d7e76195713a5b0be2acc"
1341-
integrity sha512-2k0kTePgNfgnW2kDM5ZkQv1Q+K24EQRipyr5ECgNtaWmJrF11It/OZ0Yjsdr+cK/zEiFmCCNWet+kqGqGt80JQ==
1342-
dependencies:
1343-
bignumber.js "^9.1.2"
1344-
13451338
"@hyperplay/utils@^0.0.9":
13461339
version "0.0.9"
13471340
resolved "https://registry.yarnpkg.com/@hyperplay/utils/-/utils-0.0.9.tgz#80836cfde5c4d63e41f5df809ae2e80314600c5a"
13481341
integrity sha512-gMAa6gdFXfLrJUjPAD2is06qNo4MHzpb6Cbzt4xfNd7wI9chOblQ+piwTI1oFWs44GgfacsMq6i5esNly3hELg==
13491342
dependencies:
13501343
bignumber.js "^9.1.2"
13511344

1345+
"@hyperplay/utils@^0.2.4":
1346+
version "0.2.4"
1347+
resolved "https://registry.yarnpkg.com/@hyperplay/utils/-/utils-0.2.4.tgz#17621d43f0d92a3d22de87dc08d96b0f2db2291c"
1348+
integrity sha512-aQLyh8xpVDK+R0jvHrU6eHtmcMu18PP+33bFlGvrqfLRhHfN7xmThrCfPzueWSP3u4MDQku6lQT3bYzMrATjvQ==
1349+
dependencies:
1350+
bignumber.js "^9.1.2"
1351+
13521352
"@ioredis/commands@^1.1.1":
13531353
version "1.2.0"
13541354
resolved "https://registry.yarnpkg.com/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11"

0 commit comments

Comments
 (0)