From 99d98bbf5b6cfc5f1836b6f8083051b31c9f821f Mon Sep 17 00:00:00 2001 From: vpoluyaktov Date: Fri, 24 Nov 2023 16:44:00 -0800 Subject: [PATCH] Few usability changes --- internal/controller/build_controller.go | 5 ++--- internal/controller/chapters_controller.go | 3 +-- internal/controller/cleanup_controller.go | 8 +++++--- internal/ui/build_page.go | 4 ++++ internal/ui/chapters_page.go | 13 +++++++++++-- internal/ui/download_page.go | 3 +++ internal/ui/encoding_page.go | 4 +++- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/internal/controller/build_controller.go b/internal/controller/build_controller.go index b92b142..3b91bfb 100644 --- a/internal/controller/build_controller.go +++ b/internal/controller/build_controller.go @@ -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 diff --git a/internal/controller/chapters_controller.go b/internal/controller/chapters_controller.go index 0ab1a38..c076ee5 100644 --- a/internal/controller/chapters_controller.go +++ b/internal/controller/chapters_controller.go @@ -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() { diff --git a/internal/controller/cleanup_controller.go b/internal/controller/cleanup_controller.go index 81b29ab..81a129b 100644 --- a/internal/controller/cleanup_controller.go +++ b/internal/controller/cleanup_controller.go @@ -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 @@ -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) + } } diff --git a/internal/ui/build_page.go b/internal/ui/build_page.go index a347798..5869608 100644 --- a/internal/ui/build_page.go +++ b/internal/ui/build_page.go @@ -27,6 +27,7 @@ type BuildPage struct { uploadTable *table progressTable *table progressSection *tview.Grid + ab *dto.Audiobook } func newBuildPage(dispatcher *mq.Dispatcher) *BuildPage { @@ -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) @@ -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() } diff --git a/internal/ui/chapters_page.go b/internal/ui/chapters_page.go index 0913ac6..f0336a6 100644 --- a/internal/ui/chapters_page.go +++ b/internal/ui/chapters_page.go @@ -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) } diff --git a/internal/ui/download_page.go b/internal/ui/download_page.go index ae5b18c..8a94fa0 100644 --- a/internal/ui/download_page.go +++ b/internal/ui/download_page.go @@ -19,6 +19,7 @@ type DownloadPage struct { filesSection *tview.Grid filesTable *table progressTable *table + ab *dto.Audiobook } func newDownloadPage(dispatcher *mq.Dispatcher) *DownloadPage { @@ -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) @@ -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) } diff --git a/internal/ui/encoding_page.go b/internal/ui/encoding_page.go index 7db2673..ee5452c 100644 --- a/internal/ui/encoding_page.go +++ b/internal/ui/encoding_page.go @@ -19,6 +19,7 @@ type EncodingPage struct { filesSection *tview.Grid filesTable *table progressTable *table + ab *dto.Audiobook } func newEncodingPage(dispatcher *mq.Dispatcher) *EncodingPage { @@ -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 } @@ -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) @@ -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) }