Skip to content

Commit a90bde5

Browse files
committed
refactor(SequenceMusic): Remove unused imports and update progress handling
- Remove unused imports in SequenceMusic.php - Update progress handling in the 'progress' callback function
1 parent 072c7a7 commit a90bde5

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

app/Music/SequenceMusic.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
use GuzzleHttp\Exception\GuzzleException;
1919
use Illuminate\Console\OutputStyle;
2020
use Illuminate\Support\Traits\Macroable;
21-
use Symfony\Component\Console\Helper\ProgressBar;
21+
use Laravel\Prompts\Progress;
22+
23+
use function Laravel\Prompts\progress;
2224

2325
class SequenceMusic implements \App\Contracts\HttpClientFactory, Music
2426
{
@@ -65,17 +67,24 @@ public function download(string $url, string $savePath): void
6567
{
6668
$this->createHttpClient()->get($url, [
6769
'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();
7278
}
7379

74-
if ($totalDownload === $downloaded && $progressBar instanceof ProgressBar) {
75-
$progressBar->finish();
80+
if ($totalDownload !== $downloaded) {
81+
$progress->progress = $downloaded;
82+
$progress->advance(0);
7683
}
7784

78-
$progressBar and $progressBar->setProgress($downloaded);
85+
if ($totalDownload === $downloaded && 'submit' !== $progress->state) {
86+
$progress->finish();
87+
}
7988
},
8089
]);
8190
}

0 commit comments

Comments
 (0)