diff --git a/package.json b/package.json index eb7f2ea7c..e5870cf12 100644 --- a/package.json +++ b/package.json @@ -183,8 +183,8 @@ "@sentry/electron": "^4.24.0", "@sentry/react": "7.50.0", "@shockpkg/icon-encoder": "^2.1.3", - "@tanstack/query-core": "^5.59.0", - "@tanstack/react-query": "^5.51.23", + "@tanstack/query-core": "^5.59.13", + "@tanstack/react-query": "^5.59.15", "@valist/sdk": "^2.10.5", "@walletconnect/browser-utils": "^1.8.0", "@walletconnect/ethereum-provider": "^2.10.6", diff --git a/src/backend/main.ts b/src/backend/main.ts index a803ad936..c477af39b 100644 --- a/src/backend/main.ts +++ b/src/backend/main.ts @@ -1103,10 +1103,12 @@ let powerDisplayId: number | null let gamePlaySessionStartTimes: Record = {} function startNewPlaySession(appName: string) { + const prevStartTime = gamePlaySessionStartTimes[appName] gamePlaySessionStartTimes = {} // Uses hrtime for monotonic timer not subject to clock drift or sync errors const startPlayingTimeMonotonic = hrtime.bigint() gamePlaySessionStartTimes[appName] = startPlayingTimeMonotonic + return prevStartTime } async function syncPlaySession(appName: string, runner: Runner) { @@ -1114,13 +1116,11 @@ async function syncPlaySession(appName: string, runner: Runner) { return } + // reset the time counter and start new session slightly before ending current session to prevent time loss + const startPlayingTimeMonotonic = startNewPlaySession(appName) const stopPlayingTimeMonotonic = hrtime.bigint() const sessionPlaytimeInMs = - (stopPlayingTimeMonotonic - gamePlaySessionStartTimes[appName]) / - BigInt(1000000) - - // reset the time counter - startNewPlaySession(appName) + (stopPlayingTimeMonotonic - startPlayingTimeMonotonic) / BigInt(1000000) // update local json with time played const sessionPlaytimeInMinutes = @@ -1132,9 +1132,10 @@ async function syncPlaySession(appName: string, runner: Runner) { const game = gameManagerMap[runner].getGameInfo(appName) const { hyperPlayListing } = await gameIsEpicForwarderOnHyperPlay(game) - postPlaySessionTime( + await postPlaySessionTime( hyperPlayListing?.project_id || appName, - parseInt((sessionPlaytimeInMs / BigInt(1000)).toString()) + // round up to prevent session time loss + parseInt(((sessionPlaytimeInMs + BigInt(1000)) / BigInt(1000)).toString()) ) return sessionPlaytimeInMs diff --git a/src/frontend/OverlayManager/index.tsx b/src/frontend/OverlayManager/index.tsx index bdfa21b0c..b05cfdfea 100644 --- a/src/frontend/OverlayManager/index.tsx +++ b/src/frontend/OverlayManager/index.tsx @@ -9,11 +9,20 @@ import { Overlay } from './Overlay' import { WebviewTag } from 'electron' import WebviewControls from 'frontend/components/UI/WebviewControls' import AuthModal from 'frontend/components/UI/AuthModal' +import { useKeepPlaystreaksInSync } from '@hyperplay/quests-ui' const OverlayManager = observer(function ({ appName, runner }: BrowserGameProps) { + useKeepPlaystreaksInSync({ + appName, + runner, + getQuest: window.api.getQuest, + getQuests: window.api.getQuests, + getUserPlayStreak: window.api.getUserPlayStreak, + syncPlaySession: window.api.syncPlaySession + }) const url = OverlayState.renderState.browserGameUrl /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ diff --git a/yarn.lock b/yarn.lock index aedd14cbd..46df236cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2993,10 +2993,10 @@ dependencies: defer-to-connect "^2.0.0" -"@tanstack/query-core@5.52.2": - version "5.52.2" - resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.52.2.tgz#a023864a892fda9858b724d667eb19cd84ce054a" - integrity sha512-9vvbFecK4A0nDnrc/ks41e3UHONF1DAnGz8Tgbxkl59QcvKWmc0ewhYuIKRh8NC4ja5LTHT9EH16KHbn2AIYWA== +"@tanstack/query-core@5.59.13", "@tanstack/query-core@^5.59.13": + version "5.59.13" + resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.59.13.tgz#8c962980af174bbd446b7e9b9999f7432897df80" + integrity sha512-Oou0bBu/P8+oYjXsJQ11j+gcpLAMpqW42UlokQYEz4dE7+hOtVO9rVuolJKgEccqzvyFzqX4/zZWY+R/v1wVsQ== "@tanstack/query-core@^5.59.0": version "5.59.0" @@ -3020,7 +3020,7 @@ resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.52.2.tgz#3fffbc86351edcaeec335bc8958bcab4204bd169" integrity sha512-d4OwmobpP+6+SvuAxW1RzAY95Pv87Gu+0GjtErzFOUXo+n0FGcwxKvzhswCsXKxsgnAr3bU2eJ2u+GXQAutkCQ== dependencies: - "@tanstack/query-core" "5.52.2" + "@tanstack/query-core" "5.59.13" "@testing-library/dom@^7.31.2": version "7.31.2"