diff --git a/CHANGELOG.md b/CHANGELOG.md index e7530b3..104c37b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Favicon support removed (#199) + ### Fixed - Help text is now the same color as `regular_text` in the theme config - Non-ASCII (multibyte) characters can now be used as keybindings (#198, #200) diff --git a/README.md b/README.md index c2487fa..99d57ca 100644 --- a/README.md +++ b/README.md @@ -141,9 +141,6 @@ Features in *italics* are in the master branch, but not in the latest release. - [x] Download pages and arbitrary data - [x] Theming - Check out the [user contributed themes](https://github.com/makeworld-the-better-one/amfora/tree/master/contrib/themes)! -- [x] Emoji favicons - - See `gemini://mozz.us/files/rfc_gemini_favicon.gmi` for details - - Disabled by default, enable in config - [x] Proxying - Schemes like Gopher or HTTP can be proxied through a Gemini server - [x] Client certificate support diff --git a/cache/favicon.go b/cache/favicon.go deleted file mode 100644 index 674a8f9..0000000 --- a/cache/favicon.go +++ /dev/null @@ -1,51 +0,0 @@ -package cache - -import ( - "sync" -) - -// Functions for caching emoji favicons. -// See gemini://mozz.us/files/rfc_gemini_favicon.gmi for details. - -var favicons = make(map[string]string) // domain to emoji -var favMu = sync.RWMutex{} - -var KnownNoFavicon = "no" - -// AddFavicon will add an emoji to the cache under that host. -// It does not verify that the string passed is actually an emoji. -// You can pass KnownNoFavicon as the emoji when a host doesn't have a valid favicon. -func AddFavicon(host, emoji string) { - favMu.Lock() - favicons[host] = emoji - favMu.Unlock() -} - -// ClearFavicons removes all favicons from the cache -func ClearFavicons() { - favMu.Lock() - favicons = make(map[string]string) - favMu.Unlock() -} - -// GetFavicon returns the favicon string for the host. -// It returns an empty string if there is no favicon cached. -// It might also return KnownNoFavicon to indicate that that host does not have -// a favicon at all. -func GetFavicon(host string) string { - favMu.RLock() - defer favMu.RUnlock() - return favicons[host] -} - -func NumFavicons() int { - favMu.RLock() - defer favMu.RUnlock() - return len(favicons) -} - -func RemoveFavicon(host string) { - favMu.Lock() - delete(favicons, host) - favMu.Unlock() -} diff --git a/config/config.go b/config/config.go index 37d9e6e..b0d8fed 100644 --- a/config/config.go +++ b/config/config.go @@ -207,7 +207,6 @@ func Init() error { viper.SetDefault("a-general.temp_downloads", "") viper.SetDefault("a-general.page_max_size", 2097152) viper.SetDefault("a-general.page_max_time", 10) - viper.SetDefault("a-general.emoji_favicons", false) viper.SetDefault("a-general.scrollbar", "auto") viper.SetDefault("keybindings.bind_reload", []string{"R", "Ctrl-R"}) viper.SetDefault("keybindings.bind_home", "Backspace") diff --git a/config/default.go b/config/default.go index 13e6e3e..6de65f1 100644 --- a/config/default.go +++ b/config/default.go @@ -70,9 +70,6 @@ page_max_size = 2097152 # 2 MiB # Max time it takes to load a page in seconds - after that a download window pops up page_max_time = 10 -# Whether to replace tab numbers with emoji favicons, which are cached. -emoji_favicons = false - # When a scrollbar appears. "never", "auto", and "always" are the only valid values. # "auto" means the scrollbar only appears when the page is longer than the window. scrollbar = "auto" diff --git a/default-config.toml b/default-config.toml index b4ebc18..2fb7031 100644 --- a/default-config.toml +++ b/default-config.toml @@ -67,9 +67,6 @@ page_max_size = 2097152 # 2 MiB # Max time it takes to load a page in seconds - after that a download window pops up page_max_time = 10 -# Whether to replace tab numbers with emoji favicons, which are cached. -emoji_favicons = false - # When a scrollbar appears. "never", "auto", and "always" are the only valid values. # "auto" means the scrollbar only appears when the page is longer than the window. scrollbar = "auto" diff --git a/display/bookmarks.go b/display/bookmarks.go index 25ac460..083a902 100644 --- a/display/bookmarks.go +++ b/display/bookmarks.go @@ -78,7 +78,7 @@ func bkmkInit() { // It also accepts a bool indicating whether this page already has a bookmark. // It returns the bookmark name and the bookmark action: // 1, 0, -1 for add/update, cancel, and remove -func openBkmkModal(name string, exists bool, favicon string) (string, int) { +func openBkmkModal(name string, exists bool) (string, int) { // Basically a copy of Input() // Reset buttons before input field, to make sure the input is in focus @@ -93,9 +93,7 @@ func openBkmkModal(name string, exists bool, favicon string) (string, int) { // Remove and re-add input field - to clear the old text bkmkModal.GetForm().Clear(false) - if favicon != "" && !exists { - name = favicon + " " + name - } + bkmkModalText = name bkmkModal.GetForm().AddInputField("Name: ", name, 0, nil, func(text string) { @@ -152,7 +150,7 @@ func addBookmark() { } name, exists := bookmarks.Get(p.URL) // Open a bookmark modal with the current name of the bookmark, if it exists - newName, action := openBkmkModal(name, exists, p.Favicon) + newName, action := openBkmkModal(name, exists) switch action { case 1: // Add/change the bookmark diff --git a/display/display.go b/display/display.go index cca444b..0f3d7e4 100644 --- a/display/display.go +++ b/display/display.go @@ -545,10 +545,8 @@ func Reload() { return } - parsed, _ := url.Parse(tabs[curTab].page.URL) go func(t *tab) { cache.RemovePage(tabs[curTab].page.URL) - cache.RemoveFavicon(parsed.Host) handleURL(t, t.page.URL, 0) // goURL is not used bc history shouldn't be added to if t == tabs[curTab] { // Display the bottomBar state that handleURL set diff --git a/display/handlers.go b/display/handlers.go index b0deb9a..0f45419 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -1,15 +1,12 @@ package display import ( - "bytes" "errors" - "io" "mime" "net" "net/url" "os/exec" "path" - "strconv" "strings" "github.com/makeworld-the-better-one/amfora/cache" @@ -21,7 +18,6 @@ import ( "github.com/makeworld-the-better-one/amfora/subscriptions" "github.com/makeworld-the-better-one/amfora/webbrowser" "github.com/makeworld-the-better-one/go-gemini" - "github.com/makeworld-the-better-one/go-isemoji" "github.com/spf13/viper" ) @@ -90,81 +86,6 @@ func handleOther(u string) { App.Draw() } -// handleFavicon handles getting and displaying a favicon. -func handleFavicon(t *tab, host string) { - defer func() { - // Update display if needed - if t.page.Favicon != "" && isValidTab(t) { - browser.SetTabLabel(strconv.Itoa(tabNumber(t)), makeTabLabel(t.page.Favicon)) - App.Draw() - } - }() - - if !viper.GetBool("a-general.emoji_favicons") { - // Not enabled - return - } - if t.page.Favicon != "" { - return - } - if host == "" { - return - } - - fav := cache.GetFavicon(host) - if fav == cache.KnownNoFavicon { - // It's been cached that this host doesn't have a favicon - return - } - if fav != "" { - t.page.Favicon = fav - return - } - - // No favicon cached - res, err := client.Fetch("gemini://" + host + "/favicon.txt") - if err != nil { - if res != nil { - res.Body.Close() - } - cache.AddFavicon(host, cache.KnownNoFavicon) - return - } - defer res.Body.Close() - - if res.Status != 20 { - cache.AddFavicon(host, cache.KnownNoFavicon) - return - } - if !strings.HasPrefix(res.Meta, "text/") && res.Meta != "" { - // Not a textual page - cache.AddFavicon(host, cache.KnownNoFavicon) - return - } - // It's a regular plain response - - buf := new(bytes.Buffer) - _, err = io.CopyN(buf, res.Body, 29+2+1) // 29 is the max emoji length, +2 for CRLF, +1 so that the right size will EOF - if err == nil { - // Content was too large - cache.AddFavicon(host, cache.KnownNoFavicon) - return - } else if err != io.EOF { - // Some network reading error - // No favicon is NOT known, could be a temporary error - return - } - // EOF, which is what we want. - emoji := strings.TrimRight(buf.String(), "\r\n") - if !isemoji.IsEmoji(emoji) { - cache.AddFavicon(host, cache.KnownNoFavicon) - return - } - // Valid favicon found - t.page.Favicon = emoji - cache.AddFavicon(host, emoji) -} - // handleAbout can be called to deal with any URLs that start with // 'about:'. It will display errors if the URL is not recognized, // but not display anything if an 'about:' URL is not passed. diff --git a/display/private.go b/display/private.go index 0bd7825..de2e505 100644 --- a/display/private.go +++ b/display/private.go @@ -118,11 +118,6 @@ func setPage(t *tab, p *structs.Page) { browser.SetTabLabel(strconv.Itoa(tabNum), makeTabLabel(strconv.Itoa(tabNum+1))) App.Draw() - go func() { - parsed, _ := url.Parse(p.URL) - handleFavicon(t, parsed.Host) - }() - // Setup display App.SetFocus(t.view) diff --git a/go.mod b/go.mod index 2137519..3737232 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/gdamore/tcell/v2 v2.1.1-0.20210125004847-19e17097d8fe github.com/google/go-cmp v0.5.0 // indirect github.com/makeworld-the-better-one/go-gemini v0.11.0 - github.com/makeworld-the-better-one/go-isemoji v1.1.0 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.3.1 // indirect github.com/mmcdole/gofeed v1.1.0 @@ -25,6 +24,7 @@ require ( golang.org/x/text v0.3.5 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/ini.v1 v1.62.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect ) replace github.com/mmcdole/gofeed => github.com/makeworld-the-better-one/gofeed v1.1.1-0.20201123002655-c0c6354134fe diff --git a/go.sum b/go.sum index e8234ce..01e8df2 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,6 @@ github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzR github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/makeworld-the-better-one/go-gemini v0.11.0 h1:MNGiULJFvcqls9oCy40tE897hDeKvNmEK9i5kRucgQk= github.com/makeworld-the-better-one/go-gemini v0.11.0/go.mod h1:F+3x+R1xeYK90jMtBq+U+8Sh64r2dHleDZ/en3YgSmg= -github.com/makeworld-the-better-one/go-isemoji v1.1.0 h1:wZBHOKB5zAIgaU2vaWnXFDDhatebB8TySrNVxjVV84g= -github.com/makeworld-the-better-one/go-isemoji v1.1.0/go.mod h1:FBjkPl9rr0G4vlZCc+Mr+QcnOfGCTbGWYW8/1sp06I0= github.com/makeworld-the-better-one/gofeed v1.1.1-0.20201123002655-c0c6354134fe h1:i3b9Qy5z23DcXRnrsMYcM5s9Ng5VIidM1xZd+szuTsY= github.com/makeworld-the-better-one/gofeed v1.1.1-0.20201123002655-c0c6354134fe/go.mod h1:QQO3maftbOu+hiVOGOZDRLymqGQCos4zxbA4j89gMrE= github.com/makeworld-the-better-one/progressbar/v3 v3.3.5-0.20201220005701-b036c4d38568 h1:fod4pD+rsU73WIUxl8Kpo35LDuOx0uxzlprBKbm84vw= diff --git a/structs/structs.go b/structs/structs.go index 8770cc0..2bcca8f 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -32,7 +32,6 @@ type Page struct { Selected string // The current text or link selected SelectedID string // The cview region ID for the selected text/link Mode PageMode - Favicon string MadeAt time.Time // When the page was made. Zero value indicates it should stay in cache forever. }