From 364f534a62a11f1335ce753aff71230872a6c714 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 18 Jul 2024 10:43:54 -0700 Subject: [PATCH 1/3] Fix history bug --- pkg/unpackerr/history.go | 48 +++++++++++++++++++++++++++++++++++++ pkg/unpackerr/start.go | 8 ------- pkg/unpackerr/tray.go | 37 ---------------------------- pkg/unpackerr/tray_other.go | 12 ---------- 4 files changed, 48 insertions(+), 57 deletions(-) create mode 100644 pkg/unpackerr/history.go diff --git a/pkg/unpackerr/history.go b/pkg/unpackerr/history.go new file mode 100644 index 0000000..23ee31f --- /dev/null +++ b/pkg/unpackerr/history.go @@ -0,0 +1,48 @@ +package unpackerr + +import ( + "strconv" + + "github.com/Unpackerr/unpackerr/pkg/ui" +) + +// Safety constants. +const ( + hist = "hist_" + histNone = "hist_none" +) + +// History holds the history of extracted items. +type History struct { + Items []string + Finished uint + Retries uint + Map map[string]*Extract +} + +// This is called every time an item is queued. +func (u *Unpackerr) updateHistory(item string) { + if u.KeepHistory == 0 { + return + } + + if ui.HasGUI() && item != "" { + u.menu[histNone].Hide() + } + + u.History.Items[0] = item + + //nolint:intrange // Do not process 0; this isn't an `intrange`. + for idx := len(u.History.Items) - 1; idx > 0; idx-- { + // u.History.Items is a slice with a set (identical) length and capacity. + switch u.History.Items[idx] = u.History.Items[idx-1]; { + case !ui.HasGUI(): + continue + case u.History.Items[idx] != "": + u.menu[hist+starr.Itoa(idx)].SetTitle(u.History.Items[idx]) + u.menu[hist+strconv.Itoa(idx)].Show() + default: + u.menu[hist+strconv.Itoa(idx)].Hide() + } + } +} diff --git a/pkg/unpackerr/start.go b/pkg/unpackerr/start.go index abfb01e..9748f87 100644 --- a/pkg/unpackerr/start.go +++ b/pkg/unpackerr/start.go @@ -85,14 +85,6 @@ type Flags struct { webhook uint } -// History holds the history of extracted items. -type History struct { - Items []string - Finished uint - Retries uint - Map map[string]*Extract -} - // New returns an UnpackerPoller struct full of defaults. // An empty struct will surely cause you pain, so use this! func New() *Unpackerr { diff --git a/pkg/unpackerr/tray.go b/pkg/unpackerr/tray.go index 5997ae9..1bc46e1 100644 --- a/pkg/unpackerr/tray.go +++ b/pkg/unpackerr/tray.go @@ -18,12 +18,6 @@ import ( "golift.io/version" ) -// Safety constants. -const ( - hist = "hist_" - histNone = "hist_none" -) - // startTray Run()s readyTray to bring up the web server and the GUI app. func (u *Unpackerr) startTray() { if !ui.HasGUI() { @@ -254,34 +248,3 @@ func (u *Unpackerr) checkForUpdate() { _ = ui.OpenURL(update.CurrURL) } } - -// This is called every time an item is queued. -func (u *Unpackerr) updateHistory(item string) { - if u.KeepHistory == 0 { - return - } - - if ui.HasGUI() && item != "" { - u.menu[histNone].Hide() - } - - // u.History.Items is a slice with a set (identical) length and capacity. - for idx := range u.History.Items { - if idx == 0 { - u.History.Items[0] = item - } else { - u.History.Items[idx] = u.History.Items[idx-1] - } - - if !ui.HasGUI() { - continue - } - - if u.History.Items[idx] != "" { - u.menu[hist+strconv.Itoa(idx)].SetTitle(u.History.Items[idx]) - u.menu[hist+strconv.Itoa(idx)].Show() - } else { - u.menu[hist+strconv.Itoa(idx)].Hide() - } - } -} diff --git a/pkg/unpackerr/tray_other.go b/pkg/unpackerr/tray_other.go index 5e16642..2f1e063 100644 --- a/pkg/unpackerr/tray_other.go +++ b/pkg/unpackerr/tray_other.go @@ -18,15 +18,3 @@ func (u *Unpackerr) startTray() { func (u *Unpackerr) updateTray(_ *Stats, _ uint) { // there is no tray. } - -func (u *Unpackerr) updateHistory(item string) { - if u.KeepHistory == 0 { - return - } - - u.History.Items[0] = item - // u.History.Items is a slice with a set (identical) length and capacity. - for idx := range u.History.Items { - u.History.Items[idx] = u.History.Items[idx-1] - } -} From 9c284dbe60cb501cc2c1629e7948b5f771907489 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 18 Jul 2024 10:47:13 -0700 Subject: [PATCH 2/3] oops --- pkg/unpackerr/history.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/unpackerr/history.go b/pkg/unpackerr/history.go index 23ee31f..690d4b7 100644 --- a/pkg/unpackerr/history.go +++ b/pkg/unpackerr/history.go @@ -39,7 +39,7 @@ func (u *Unpackerr) updateHistory(item string) { case !ui.HasGUI(): continue case u.History.Items[idx] != "": - u.menu[hist+starr.Itoa(idx)].SetTitle(u.History.Items[idx]) + u.menu[hist+strconv.Itoa(idx)].SetTitle(u.History.Items[idx]) u.menu[hist+strconv.Itoa(idx)].Show() default: u.menu[hist+strconv.Itoa(idx)].Hide() From bfc064ee52cc3f164910ca44a6afffeabc58f055 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 18 Jul 2024 10:47:38 -0700 Subject: [PATCH 3/3] oops --- pkg/unpackerr/history.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/unpackerr/history.go b/pkg/unpackerr/history.go index 690d4b7..0d7c8f1 100644 --- a/pkg/unpackerr/history.go +++ b/pkg/unpackerr/history.go @@ -32,7 +32,7 @@ func (u *Unpackerr) updateHistory(item string) { u.History.Items[0] = item - //nolint:intrange // Do not process 0; this isn't an `intrange`. + // Do not process 0; this isn't an `intrange`. for idx := len(u.History.Items) - 1; idx > 0; idx-- { // u.History.Items is a slice with a set (identical) length and capacity. switch u.History.Items[idx] = u.History.Items[idx-1]; {