1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-19 19:25:24 +00:00

Add handleAbout()

This commit is contained in:
makeworld 2020-11-27 18:25:17 -05:00
parent 5722c50432
commit 62102d4f98
3 changed files with 35 additions and 41 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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
}