Skip to content

Commit

Permalink
feat: detect if I am in a certain steam game
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Nov 19, 2024
1 parent 5e5eada commit 4140534
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/apis/steam/games.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type game struct {
LibraryHeroLogoURL string `json:"library_hero_logo_url"`
AchievementProgress *float32 `json:"achievement_progress"`
Achievements *[]achievement `json:"achievements"`
InGame bool `json:"in_game"`
}

func fetchRecentlyPlayedGames() ([]game, error) {
Expand Down Expand Up @@ -107,6 +108,7 @@ func fetchRecentlyPlayedGames() ([]game, error) {

achievementPercentage, achievements := fetchGameAchievements(g.AppID)

lastPlaytime := time.Unix(g.RTimeLastPlayed, 0)
games = append(games, game{
Name: g.Name,
AppID: g.AppID,
Expand All @@ -115,7 +117,7 @@ func fetchRecentlyPlayedGames() ([]game, error) {
g.AppID,
g.ImgIconURL,
),
RTimeLastPlayed: time.Unix(g.RTimeLastPlayed, 0),
RTimeLastPlayed: lastPlaytime,
PlaytimeForever: g.PlaytimeForever,
URL: fmt.Sprintf("https://store.steampowered.com/app/%d/", g.AppID),
HeaderURL: fmt.Sprintf(
Expand All @@ -133,6 +135,9 @@ func fetchRecentlyPlayedGames() ([]game, error) {
),
AchievementProgress: achievementPercentage,
Achievements: achievements,
InGame: time.Now().
Unix()-
lastPlaytime.Unix() > 10, // game was playing in the last 10 seconds
})

}
Expand Down

0 comments on commit 4140534

Please sign in to comment.