Skip to content

Commit

Permalink
[Fix] open overlay for epic forwarder listings (#977)
Browse files Browse the repository at this point in the history
* open overlay for epic forwarder listings

* fix time for epic forwarder listings

* bump 0.17.1
  • Loading branch information
BrettCleary authored Jul 31, 2024
1 parent 632525a commit 17f3f42
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyperplay",
"version": "0.17.0",
"version": "0.17.1",
"private": true,
"main": "build/main/main.js",
"homepage": "./",
Expand Down
17 changes: 10 additions & 7 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { LegendaryCommand } from './storeManagers/legendary/commands'
import { commandToArgsArray } from './storeManagers/legendary/library'
import { searchForExecutableOnPath } from './utils/os/path'
import { getHpOverlay } from './overlay'
import { launchingGameShouldOpenOverlay } from './utils/shouldOpenOverlay'

async function prepareLaunch(
gameSettings: GameSettings,
Expand Down Expand Up @@ -821,6 +822,8 @@ async function callRunner(
return currentPromise
}
const hpOverlay = await getHpOverlay()
const { shouldOpenOverlay, gameIsEpicForwarderOnHP, hyperPlayListing } =
await launchingGameShouldOpenOverlay(gameInfo)

let promise = new Promise<ExecResult>((res, rej) => {
const child = spawn(bin, commandParts, {
Expand All @@ -829,13 +832,13 @@ async function callRunner(
signal: abortController.signal
})

const shouldOpenOverlay =
gameInfo &&
(gameInfo.runner === 'hyperplay' ||
(gameInfo.runner === 'sideload' && gameInfo.web3?.supported))

if (shouldOpenOverlay)
hpOverlay?.openOverlay(gameInfo?.app_name, gameInfo.runner)
if (gameInfo && shouldOpenOverlay) {
if (gameIsEpicForwarderOnHP && hyperPlayListing?.project_id) {
hpOverlay?.openOverlay(hyperPlayListing?.project_id, gameInfo.runner)
} else {
hpOverlay?.openOverlay(gameInfo?.app_name, gameInfo.runner)
}
}

const stdout: string[] = []
const stderr: string[] = []
Expand Down
18 changes: 14 additions & 4 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ import { hrtime } from 'process'
import { getHyperPlayReleaseObject } from './storeManagers/hyperplay/utils'
import { postPlaySessionTime } from './utils/quests'

import { gameIsEpicForwarderOnHyperPlay } from './utils/shouldOpenOverlay'

async function startProxyServer() {
try {
const proxyServer = await import('@hyperplay/proxy-server')
Expand Down Expand Up @@ -1312,10 +1314,18 @@ ipcMain.handle(
BigInt(tsStore.get(`${appName}.totalPlayed`, 0))
tsStore.set(`${appName}.totalPlayed`, Number(totalPlaytime))

postPlaySessionTime(
appName,
parseInt((sessionPlaytimeInMs / BigInt(1000)).toString())
)
const { gameIsEpicForwarderOnHP, hyperPlayListing } =
await gameIsEpicForwarderOnHyperPlay(game)

if (gameIsEpicForwarderOnHP && hyperPlayListing) {
// TODO: fix legendary launch await
postPlaySessionTime(hyperPlayListing.project_id, 900)
} else {
postPlaySessionTime(
appName,
parseInt((sessionPlaytimeInMs / BigInt(1000)).toString())
)
}

if (runner === 'gog') {
await updateGOGPlaytime(appName, startPlayingDate, finishedPlayingDate)
Expand Down
14 changes: 14 additions & 0 deletions src/backend/storeManagers/hyperplay/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export async function getHyperPlayReleaseMap() {
return hpStoreGameMap
}

export async function getHyperPlayNameToReleaseMap() {
const hpStoreGameReleases = (
await axios.get<HyperPlayRelease[]>(valistListingsApiUrl)
).data

const hpStoreGameMap = new Map<string, HyperPlayRelease>()

hpStoreGameReleases.forEach((val) => {
hpStoreGameMap.set(val.project_name.toLowerCase(), val)
})

return hpStoreGameMap
}

/**
* @returns an object mapping project id key to listing value
* necessary for stringifying over ipc to send to the frontend.
Expand Down
6 changes: 2 additions & 4 deletions src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { PROVIDERS } from 'common/types/proxy-types'
import { getExecutableAndArgs } from 'backend/utils'
import { hpApi } from 'backend/utils/hyperplay_api'
import { getHpOverlay } from 'backend/overlay'
import { launchingGameShouldOpenOverlay } from 'backend/utils/shouldOpenOverlay'

export async function getAppSettings(appName: string): Promise<GameSettings> {
return (
Expand Down Expand Up @@ -360,10 +361,7 @@ export async function launchGame(
LogPrefix.Backend
)

const shouldOpenOverlay =
gameInfo &&
(gameInfo.runner === 'hyperplay' ||
(gameInfo.runner === 'sideload' && gameInfo.web3?.supported))
const { shouldOpenOverlay } = await launchingGameShouldOpenOverlay(gameInfo)

await runWineCommand({
commandParts: [exeOnly, combinedArgs ?? ''],
Expand Down
33 changes: 33 additions & 0 deletions src/backend/utils/shouldOpenOverlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getHyperPlayNameToReleaseMap } from 'backend/storeManagers/hyperplay/utils'
import { GameInfo } from 'common/types'

export async function gameIsEpicForwarderOnHyperPlay(gameInfo: GameInfo) {
const gameNameMap = await getHyperPlayNameToReleaseMap()
let hyperPlayListing = undefined
const gameInfoTitle = gameInfo.title.toLowerCase()
const gameIsEpicForwarderOnHP =
gameInfo.runner === 'legendary' && gameNameMap.has(gameInfoTitle)
if (gameIsEpicForwarderOnHP) {
hyperPlayListing = gameNameMap.get(gameInfoTitle)
}
return { gameIsEpicForwarderOnHP, hyperPlayListing }
}

export async function launchingGameShouldOpenOverlay(gameInfo?: GameInfo) {
if (!gameInfo) {
return { shouldOpenOverlay: false }
}
const { gameIsEpicForwarderOnHP, hyperPlayListing } =
await gameIsEpicForwarderOnHyperPlay(gameInfo)
const gameIsDirectOnHyperPlay = gameInfo.runner === 'hyperplay'
const gameIsSideloadedWithWeb3 =
gameInfo.runner === 'sideload' && !!gameInfo.web3?.supported
return {
shouldOpenOverlay:
gameIsEpicForwarderOnHP ||
gameIsDirectOnHyperPlay ||
gameIsSideloadedWithWeb3,
gameIsEpicForwarderOnHP,
hyperPlayListing
}
}

0 comments on commit 17f3f42

Please sign in to comment.