Skip to content

Commit a9faab5

Browse files
authored
Merge pull request #467 from Unpackerr/unstable
Fix history bug
2 parents 58e0508 + bfc064e commit a9faab5

4 files changed

Lines changed: 48 additions & 57 deletions

File tree

pkg/unpackerr/history.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package unpackerr
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/Unpackerr/unpackerr/pkg/ui"
7+
)
8+
9+
// Safety constants.
10+
const (
11+
hist = "hist_"
12+
histNone = "hist_none"
13+
)
14+
15+
// History holds the history of extracted items.
16+
type History struct {
17+
Items []string
18+
Finished uint
19+
Retries uint
20+
Map map[string]*Extract
21+
}
22+
23+
// This is called every time an item is queued.
24+
func (u *Unpackerr) updateHistory(item string) {
25+
if u.KeepHistory == 0 {
26+
return
27+
}
28+
29+
if ui.HasGUI() && item != "" {
30+
u.menu[histNone].Hide()
31+
}
32+
33+
u.History.Items[0] = item
34+
35+
// Do not process 0; this isn't an `intrange`.
36+
for idx := len(u.History.Items) - 1; idx > 0; idx-- {
37+
// u.History.Items is a slice with a set (identical) length and capacity.
38+
switch u.History.Items[idx] = u.History.Items[idx-1]; {
39+
case !ui.HasGUI():
40+
continue
41+
case u.History.Items[idx] != "":
42+
u.menu[hist+strconv.Itoa(idx)].SetTitle(u.History.Items[idx])
43+
u.menu[hist+strconv.Itoa(idx)].Show()
44+
default:
45+
u.menu[hist+strconv.Itoa(idx)].Hide()
46+
}
47+
}
48+
}

pkg/unpackerr/start.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ type Flags struct {
8585
webhook uint
8686
}
8787

88-
// History holds the history of extracted items.
89-
type History struct {
90-
Items []string
91-
Finished uint
92-
Retries uint
93-
Map map[string]*Extract
94-
}
95-
9688
// New returns an UnpackerPoller struct full of defaults.
9789
// An empty struct will surely cause you pain, so use this!
9890
func New() *Unpackerr {

pkg/unpackerr/tray.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ import (
1818
"golift.io/version"
1919
)
2020

21-
// Safety constants.
22-
const (
23-
hist = "hist_"
24-
histNone = "hist_none"
25-
)
26-
2721
// startTray Run()s readyTray to bring up the web server and the GUI app.
2822
func (u *Unpackerr) startTray() {
2923
if !ui.HasGUI() {
@@ -254,34 +248,3 @@ func (u *Unpackerr) checkForUpdate() {
254248
_ = ui.OpenURL(update.CurrURL)
255249
}
256250
}
257-
258-
// This is called every time an item is queued.
259-
func (u *Unpackerr) updateHistory(item string) {
260-
if u.KeepHistory == 0 {
261-
return
262-
}
263-
264-
if ui.HasGUI() && item != "" {
265-
u.menu[histNone].Hide()
266-
}
267-
268-
// u.History.Items is a slice with a set (identical) length and capacity.
269-
for idx := range u.History.Items {
270-
if idx == 0 {
271-
u.History.Items[0] = item
272-
} else {
273-
u.History.Items[idx] = u.History.Items[idx-1]
274-
}
275-
276-
if !ui.HasGUI() {
277-
continue
278-
}
279-
280-
if u.History.Items[idx] != "" {
281-
u.menu[hist+strconv.Itoa(idx)].SetTitle(u.History.Items[idx])
282-
u.menu[hist+strconv.Itoa(idx)].Show()
283-
} else {
284-
u.menu[hist+strconv.Itoa(idx)].Hide()
285-
}
286-
}
287-
}

pkg/unpackerr/tray_other.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,3 @@ func (u *Unpackerr) startTray() {
1818
func (u *Unpackerr) updateTray(_ *Stats, _ uint) {
1919
// there is no tray.
2020
}
21-
22-
func (u *Unpackerr) updateHistory(item string) {
23-
if u.KeepHistory == 0 {
24-
return
25-
}
26-
27-
u.History.Items[0] = item
28-
// u.History.Items is a slice with a set (identical) length and capacity.
29-
for idx := range u.History.Items {
30-
u.History.Items[idx] = u.History.Items[idx-1]
31-
}
32-
}

0 commit comments

Comments
 (0)