Skip to content

Commit

Permalink
Few usability changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vpoluyaktov committed Nov 25, 2023
1 parent 5d10ad1 commit 99d98bb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
5 changes: 2 additions & 3 deletions internal/controller/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ func (c *BuildController) stopBuild(cmd *dto.StopCommand) {
}

func (c *BuildController) startBuild(cmd *dto.BuildCommand) {
c.startTime = time.Now()
logger.Info(mq.BuildController + " received " + cmd.String())

c.ab = cmd.Audiobook
c.stopFlag = false
c.startTime = time.Now()
c.ab = cmd.Audiobook
c.files = make([]fileBuild, len(c.ab.Parts))

// calculate output file names
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/chapters_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ func (c *ChaptersController) stopChapters(cmd *dto.StopCommand) {
}

func (c *ChaptersController) createChapters(cmd *dto.ChaptersCreate) {

logger.Debug(mq.ChaptersController + " received " + cmd.String())

c.stopFlag = false
c.ab = cmd.Audiobook

if c.ab.Config.IsShortenTitle() {
Expand Down
8 changes: 5 additions & 3 deletions internal/controller/cleanup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func (c *CleanupController) checkMQ() {
func (c *CleanupController) dispatchMessage(m *mq.Message) {
switch dto := m.Dto.(type) {
case *dto.CleanupCommand:
go c.cleanUp(dto)
go c.cleanUp(dto, m.From)
default:
m.UnsupportedTypeError(mq.CleanupController)
}
}

func (c *CleanupController) cleanUp(cmd *dto.CleanupCommand) {
func (c *CleanupController) cleanUp(cmd *dto.CleanupCommand, requestor string) {
logger.Info(mq.CleanupController + " received " + cmd.String())
c.ab = cmd.Audiobook

Expand All @@ -53,5 +53,7 @@ func (c *CleanupController) cleanUp(cmd *dto.CleanupCommand) {
}
os.Remove(c.ab.CoverFile)

c.mq.SendMessage(mq.CleanupController, mq.BuildPage, &dto.CleanupComplete{Audiobook: cmd.Audiobook}, true)
if requestor == mq.BuildPage {
c.mq.SendMessage(mq.CleanupController, mq.BuildPage, &dto.CleanupComplete{Audiobook: cmd.Audiobook}, true)
}
}
4 changes: 4 additions & 0 deletions internal/ui/build_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type BuildPage struct {
uploadTable *table
progressTable *table
progressSection *tview.Grid
ab *dto.Audiobook
}

func newBuildPage(dispatcher *mq.Dispatcher) *BuildPage {
Expand Down Expand Up @@ -157,6 +158,8 @@ func (p *BuildPage) dispatchMessage(m *mq.Message) {

func (p *BuildPage) displayBookInfo(ab *dto.Audiobook) {

p.ab = ab

// dynamic grid layout generation
p.grid.Clear()
p.grid.SetColumns(0)
Expand Down Expand Up @@ -220,6 +223,7 @@ func (p *BuildPage) stopConfirmation() {
func (p *BuildPage) stopBuild() {
// Stop the build here
p.mq.SendMessage(mq.BuildPage, mq.BuildController, &dto.StopCommand{Process: "Build", Reason: "User request"}, false)
p.mq.SendMessage(mq.ChaptersPage, mq.CleanupController, &dto.CleanupCommand{Audiobook: p.ab}, true)
p.switchToSearch()
}

Expand Down
13 changes: 11 additions & 2 deletions internal/ui/chapters_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,20 @@ func (p *ChaptersPage) stopConfirmation() {
}

func (p *ChaptersPage) stopChapters() {
p.mq.SendMessage(mq.ChaptersPage, mq.ChaptersController, &dto.StopCommand{Process: "Chapters", Reason: "User request"}, true)
p.mq.SendMessage(mq.ChaptersPage, mq.Frame, &dto.SwitchToPageCommand{Name: "SearchPage"}, true)
p.mq.SendMessage(mq.ChaptersPage, mq.ChaptersController, &dto.StopCommand{Process: "Chapters", Reason: "User request"}, false)
p.mq.SendMessage(mq.ChaptersPage, mq.CleanupController, &dto.CleanupCommand{Audiobook: p.ab}, true)
p.mq.SendMessage(mq.ChaptersPage, mq.Frame, &dto.SwitchToPageCommand{Name: "SearchPage"}, false)
}

func (p *ChaptersPage) buildBook() {
// update ab fields just to ensure (they are not updated automatically if a value wasn't change)
p.ab.Author = p.author.GetText()
p.ab.Title = p.title.GetText()
p.ab.Series = p.series.GetText()
p.ab.SeriesNo = p.seriesNo.GetText()
p.ab.Narator = p.narator.GetText()
_, p.ab.Genre = p.genre.GetCurrentOption()

p.mq.SendMessage(mq.ChaptersPage, mq.BuildController, &dto.BuildCommand{Audiobook: p.ab}, true)
p.mq.SendMessage(mq.ChaptersPage, mq.Frame, &dto.SwitchToPageCommand{Name: "BuildPage"}, true)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/ui/download_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DownloadPage struct {
filesSection *tview.Grid
filesTable *table
progressTable *table
ab *dto.Audiobook
}

func newDownloadPage(dispatcher *mq.Dispatcher) *DownloadPage {
Expand Down Expand Up @@ -107,6 +108,7 @@ func (p *DownloadPage) dispatchMessage(m *mq.Message) {
}

func (p *DownloadPage) displayBookInfo(ab *dto.Audiobook) {
p.ab = ab
p.infoPanel.clear()
// p.infoPanel.appendRow("", "")
p.infoPanel.appendRow("Title:", ab.Title)
Expand All @@ -131,6 +133,7 @@ func (p *DownloadPage) stopConfirmation() {

func (p *DownloadPage) stopDownload() {
p.mq.SendMessage(mq.DownloadPage, mq.DownloadController, &dto.StopCommand{Process: "Download", Reason: "User request"}, false)
p.mq.SendMessage(mq.DownloadPage, mq.CleanupController, &dto.CleanupCommand{Audiobook: p.ab}, true)
p.mq.SendMessage(mq.DownloadPage, mq.Frame, &dto.SwitchToPageCommand{Name: "SearchPage"}, false)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/ui/encoding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type EncodingPage struct {
filesSection *tview.Grid
filesTable *table
progressTable *table
ab *dto.Audiobook
}

func newEncodingPage(dispatcher *mq.Dispatcher) *EncodingPage {
Expand Down Expand Up @@ -80,7 +81,6 @@ func newEncodingPage(dispatcher *mq.Dispatcher) *EncodingPage {
p.progressTable.t.SetSelectable(false, false)
progressSection.AddItem(p.progressTable.t, 0, 0, 1, 1, 0, 0, false)
p.grid.AddItem(progressSection, 2, 0, 1, 1, 0, 0, false)

return p
}

Expand All @@ -107,6 +107,7 @@ func (p *EncodingPage) dispatchMessage(m *mq.Message) {
}

func (p *EncodingPage) displayBookInfo(ab *dto.Audiobook) {
p.ab = ab
p.infoPanel.clear()
// p.infoPanel.appendRow("", "")
p.infoPanel.appendRow("Title:", ab.Title)
Expand All @@ -131,6 +132,7 @@ func (p *EncodingPage) stopConfirmation() {

func (p *EncodingPage) stopEncoding() {
p.mq.SendMessage(mq.EncodingPage, mq.EncodingController, &dto.StopCommand{Process: "Encoding", Reason: "User request"}, true)
p.mq.SendMessage(mq.EncodingPage, mq.CleanupController, &dto.CleanupCommand{Audiobook: p.ab}, true)
p.mq.SendMessage(mq.EncodingPage, mq.Frame, &dto.SwitchToPageCommand{Name: "SearchPage"}, true)
}

Expand Down

0 comments on commit 99d98bb

Please sign in to comment.