Fix a UI bug that shows "resume download" button on download manager even when the downloading process is not paused

This commit is contained in:
Alex Ling 2020-04-01 23:21:32 +00:00
parent 58e96cd4fe
commit 5400c8c8ef

View File

@ -249,6 +249,7 @@ module MangaDex
class Downloader class Downloader
property stopped = false property stopped = false
@downloading = false
def initialize(@queue : Queue, @api : API, @library_path : String, def initialize(@queue : Queue, @api : API, @library_path : String,
@wait_seconds : Int32, @retries : Int32, @wait_seconds : Int32, @retries : Int32,
@ -258,7 +259,7 @@ module MangaDex
spawn do spawn do
loop do loop do
sleep 1.second sleep 1.second
next if @stopped next if @stopped || @downloading
begin begin
job = @queue.pop job = @queue.pop
next if job.nil? next if job.nil?
@ -271,7 +272,7 @@ module MangaDex
end end
private def download(job : Job) private def download(job : Job)
@stopped = true @downloading = true
@queue.set_status JobStatus::Downloading, job @queue.set_status JobStatus::Downloading, job
begin begin
chapter = @api.get_chapter(job.id) chapter = @api.get_chapter(job.id)
@ -281,7 +282,7 @@ module MangaDex
unless e.message.nil? unless e.message.nil?
@queue.add_message e.message.not_nil!, job @queue.add_message e.message.not_nil!, job
end end
@stopped = false @downloading = false
return return
end end
@queue.set_pages chapter.pages.size, job @queue.set_pages chapter.pages.size, job
@ -346,7 +347,7 @@ module MangaDex
else else
@queue.set_status JobStatus::MissingPages, job @queue.set_status JobStatus::MissingPages, job
end end
@stopped = false @downloading = false
end end
end end