Skip to content

Commit

Permalink
hist const
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jan 18, 2024
1 parent 4a244ff commit 4b6e7e6
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pkg/unpackerr/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"golift.io/version"
)

// Safety constant.
const hist = "hist_"

// 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 @@ -139,18 +142,18 @@ func (u *Unpackerr) watchGuiChannels() {
func (u *Unpackerr) makeHistoryChannels() {
history := systray.AddMenuItem("History", fmt.Sprintf("display last %d items queued", u.KeepHistory))
u.menu["history"] = ui.WrapMenu(history)
u.menu["hist_none"] = ui.WrapMenu(history.AddSubMenuItem("-- there is no history --", "nothing has been queued yet"))
u.menu["hist_none"].Disable()
u.menu[hist+"none"] = ui.WrapMenu(history.AddSubMenuItem("-- there is no history --", "nothing has been queued yet"))
u.menu[hist+"none"].Disable()

if u.KeepHistory == 0 {
u.menu["hist_none"].SetTitle("-- history disabled --")
u.menu["hist_none"].SetTooltip("history is disabled in the config")
u.menu[hist+"none"].SetTitle("-- history disabled --")
u.menu[hist+"none"].SetTooltip("history is disabled in the config")
}

for i := 0; i < int(u.KeepHistory); i++ {
u.menu["hist_"+strconv.Itoa(i)] = ui.WrapMenu(history.AddSubMenuItem("", ""))
u.menu["hist_"+strconv.Itoa(i)].Disable()
u.menu["hist_"+strconv.Itoa(i)].Hide()
u.menu[hist+strconv.Itoa(i)] = ui.WrapMenu(history.AddSubMenuItem("", ""))
u.menu[hist+strconv.Itoa(i)].Disable()
u.menu[hist+strconv.Itoa(i)].Hide()
}
}

Expand Down Expand Up @@ -258,7 +261,7 @@ func (u *Unpackerr) updateHistory(item string) {
}

if ui.HasGUI() && item != "" {
u.menu["hist_none"].Hide()
u.menu[hist+"none"].Hide()
}

// u.History.Items is a slice with a set (identical) length and capacity.
Expand All @@ -274,10 +277,10 @@ func (u *Unpackerr) updateHistory(item string) {
}

if u.History.Items[i] != "" {
u.menu["hist_"+strconv.Itoa(i)].SetTitle(u.History.Items[i])
u.menu["hist_"+strconv.Itoa(i)].Show()
u.menu[hist+strconv.Itoa(i)].SetTitle(u.History.Items[i])
u.menu[hist+strconv.Itoa(i)].Show()
} else {
u.menu["hist_"+strconv.Itoa(i)].Hide()
u.menu[hist+strconv.Itoa(i)].Hide()
}
}
}

0 comments on commit 4b6e7e6

Please sign in to comment.