| 
18 | 18 | use GuzzleHttp\Exception\GuzzleException;  | 
19 | 19 | use Illuminate\Console\OutputStyle;  | 
20 | 20 | use Illuminate\Support\Traits\Macroable;  | 
21 |  | -use Symfony\Component\Console\Helper\ProgressBar;  | 
 | 21 | +use Laravel\Prompts\Progress;  | 
 | 22 | + | 
 | 23 | +use function Laravel\Prompts\progress;  | 
22 | 24 | 
 
  | 
23 | 25 | class SequenceMusic implements \App\Contracts\HttpClientFactory, Music  | 
24 | 26 | {  | 
@@ -65,17 +67,24 @@ public function download(string $url, string $savePath): void  | 
65 | 67 |     {  | 
66 | 68 |         $this->createHttpClient()->get($url, [  | 
67 | 69 |             'sink' => $savePath,  | 
68 |  | -            'progress' => function (int $totalDownload, int $downloaded) use (&$progressBar): void {  | 
69 |  | -                if ($totalDownload > 0 && $downloaded > 0 && ! $progressBar instanceof ProgressBar) {  | 
70 |  | -                    $progressBar = new ProgressBar($this->output, $totalDownload);  | 
71 |  | -                    $progressBar->start();  | 
 | 70 | +            'progress' => function (int $totalDownload, int $downloaded) use (&$progress, $savePath): void {  | 
 | 71 | +                if (0 === $totalDownload || 0 === $downloaded) {  | 
 | 72 | +                    return;  | 
 | 73 | +                }  | 
 | 74 | + | 
 | 75 | +                if (! $progress instanceof Progress) {  | 
 | 76 | +                    $progress = progress($savePath, $totalDownload);  | 
 | 77 | +                    $progress->start();  | 
72 | 78 |                 }  | 
73 | 79 | 
 
  | 
74 |  | -                if ($totalDownload === $downloaded && $progressBar instanceof ProgressBar) {  | 
75 |  | -                    $progressBar->finish();  | 
 | 80 | +                if ($totalDownload !== $downloaded) {  | 
 | 81 | +                    $progress->progress = $downloaded;  | 
 | 82 | +                    $progress->advance(0);  | 
76 | 83 |                 }  | 
77 | 84 | 
 
  | 
78 |  | -                $progressBar and $progressBar->setProgress($downloaded);  | 
 | 85 | +                if ($totalDownload === $downloaded && 'submit' !== $progress->state) {  | 
 | 86 | +                    $progress->finish();  | 
 | 87 | +                }  | 
79 | 88 |             },  | 
80 | 89 |         ]);  | 
81 | 90 |     }  | 
 | 
0 commit comments