@@ -184,6 +184,7 @@ import { PROVIDERS } from 'common/types/proxy-types'
184
184
import 'backend/ipcHandlers/quests'
185
185
import 'backend/ipcHandlers/achievements'
186
186
import 'backend/utils/auto_launch'
187
+ import { hrtime } from 'process'
187
188
import { getHyperPlayReleaseObject } from './storeManagers/hyperplay/utils'
188
189
189
190
async function startProxyServer ( ) {
@@ -1123,6 +1124,8 @@ ipcMain.handle(
1123
1124
const { minimizeOnGameLaunch } = GlobalConfig . get ( ) . getSettings ( )
1124
1125
1125
1126
const startPlayingDate = new Date ( )
1127
+ // Uses hrtime for monotonic timer not subject to clock drift or sync errors
1128
+ const startPlayingTimeMonotonic = hrtime . bigint ( )
1126
1129
1127
1130
if ( ! tsStore . has ( game . app_name ) ) {
1128
1131
tsStore . set (
@@ -1272,12 +1275,17 @@ ipcMain.handle(
1272
1275
// Update playtime and last played date
1273
1276
const finishedPlayingDate = new Date ( )
1274
1277
tsStore . set ( `${ appName } .lastPlayed` , finishedPlayingDate . toISOString ( ) )
1275
- // Playtime of this session in minutes
1276
- const sessionPlaytime =
1277
- ( finishedPlayingDate . getTime ( ) - startPlayingDate . getTime ( ) ) / 1000 / 60
1278
+ // Playtime of this session in minutes. Uses hrtime for monotonic timer not subject to clock drift or sync errors
1279
+ const stopPlayingTimeMonotonic = hrtime . bigint ( )
1280
+ const sessionPlaytimeInMs =
1281
+ ( stopPlayingTimeMonotonic - startPlayingTimeMonotonic ) / BigInt ( 1000000 )
1282
+ const sessionPlaytimeInMinutes =
1283
+ sessionPlaytimeInMs / BigInt ( 1000 ) / BigInt ( 60 )
1284
+
1278
1285
const totalPlaytime =
1279
- sessionPlaytime + tsStore . get ( `${ appName } .totalPlayed` , 0 )
1280
- tsStore . set ( `${ appName } .totalPlayed` , Math . floor ( totalPlaytime ) )
1286
+ sessionPlaytimeInMinutes +
1287
+ BigInt ( tsStore . get ( `${ appName } .totalPlayed` , 0 ) )
1288
+ tsStore . set ( `${ appName } .totalPlayed` , Number ( totalPlaytime ) )
1281
1289
1282
1290
if ( runner === 'gog' ) {
1283
1291
await updateGOGPlaytime ( appName , startPlayingDate , finishedPlayingDate )
@@ -1330,7 +1338,7 @@ ipcMain.handle(
1330
1338
store_name : getStoreName ( runner ) ,
1331
1339
browserUrl : browserUrl ?? undefined ,
1332
1340
platform : getPlatformName ( install . platform ! ) ,
1333
- playTimeInMs : sessionPlaytime * 60 * 1000 ,
1341
+ playTimeInMs : Number ( sessionPlaytimeInMs ) ,
1334
1342
platform_arch : install . platform !
1335
1343
}
1336
1344
} )
0 commit comments