From e34644be6f4cb791372308fabf70d9b45961a7c0 Mon Sep 17 00:00:00 2001 From: makeworld Date: Sun, 27 Dec 2020 20:13:13 -0500 Subject: [PATCH] Favicons work --- display/handlers.go | 5 +++-- display/util.go | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/display/handlers.go b/display/handlers.go index 952f49f..a3239cd 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -9,6 +9,7 @@ import ( "net/url" "os/exec" "path" + "strconv" "strings" "github.com/makeworld-the-better-one/amfora/cache" @@ -95,7 +96,8 @@ func handleFavicon(t *tab, host, old string) { defer func() { // Update display if needed if t.page.Favicon != old && isValidTab(t) { - // TODO update browser tab label + browser.SetTabLabel(strconv.Itoa(tabNumber(t)), t.page.Favicon) + App.Draw() } }() @@ -117,7 +119,6 @@ func handleFavicon(t *tab, host, old string) { } if fav != "" { t.page.Favicon = fav - // TODO update browser tab label return } diff --git a/display/util.go b/display/util.go index 33495c1..33e4a59 100644 --- a/display/util.go +++ b/display/util.go @@ -13,6 +13,18 @@ import ( // This file contains funcs that are small, self-contained utilities. +// tabNumber gets the index of the tab in the tabs slice. It returns -1 +// if the tab is not in that slice. +func tabNumber(t *tab) int { + tempTabs := tabs + for i := range tempTabs { + if tempTabs[i] == t { + return i + } + } + return -1 +} + // escapeMeta santizes a META string for use within a cview modal. func escapeMeta(meta string) string { return cview.Escape(strings.ReplaceAll(meta, "\n", "")) @@ -20,13 +32,7 @@ func escapeMeta(meta string) string { // isValidTab indicates whether the passed tab is still being used, even if it's not currently displayed. func isValidTab(t *tab) bool { - tempTabs := tabs - for i := range tempTabs { - if tempTabs[i] == t { - return true - } - } - return false + return tabNumber(t) != -1 } func leftMargin() int {