Skip to content

Commit

Permalink
Merge pull request #467 from Unpackerr/unstable
Browse files Browse the repository at this point in the history
Fix history bug
  • Loading branch information
davidnewhall authored Jul 19, 2024
2 parents 58e0508 + bfc064e commit a9faab5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 57 deletions.
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]
}
}

0 comments on commit a9faab5

Please sign in to comment.