itchio / itch

🎮 The best way to play your itch.io games
https://itch.io/app
MIT License
2.31k stars 198 forks source link

Niche Feature Request: Account for system sleep time in Playtime Tracking #2993

Open JpTiger opened 4 months ago

JpTiger commented 4 months ago

This is primarily for the Steam Deck: I like how the launcher tracks playing time for our games. Like most launchers though, it doesn't notice when the system is asleep. So, if you:

  1. play a game for thirty minutes,
  2. put the system to sleep while the game is running
  3. leave it that way for 24 hours,
  4. wake the system,
  5. play another half an hour
  6. quit,

the launcher thinks you've been playing the game for 25 hours instead of one.

This isn't common behavior on most PCs but it is very common behavior on a Steam Deck. The Steam Deck handles this for Steam games by noting when the system is asleep and subtracting that time from playtime after the game has been exited. Might something similar be possible for the itch.io app?

3ter commented 4 months ago

You can run the itch.io app on a Steam Deck 😲? I need to read those blog posts more (or get myself a Steam Deck 😜).

I actually searched in the code for how this computation is done but couldn't find it. I mean it seems to be here https://github.com/itchio/butler/blob/50d55e90a90f4d03b5cfc7d35d135b30584c91a7/database/models/cave.go#L86-L89

func (c *Cave) RecordPlayTime(playTime time.Duration) {
        c.SecondsRun += int64(playTime.Seconds())
        c.Touch()
}

but I can't find the receiver RecordPlayTime to be called on a cave instance anywhere. I expected it somewhere not far from launching a game https://github.com/itchio/itch/blob/105041c6dabf596a5f3243c0c732326ee9102eaf/src/main/reactors/launch/perform-launch.ts#L69C1-L75C13

        await mcall(
          messages.Launch,
          {
            caveId: cave.id,
            prereqsDir,
            sandbox: preferences.isolateApps,
          },