Added ability to save `about:` pages. (#236)

Co-authored-by: makeworld
This commit is contained in:
Anas Mohamed 2021-05-13 14:38:53 -06:00 committed by GitHub
parent 2f214b547c
commit a3713075dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 11 deletions

View File

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

View File

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

View File

@ -321,8 +321,14 @@ 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(u, "about:") {
name, err = getSafeDownloadName(dir, parsed.Opaque+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 +346,7 @@ func downloadNameFromURL(dir, u, ext string) (string, error) {
return "", err
}
}
return filepath.Join(dir, name), nil
}

View File

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

View File

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

View File

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

View File

@ -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.
//

View File

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