From 5b62b9c593c5ddf11e81674e6509180b0b159b31 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Fri, 11 Apr 2025 17:09:33 -0300 Subject: [PATCH] feat: add option to show download speed in megabits --- src/locales/en/translation.json | 3 ++- src/locales/pt-BR/translation.json | 3 ++- src/renderer/src/hooks/use-download.ts | 12 ++++++++++-- .../src/pages/settings/settings-behavior.tsx | 13 +++++++++++++ src/types/level.types.ts | 1 + 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index d6a1f687..57a43435 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -354,7 +354,8 @@ "common_redist": "Common redistributables", "common_redist_description": "Common redistributables are required to run some games. Installing them is recommended to avoid issues.", "install_common_redist": "Install", - "installing_common_redist": "Installing…" + "installing_common_redist": "Installing…", + "show_download_speed_in_megabits": "Show download speed in megabits per second" }, "notifications": { "download_complete": "Download complete", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 5f2b62cc..4f27bcf9 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -341,7 +341,8 @@ "common_redist": "Componentes recomendados", "common_redist_description": "Componentes recomendados são necessários para executar alguns jogos. A instalação deles é recomendada para evitar problemas.", "install_common_redist": "Instalar", - "installing_common_redist": "Instalando…" + "installing_common_redist": "Instalando…", + "show_download_speed_in_megabits": "Exibir taxas de download em megabits por segundo" }, "notifications": { "download_complete": "Download concluído", diff --git a/src/renderer/src/hooks/use-download.ts b/src/renderer/src/hooks/use-download.ts index 73efec9a..a3b655d1 100644 --- a/src/renderer/src/hooks/use-download.ts +++ b/src/renderer/src/hooks/use-download.ts @@ -15,12 +15,14 @@ import type { StartGameDownloadPayload, } from "@types"; import { useDate } from "./use-date"; -import { formatBytesToMbps } from "@shared"; +import { formatBytes, formatBytesToMbps } from "@shared"; export function useDownload() { const { updateLibrary } = useLibrary(); const { formatDistance } = useDate(); + const userPrefs = useAppSelector((state) => state.userPreferences.value); + const { lastPacket, gamesWithDeletionInProgress } = useAppSelector( (state) => state.download ); @@ -99,8 +101,14 @@ export function useDownload() { return gamesWithDeletionInProgress.includes(objectId); }; + const formatDownloadSpeed = (downloadSpeed: number): string => { + return userPrefs?.showDownloadSpeedInMegabits + ? `${formatBytes(downloadSpeed)}/s` + : formatBytesToMbps(downloadSpeed); + }; + return { - downloadSpeed: formatBytesToMbps(lastPacket?.downloadSpeed ?? 0), + downloadSpeed: formatDownloadSpeed(lastPacket?.downloadSpeed ?? 0), progress: formatDownloadProgress(lastPacket?.progress ?? 0), lastPacket, eta: calculateETA(), diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index 54b1a3c8..230bd065 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -23,6 +23,7 @@ export function SettingsBehavior() { enableAutoInstall: false, seedAfterDownloadComplete: false, showHiddenAchievementsDescription: false, + showDownloadSpeedInMegabits: false, }); const { t } = useTranslation("settings"); @@ -40,6 +41,8 @@ export function SettingsBehavior() { userPreferences.seedAfterDownloadComplete ?? false, showHiddenAchievementsDescription: userPreferences.showHiddenAchievementsDescription ?? false, + showDownloadSpeedInMegabits: + userPreferences.showDownloadSpeedInMegabits ?? false, }); } }, [userPreferences]); @@ -139,6 +142,16 @@ export function SettingsBehavior() { }) } /> + + + handleChange({ + showDownloadSpeedInMegabits: !form.showDownloadSpeedInMegabits, + }) + } + /> ); } diff --git a/src/types/level.types.ts b/src/types/level.types.ts index f98842a2..1187d562 100644 --- a/src/types/level.types.ts +++ b/src/types/level.types.ts @@ -81,6 +81,7 @@ export interface UserPreferences { enableAutoInstall?: boolean; seedAfterDownloadComplete?: boolean; showHiddenAchievementsDescription?: boolean; + showDownloadSpeedInMegabits?: boolean; downloadNotificationsEnabled?: boolean; repackUpdatesNotificationsEnabled?: boolean; achievementNotificationsEnabled?: boolean;