mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-31 06:41:03 +00:00
refactor: streamline download preparation and status handling in DownloadManager
This commit is contained in:
@@ -31,11 +31,16 @@ export const downloadSlice = createSlice({
|
||||
reducers: {
|
||||
setLastPacket: (state, action: PayloadAction<DownloadProgress | null>) => {
|
||||
state.lastPacket = action.payload;
|
||||
if (!state.gameId && action.payload) state.gameId = action.payload.gameId;
|
||||
|
||||
// Ensure payload exists and has a valid gameId before accessing
|
||||
const payload = action.payload;
|
||||
if (!state.gameId && payload?.gameId) {
|
||||
state.gameId = payload.gameId;
|
||||
}
|
||||
|
||||
// Track peak speed and speed history atomically when packet arrives
|
||||
if (action.payload?.gameId && action.payload.downloadSpeed != null) {
|
||||
const { gameId, downloadSpeed } = action.payload;
|
||||
if (payload?.gameId && payload.downloadSpeed != null) {
|
||||
const { gameId, downloadSpeed } = payload;
|
||||
|
||||
// Update peak speed if this is higher
|
||||
const currentPeak = state.peakSpeeds[gameId] || 0;
|
||||
|
||||
@@ -613,11 +613,18 @@ export function DownloadGroup({
|
||||
const download = game.download!;
|
||||
const isGameDownloading = isGameDownloadingMap[game.id];
|
||||
|
||||
if (download.fileSize != null) return formatBytes(download.fileSize);
|
||||
|
||||
if (lastPacket?.download.fileSize && isGameDownloading)
|
||||
// Check lastPacket first for most up-to-date size during active downloads
|
||||
if (
|
||||
isGameDownloading &&
|
||||
lastPacket?.download.fileSize &&
|
||||
lastPacket.download.fileSize > 0
|
||||
)
|
||||
return formatBytes(lastPacket.download.fileSize);
|
||||
|
||||
// Then check the stored download size (must be > 0 to be valid)
|
||||
if (download.fileSize != null && download.fileSize > 0)
|
||||
return formatBytes(download.fileSize);
|
||||
|
||||
return "N/A";
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user