Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix history bug #467

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions pkg/unpackerr/history.go
Original file line number Diff line number Diff line change
@@ -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

// 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+strconv.Itoa(idx)].SetTitle(u.History.Items[idx])
u.menu[hist+strconv.Itoa(idx)].Show()
default:
u.menu[hist+strconv.Itoa(idx)].Hide()
}
}
}
8 changes: 0 additions & 8 deletions pkg/unpackerr/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 0 additions & 37 deletions pkg/unpackerr/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
}
}
}
12 changes: 0 additions & 12 deletions pkg/unpackerr/tray_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}