diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index cc51f5f3..b6d1b882 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -69,6 +69,8 @@ "copied_link_to_clipboard": "Link copied", "hours": "hours", "minutes": "minutes", + "amount_hours": "{{amount}} hours", + "amount_minutes": "{{amount}} minutes", "accuracy": "{{accuracy}}% accuracy", "add_to_library": "Add to library", "remove_from_library": "Remove from library", diff --git a/src/locales/es/translation.json b/src/locales/es/translation.json index e6f114c4..8f36c12f 100644 --- a/src/locales/es/translation.json +++ b/src/locales/es/translation.json @@ -61,6 +61,8 @@ "copied_link_to_clipboard": "Enlace copiado", "hours": "horas", "minutes": "minutos", + "amount_hours": "{{amount}} horas", + "amount_minutes": "{{amount}} minutos", "accuracy": "{{accuracy}}% precisión", "add_to_library": "Agregar a la biblioteca", "remove_from_library": "Eliminar de la biblioteca", diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.json index 3e247b07..2e17f492 100644 --- a/src/locales/fr/translation.json +++ b/src/locales/fr/translation.json @@ -61,6 +61,8 @@ "copied_link_to_clipboard": "Lien copié", "hours": "heures", "minutes": "minutes", + "amount_hours": "{{amount}} heures", + "amount_minutes": "{{amount}} minutes", "accuracy": "{{accuracy}}% précision", "add_to_library": "Ajouter à la bibliothèque", "remove_from_library": "Supprimer de la bibliothèque", diff --git a/src/locales/hu/translation.json b/src/locales/hu/translation.json index 901574a1..2f5dc79b 100644 --- a/src/locales/hu/translation.json +++ b/src/locales/hu/translation.json @@ -66,6 +66,8 @@ "copied_link_to_clipboard": "Link másolva", "hours": "óra", "minutes": "perc", + "amount_hours": "{{amount}} óra", + "amount_minutes": "{{amount}} perc", "accuracy": "{{accuracy}}% pontosság", "add_to_library": "Hozzáadás a könyvtárhoz", "remove_from_library": "Eltávolítás a könyvtárból", diff --git a/src/locales/it/translation.json b/src/locales/it/translation.json index 0cc95e2a..b4ff3723 100644 --- a/src/locales/it/translation.json +++ b/src/locales/it/translation.json @@ -69,6 +69,8 @@ "copied_link_to_clipboard": "Link copiato", "hours": "ore", "minutes": "minuti", + "amount_hours": "{{amount}} ore", + "amount_minutes": "{{amount}} minuti", "accuracy": "{{accuratezza}}% di accuratezza", "add_to_library": "Aggiungi alla libreria", "remove_from_library": "Rimuovi dalla libreria", diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json index a86855d6..fc178889 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -64,6 +64,8 @@ "copied_link_to_clipboard": "Link copiado", "hours": "horas", "minutes": "minutos", + "amount_hours": "{{amount}} horas", + "amount_minutes": "{{amount}} minutos", "accuracy": "{{accuracy}}% de precisão", "add_to_library": "Adicionar à biblioteca", "remove_from_library": "Remover da biblioteca", diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index fc81e8d3..ffed95e9 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -8,20 +8,18 @@ import { WindowManager } from "./window-manager"; const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); export const startProcessWatcher = async () => { - const sleepTime = 300; + const sleepTime = 500; const gamesPlaytime = new Map(); // eslint-disable-next-line no-constant-condition while (true) { - await sleep(sleepTime); - const games = await gameRepository.find({ where: { executablePath: Not(IsNull()), }, }); - if (games.length == 0) { + if (games.length === 0) { continue; } @@ -71,5 +69,7 @@ export const startProcessWatcher = async () => { } } } + + await sleep(sleepTime); } }; diff --git a/src/renderer/src/pages/game-details/hero/hero-panel.tsx b/src/renderer/src/pages/game-details/hero/hero-panel.tsx index f45f8e57..a40c3aa4 100644 --- a/src/renderer/src/pages/game-details/hero/hero-panel.tsx +++ b/src/renderer/src/pages/game-details/hero/hero-panel.tsx @@ -1,5 +1,5 @@ import { format } from "date-fns"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useDownload } from "@renderer/hooks"; @@ -22,6 +22,8 @@ export interface HeroPanelProps { getGame: () => void; } +const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120; + export function HeroPanel({ game, gameDetails, @@ -30,7 +32,7 @@ export function HeroPanel({ getGame, isGamePlaying, }: HeroPanelProps) { - const { t } = useTranslation("game_details"); + const { t, i18n } = useTranslation("game_details"); const [showBinaryNotFoundModal, setShowBinaryNotFoundModal] = useState(false); const [lastTimePlayed, setLastTimePlayed] = useState(""); @@ -48,29 +50,36 @@ export function HeroPanel({ } = useDownload(); const isGameDownloading = isDownloading && gameDownloading?.id === game?.id; - const updateLastTimePlayed = useCallback(() => { - setLastTimePlayed( - formatDistance(game.lastTimePlayed, new Date(), { - addSuffix: true, - }) - ); - }, [game?.lastTimePlayed, formatDistance]); - useEffect(() => { if (game?.lastTimePlayed) { - updateLastTimePlayed(); + setLastTimePlayed( + formatDistance(game.lastTimePlayed, new Date(), { + addSuffix: true, + }) + ); + } + }, [game?.lastTimePlayed, formatDistance]); - const interval = setInterval(() => { - updateLastTimePlayed(); - }, 1000); + const numberFormatter = useMemo(() => { + return new Intl.NumberFormat(i18n.language, { + maximumFractionDigits: 1, + }); + }, [i18n]); - return () => { - clearInterval(interval); - }; + const formatPlayTime = () => { + const milliseconds = game?.playTimeInMilliseconds || 0; + const seconds = milliseconds / 1000; + const minutes = seconds / 60; + + if (minutes < MAX_MINUTES_TO_SHOW_IN_PLAYTIME) { + return t("amount_minutes", { + amount: minutes.toFixed(0), + }); } - return () => {}; - }, [game?.lastTimePlayed, updateLastTimePlayed]); + const hours = minutes / 60; + return t("amount_hours", { amount: numberFormatter.format(hours) }); + }; const finalDownloadSize = useMemo(() => { if (!game) return "N/A"; @@ -139,7 +148,7 @@ export function HeroPanel({ <>

{t("play_time", { - amount: formatDistance(0, game.playTimeInMilliseconds), + amount: formatPlayTime(game.playTimeInMilliseconds), })}