diff --git a/display/display.go b/display/display.go index 919cfb8..a2c5bdb 100644 --- a/display/display.go +++ b/display/display.go @@ -576,25 +576,8 @@ func Reload() { // URL loads and handles the provided URL for the current tab. // It should be an absolute URL. func URL(u string) { - // Some code is copied in followLink() - - if u == "about:bookmarks" { //nolint:goconst - Bookmarks(tabs[curTab]) - tabs[curTab].addToHistory("about:bookmarks") - return - } - if u == "about:subscriptions" { //nolint:goconst - Subscriptions(tabs[curTab]) - tabs[curTab].addToHistory("about:subscriptions") - return - } - if u == "about:newtab" { - temp := newTabPage // Copy - setPage(tabs[curTab], &temp) - return - } - if strings.HasPrefix(u, "about:") { - Error("Error", "Not a valid 'about:' URL.") + if u[:6] == "about:" { + handleAbout(tabs[curTab], u) return } diff --git a/display/handlers.go b/display/handlers.go index b3ae20a..e4440de 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -163,6 +163,35 @@ func handleFavicon(t *tab, host, old string) { 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. +// +// It returns a bool indicating if the provided URL could be handled. +func handleAbout(t *tab, u string) bool { + if u[:6] != "about:" { + return false + } + + switch u { + case "about:bookmarks": + Bookmarks(t) + t.addToHistory("about:bookmarks") + return true + case "about:subscriptions": + Subscriptions(t) + t.addToHistory("about:subscriptions") + return true + case "about:newtab": + temp := newTabPage // Copy + setPage(t, &temp) + return true + } + + Error("Error", "Not a valid 'about:' URL.") + return false +} + // handleURL displays whatever action is needed for the provided URL, // and applies it to the current tab. // It loads documents, handles errors, brings up a download prompt, etc. @@ -215,14 +244,8 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) { App.SetFocus(t.view) - // To allow linking to the bookmarks page, and history browsing - if u == "about:bookmarks" { - Bookmarks(t) - return ret("about:bookmarks", true) - } - if u == "about:subscriptions" { - Subscriptions(t) - return ret("about:subscriptions", true) + if u[:6] == "about:" { + return ret(u, handleAbout(t, u)) } u = normalizeURL(u) diff --git a/display/private.go b/display/private.go index 63ea32e..2758f0f 100644 --- a/display/private.go +++ b/display/private.go @@ -19,20 +19,8 @@ import ( // Not when a URL is opened on a new tab for the first time. // It will handle setting the bottomBar. func followLink(t *tab, prev, next string) { - - // Copied from URL() - if next == "about:bookmarks" { - Bookmarks(t) - t.addToHistory("about:bookmarks") - return - } - if next == "about:subscriptions" { - Subscriptions(t) - t.addToHistory("about:subscriptions") - return - } - if strings.HasPrefix(next, "about:") { - Error("Error", "Not a valid 'about:' URL for linking") + if next[:6] == "about:" { + handleAbout(t, next) return }