feat: add option to show download speed in megabits

This commit is contained in:
Hachi-R
2025-04-12 14:23:02 -03:00
parent ee1dda90d9
commit 75c3bbf858
6 changed files with 34 additions and 4 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -15,12 +15,14 @@ import type {
StartGameDownloadPayload,
} from "@types";
import { useDate } from "./use-date";
import { formatBytes } 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: `${formatBytes(lastPacket?.downloadSpeed ?? 0)}/s`,
downloadSpeed: formatDownloadSpeed(lastPacket?.downloadSpeed ?? 0),
progress: formatDownloadProgress(lastPacket?.progress ?? 0),
lastPacket,
eta: calculateETA(),

View File

@@ -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() {
})
}
/>
<CheckboxField
label={t("show_download_speed_in_megabits")}
checked={form.showDownloadSpeedInMegabits}
onChange={() =>
handleChange({
showDownloadSpeedInMegabits: !form.showDownloadSpeedInMegabits,
})
}
/>
</>
);
}

View File

@@ -49,6 +49,12 @@ export const formatBytes = (bytes: number): string => {
return `${Math.trunc(formatedByte * 10) / 10} ${FORMAT[base]}`;
};
export const formatBytesToMbps = (bytesPerSecond: number): string => {
const bitsPerSecond = bytesPerSecond * 8;
const mbps = bitsPerSecond / (1024 * 1024);
return `${Math.trunc(mbps * 10) / 10} Mbps`;
};
export const pipe =
<T>(...fns: ((arg: T) => any)[]) =>
(arg: T) =>

View File

@@ -85,6 +85,7 @@ export interface UserPreferences {
repackUpdatesNotificationsEnabled?: boolean;
achievementNotificationsEnabled?: boolean;
friendRequestNotificationsEnabled?: boolean;
showDownloadSpeedInMegabits?: boolean;
}
export interface ScreenState {