Skip to content

Commit df5cb64

Browse files
authored
[Feat] Navigate to Game page from Store (#914)
* feat: Support navigate from Store to Library * fix: import * chore: REVERT BEFORE MERGING - test store URL * chore: only listen to ipc calls on hp url * Revert "chore: REVERT BEFORE MERGING - test store URL" This reverts commit 07357fd. * fix: pr comments * Revert "fix: pr comments" This reverts commit e5bd86a. * fix: pr comments * Revert "Revert "chore: REVERT BEFORE MERGING - test store URL"" This reverts commit 93c65fa. * Revert "Revert "Revert "chore: REVERT BEFORE MERGING - test store URL""" This reverts commit be94bfe. --------- Co-authored-by: Flavio F Lima <flavioislima@users.noreply.github.com>
1 parent 01cb082 commit df5cb64

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

src/backend/api/library.ts

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ export const handleGameStatus = (
5757
}
5858
}
5959

60+
export const handleGoToGamePage = (
61+
onChange: (e: Electron.IpcRendererEvent, gameId: string) => void
62+
) => {
63+
ipcRenderer.on('goToGamePage', onChange)
64+
return () => {
65+
ipcRenderer.removeListener('goToGamePage', onChange)
66+
}
67+
}
68+
6069
export const onProgressUpdate = (
6170
appName: string,
6271
onChange: (e: Electron.IpcRendererEvent, status: GameStatus) => void

src/backend/hyperplay_store_preload.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ contextBridge.exposeInMainWorld('api', {
1717
ipcRenderer.send('openGameInEpicStore', url),
1818
apiVersion: 1,
1919
appIsInLibrary: async (gameId: string) =>
20-
ipcRenderer.invoke('appIsInLibrary', gameId, 'hyperplay')
20+
ipcRenderer.invoke('appIsInLibrary', gameId, 'hyperplay'),
21+
goToGamePage: (gameId: string) => ipcRenderer.send('goToGamePage', gameId)
2122
})

src/backend/main.ts

+4
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,10 @@ ipcMain.handle('appIsInLibrary', async (event, appName, runner) => {
879879
return HyperPlayGameManager.appIsInLibrary(appName)
880880
})
881881

882+
ipcMain.on('goToGamePage', async (event, appName) => {
883+
return sendFrontendMessage('goToGamePage', appName)
884+
})
885+
882886
ipcMain.handle('getGameInfo', async (event, appName, runner) => {
883887
// Fastpath since we sometimes have to request info for a GOG game as Legendary because we don't know it's a GOG game yet
884888
if (runner === 'legendary' && !LegendaryLibraryManager.hasGame(appName)) {

src/common/typedefs/ipcBridge.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ interface HyperPlaySyncIPCFunctions {
8989
lockPopup: (lock: boolean) => void
9090
killOverlay: () => void
9191
toggleOverlay: () => void
92+
goToGamePage: (appName: string) => void
9293
}
9394

9495
interface SyncIPCFunctions extends HyperPlaySyncIPCFunctions {

src/frontend/screens/WebView/index.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from '../../constants'
2929
import { METAMASK_SNAPS_URL } from 'common/constants'
3030
import storeAuthState from 'frontend/state/storeAuthState'
31+
import { getGameInfo } from 'frontend/helpers'
3132

3233
function urlIsHpUrl(url: string) {
3334
const urlToTest = new URL(url)
@@ -124,6 +125,25 @@ function WebView() {
124125
window.api.trackScreen('WebView', { url: startUrl, runner })
125126
}, [startUrl, runner])
126127

128+
useEffect(() => {
129+
if (!urlIsHpUrl(startUrl)) {
130+
return
131+
}
132+
133+
const removeHandleGoToGamePage = window.api.handleGoToGamePage(
134+
async (_, gameId) => {
135+
const gameInfo = await getGameInfo(gameId, 'hyperplay')
136+
navigate(`/gamepage/hyperplay/${gameId}`, {
137+
state: { gameInfo, fromDM: false }
138+
})
139+
}
140+
)
141+
142+
return () => {
143+
removeHandleGoToGamePage()
144+
}
145+
}, [])
146+
127147
useLayoutEffect(() => {
128148
const webview = webviewRef.current
129149
if (webview && ((preloadPath && isEpicLogin) || !isEpicLogin)) {

0 commit comments

Comments
 (0)