From 096820871cf95600d15f5e1a8e01d684deea57ea Mon Sep 17 00:00:00 2001 From: Anas Mohamed Date: Wed, 12 May 2021 05:19:41 -0600 Subject: [PATCH 1/4] extracted about page check to a separate function. --- display/bookmarks.go | 2 +- display/display.go | 4 ++-- display/handlers.go | 2 +- display/private.go | 2 +- display/subscriptions.go | 2 +- display/tab.go | 10 ++++++---- display/util.go | 2 +- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/display/bookmarks.go b/display/bookmarks.go index e956fb58..e20c2235 100644 --- a/display/bookmarks.go +++ b/display/bookmarks.go @@ -152,7 +152,7 @@ func addBookmark() { t := tabs[curTab] p := t.page - if !t.hasContent() { + if !t.hasContent() || t.isAnAboutPage() { // It's an about: page, or a malformed one return } diff --git a/display/display.go b/display/display.go index 4771787c..60918799 100644 --- a/display/display.go +++ b/display/display.go @@ -155,7 +155,7 @@ func Init(version, commit, builtBy string) { reset() return } - if query[0] == '.' && tabs[tab].hasContent() { + if query[0] == '.' && tabs[tab].hasContent() && !tabs[tab].isAnAboutPage() { // Relative url current, err := url.Parse(tabs[tab].page.URL) if err != nil { @@ -576,7 +576,7 @@ func Reload() { return } - if !tabs[curTab].hasContent() { + if !tabs[curTab].hasContent() || tabs[curTab].isAnAboutPage() { return } diff --git a/display/handlers.go b/display/handlers.go index 8f633704..8deaf90f 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -180,7 +180,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) { t.mode = tabModeDone go func(p *structs.Page) { - if b && t.hasContent() && viper.GetBool("subscriptions.popup") { + if b && t.hasContent() && !t.isAnAboutPage() && viper.GetBool("subscriptions.popup") { // The current page might be an untracked feed, and the user wants // to be notified in such cases. diff --git a/display/private.go b/display/private.go index 90cd8bd8..ecf4491a 100644 --- a/display/private.go +++ b/display/private.go @@ -23,7 +23,7 @@ func followLink(t *tab, prev, next string) { return } - if t.hasContent() { + if t.hasContent() && !t.isAnAboutPage() { nextURL, err := resolveRelLink(t, prev, next) if err != nil { Error("URL Error", err.Error()) diff --git a/display/subscriptions.go b/display/subscriptions.go index b582dd9e..30e76d85 100644 --- a/display/subscriptions.go +++ b/display/subscriptions.go @@ -304,7 +304,7 @@ func addSubscription() { t := tabs[curTab] p := t.page - if !t.hasContent() { + if !t.hasContent() || t.isAnAboutPage() { // It's an about: page, or a malformed one return } diff --git a/display/tab.go b/display/tab.go index cbbe593b..dbe75a97 100644 --- a/display/tab.go +++ b/display/tab.go @@ -213,7 +213,7 @@ func (t *tab) pageDown() { } // hasContent returns false when the tab's page is malformed, -// has no content or URL, or if it's an 'about:' page. +// has no content or URL. func (t *tab) hasContent() bool { if t.page == nil || t.view == nil { return false @@ -221,15 +221,17 @@ func (t *tab) hasContent() bool { if t.page.URL == "" { return false } - if strings.HasPrefix(t.page.URL, "about:") { - return false - } if t.page.Content == "" { return false } return true } +// isAnAboutPage returns true when the tab's page is an about page +func (t *tab) isAnAboutPage() bool { + return strings.HasPrefix(t.page.URL, "about:") +} + // applyHorizontalScroll handles horizontal scroll logic including left margin resizing, // see #197 for details. Use applyScroll instead. // diff --git a/display/util.go b/display/util.go index e0949ab0..f91f2a84 100644 --- a/display/util.go +++ b/display/util.go @@ -90,7 +90,7 @@ func textWidth() int { // It also returns an error if it could not resolve the links, which should be displayed // to the user. func resolveRelLink(t *tab, prev, next string) (string, error) { - if !t.hasContent() { + if !t.hasContent() || t.isAnAboutPage() { return next, nil } From 801861e7ab75b5cc9f6b128420c73553662bba7d Mon Sep 17 00:00:00 2001 From: Anas Mohamed Date: Wed, 12 May 2021 06:03:18 -0600 Subject: [PATCH 2/4] saves for about pages now use the entire url for filename. --- display/download.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/display/download.go b/display/download.go index 28fa9fa5..10313783 100644 --- a/display/download.go +++ b/display/download.go @@ -321,8 +321,15 @@ func downloadPage(p *structs.Page) (string, error) { func downloadNameFromURL(dir, u, ext string) (string, error) { var name string var err error + parsed, _ := url.Parse(u) - if parsed.Path == "" || path.Base(parsed.Path) == "/" { + if strings.HasPrefix(parsed.String(), "about:") { + // Is an about page, use the entire page url since there is no hostname + name, err = getSafeDownloadName(dir, parsed.String()+ext, true, 0) + if err != nil { + return "", err + } + } else if parsed.Path == "" || path.Base(parsed.Path) == "/" { // No file, just the root domain name, err = getSafeDownloadName(dir, parsed.Hostname()+ext, true, 0) if err != nil { @@ -340,6 +347,7 @@ func downloadNameFromURL(dir, u, ext string) (string, error) { return "", err } } + return filepath.Join(dir, name), nil } From ea0fabb67ced43f78c3a91b49a67a6e64cad57c3 Mon Sep 17 00:00:00 2001 From: Anas Mohamed Date: Thu, 13 May 2021 08:39:57 -0600 Subject: [PATCH 3/4] about pages can reload. Fixes for PR comments. --- display/display.go | 2 +- display/download.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/display/display.go b/display/display.go index 60918799..0368de9e 100644 --- a/display/display.go +++ b/display/display.go @@ -576,7 +576,7 @@ func Reload() { return } - if !tabs[curTab].hasContent() || tabs[curTab].isAnAboutPage() { + if !tabs[curTab].hasContent() { return } diff --git a/display/download.go b/display/download.go index 10313783..e9ff2865 100644 --- a/display/download.go +++ b/display/download.go @@ -323,9 +323,10 @@ func downloadNameFromURL(dir, u, ext string) (string, error) { var err error parsed, _ := url.Parse(u) - if strings.HasPrefix(parsed.String(), "about:") { - // Is an about page, use the entire page url since there is no hostname - name, err = getSafeDownloadName(dir, parsed.String()+ext, true, 0) + if strings.HasPrefix(u, "about:") { + // Is an about page, trim out 'about:' for the filename to be saved. + pagePath := strings.TrimPrefix(u, "about:") + name, err = getSafeDownloadName(dir, pagePath+ext, true, 0) if err != nil { return "", err } From 56b7e4ab68fbff8b7bb29688b8861d0fc8f2cab5 Mon Sep 17 00:00:00 2001 From: makeworld Date: Thu, 13 May 2021 16:36:49 -0400 Subject: [PATCH 4/4] Only use page path --- display/download.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/display/download.go b/display/download.go index e9ff2865..b57a097b 100644 --- a/display/download.go +++ b/display/download.go @@ -324,9 +324,7 @@ func downloadNameFromURL(dir, u, ext string) (string, error) { parsed, _ := url.Parse(u) if strings.HasPrefix(u, "about:") { - // Is an about page, trim out 'about:' for the filename to be saved. - pagePath := strings.TrimPrefix(u, "about:") - name, err = getSafeDownloadName(dir, pagePath+ext, true, 0) + name, err = getSafeDownloadName(dir, parsed.Opaque+ext, true, 0) if err != nil { return "", err }