Skip to content

Commit da532a9

Browse files
committed
Add x-button for cancel job
1 parent f511b3c commit da532a9

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/net/DownloadManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void DownloadManager::run(const std::string& zipUrl,
172172
// Download with retry
173173
bool downloaded = false;
174174
for (int attempt = 1; attempt <= maxRetries + 1; attempt++) {
175+
if (m_cancelFlag && m_cancelFlag->load()) break;
175176
m_progress = 0.0f;
176177
LOG_INFO("DownloadManager: attempt %d/%d: %s", attempt, maxRetries+1, zipUrl.c_str());
177178
if (download(zipUrl, tmpPath)) { downloaded = true; break; }

src/ui/DownloadQueueScreen.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ void DownloadQueueScreen::handleInput(const Input& input) {
3535
return;
3636
}
3737

38+
if (input.x && !jobs.empty() && m_selectedIdx < (int)jobs.size()) {
39+
auto state = jobs[m_selectedIdx].state;
40+
if (state == DownloadJob::State::Pending ||
41+
state == DownloadJob::State::Downloading) {
42+
DownloadQueue::get().cancelJob(m_selectedIdx);
43+
}
44+
}
45+
3846
if (input.up) m_selectedIdx = std::max(0, m_selectedIdx - 1);
3947
if (input.down) m_selectedIdx = std::min((int)jobs.size() - 1, m_selectedIdx + 1);
4048
}
@@ -124,10 +132,17 @@ void DownloadQueueScreen::render(SDL_Renderer* renderer) {
124132

125133
// Bottom hint
126134
if (m_fontSmall) {
127-
bool errorSelected = !jobs.empty() && m_selectedIdx < (int)jobs.size() &&
128-
jobs[m_selectedIdx].state == DownloadJob::State::Error;
129-
std::string hint = errorSelected ? "B: Dismiss error Up/Down: navigate" : "B: Back Up/Down: navigate";
130-
renderText(renderer, hint, W/2 - 160, H - 35, grey, m_fontSmall);
135+
std::string hint = "B: Back Up/Down: navigate";
136+
if (!jobs.empty() && m_selectedIdx < (int)jobs.size()) {
137+
auto selState = jobs[m_selectedIdx].state;
138+
if (selState == DownloadJob::State::Error) {
139+
hint = "B: Dismiss error Up/Down: navigate";
140+
} else if (selState == DownloadJob::State::Pending ||
141+
selState == DownloadJob::State::Downloading) {
142+
hint = "X: Cancel B: Back Up/Down: navigate";
143+
}
144+
}
145+
renderText(renderer, hint, W/2 - 180, H - 35, grey, m_fontSmall);
131146
}
132147
}
133148

0 commit comments

Comments
 (0)