Skip to content

Commit

Permalink
feat(dl): enable auto-quit (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamjz authored Dec 23, 2023
1 parent 83b4c6b commit 76e6c9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ func download(aniURL string, cfg *Config) error {
group.Go(dl(ani, m))
}

if _, err := p.Run(); err != nil {
log.Errorf("Start progress bar %v", err)
}
go func() {
if err := group.Wait(); err != nil {
p.Send(progressbar.ProgressErrMsg{Err: err})
return
}
p.Send(progressbar.ProgressSuccessMsg{})
}()

_, err = p.Run()

return group.Wait() //nolint:wrapcheck
return err //nolint:wrapcheck
}

func init() {
Expand Down
5 changes: 5 additions & 0 deletions internal/tui/progressbar/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type ProgressMsg struct {
Ratio float64
}

type ProgressSuccessMsg struct{}

type ProgressErrMsg struct{ Err error }

type ProgressStatusMsg struct {
Expand All @@ -38,6 +40,9 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:cyclop
m.width = w
return m, nil

case ProgressSuccessMsg:
return m, tea.Quit

case ProgressErrMsg:
m.err = msg.Err
return m, tea.Quit
Expand Down

0 comments on commit 76e6c9b

Please sign in to comment.