mirror of
https://github.com/makew0rld/amfora.git
synced 2025-02-02 15:07:34 -05:00
✨Add option to automatically follow redirects (#75)
Co-authored-by: makeworld
This commit is contained in:
parent
580e87bcc9
commit
4452fcfec6
@ -145,6 +145,7 @@ func Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
viper.SetDefault("a-general.home", "gemini.circumlunar.space")
|
viper.SetDefault("a-general.home", "gemini.circumlunar.space")
|
||||||
|
viper.SetDefault("a-general.auto_redirect", false)
|
||||||
viper.SetDefault("a-general.http", "default")
|
viper.SetDefault("a-general.http", "default")
|
||||||
viper.SetDefault("a-general.search", "gus.guru/search")
|
viper.SetDefault("a-general.search", "gus.guru/search")
|
||||||
viper.SetDefault("a-general.color", true)
|
viper.SetDefault("a-general.color", true)
|
||||||
|
@ -16,6 +16,11 @@ var defaultConf = []byte(`# This is the default config file.
|
|||||||
# Press Ctrl-H to access it
|
# Press Ctrl-H to access it
|
||||||
home = "gemini://gemini.circumlunar.space"
|
home = "gemini://gemini.circumlunar.space"
|
||||||
|
|
||||||
|
# Follow up to 5 Gemini redirects without prompting.
|
||||||
|
# A prompt is always shown after the 5th redirect and for redirects to protocols other than Gemini.
|
||||||
|
# If set to false, a prompt will be shown before following redirects.
|
||||||
|
auto_redirect = false
|
||||||
|
|
||||||
# What command to run to open a HTTP URL. Set to "default" to try to guess the browser,
|
# What command to run to open a HTTP URL. Set to "default" to try to guess the browser,
|
||||||
# or set to "off" to not open HTTP URLs.
|
# or set to "off" to not open HTTP URLs.
|
||||||
# If a command is set, than the URL will be added (in quotes) to the end of the command.
|
# If a command is set, than the URL will be added (in quotes) to the end of the command.
|
||||||
|
@ -13,6 +13,11 @@
|
|||||||
# Press Ctrl-H to access it
|
# Press Ctrl-H to access it
|
||||||
home = "gemini://gemini.circumlunar.space"
|
home = "gemini://gemini.circumlunar.space"
|
||||||
|
|
||||||
|
# Follow up to 5 Gemini redirects without prompting.
|
||||||
|
# A prompt is always shown after the 5th redirect and for redirects to protocols other than Gemini.
|
||||||
|
# If set to false, a prompt will be shown before following redirects.
|
||||||
|
auto_redirect = false
|
||||||
|
|
||||||
# What command to run to open a HTTP URL. Set to "default" to try to guess the browser,
|
# What command to run to open a HTTP URL. Set to "default" to try to guess the browser,
|
||||||
# or set to "off" to not open HTTP URLs.
|
# or set to "off" to not open HTTP URLs.
|
||||||
# If a command is set, than the URL will be added (in quotes) to the end of the command.
|
# If a command is set, than the URL will be added (in quotes) to the end of the command.
|
||||||
|
@ -521,7 +521,7 @@ func Reload() {
|
|||||||
go func(t *tab) {
|
go func(t *tab) {
|
||||||
cache.RemovePage(tabs[curTab].page.URL)
|
cache.RemovePage(tabs[curTab].page.URL)
|
||||||
cache.RemoveFavicon(parsed.Host)
|
cache.RemoveFavicon(parsed.Host)
|
||||||
handleURL(t, t.page.URL) // goURL is not used bc history shouldn't be added to
|
handleURL(t, t.page.URL, 0) // goURL is not used bc history shouldn't be added to
|
||||||
if t == tabs[curTab] {
|
if t == tabs[curTab] {
|
||||||
// Display the bottomBar state that handleURL set
|
// Display the bottomBar state that handleURL set
|
||||||
t.applyBottomBar()
|
t.applyBottomBar()
|
||||||
|
@ -2,7 +2,7 @@ package display
|
|||||||
|
|
||||||
// applyHist is a history.go internal function, to load a URL in the history.
|
// applyHist is a history.go internal function, to load a URL in the history.
|
||||||
func applyHist(t *tab) {
|
func applyHist(t *tab) {
|
||||||
handleURL(t, t.history.urls[t.history.pos]) // Load that position in history
|
handleURL(t, t.history.urls[t.history.pos], 0) // Load that position in history
|
||||||
t.applyAll()
|
t.applyAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ func handleFavicon(t *tab, host, old string) {
|
|||||||
//
|
//
|
||||||
// It should be called in a goroutine.
|
// It should be called in a goroutine.
|
||||||
func goURL(t *tab, u string) {
|
func goURL(t *tab, u string) {
|
||||||
final, displayed := handleURL(t, u)
|
final, displayed := handleURL(t, u, 0)
|
||||||
if displayed {
|
if displayed {
|
||||||
t.addToHistory(final)
|
t.addToHistory(final)
|
||||||
}
|
}
|
||||||
@ -289,7 +289,10 @@ func goURL(t *tab, u string) {
|
|||||||
//
|
//
|
||||||
// The bottomBar is not actually changed in this func, except during loading.
|
// The bottomBar is not actually changed in this func, except during loading.
|
||||||
// The func that calls this one should apply the bottomBar values if necessary.
|
// The func that calls this one should apply the bottomBar values if necessary.
|
||||||
func handleURL(t *tab, u string) (string, bool) {
|
//
|
||||||
|
// numRedirects is the number of redirects that resulted in the provided URL.
|
||||||
|
// It should typically be 0.
|
||||||
|
func handleURL(t *tab, u string, numRedirects int) (string, bool) {
|
||||||
defer App.Draw() // Just in case
|
defer App.Draw() // Just in case
|
||||||
|
|
||||||
// Save for resetting on error
|
// Save for resetting on error
|
||||||
@ -421,7 +424,7 @@ func handleURL(t *tab, u string) (string, bool) {
|
|||||||
Error("Input Error", "URL for that input would be too long.")
|
Error("Input Error", "URL for that input would be too long.")
|
||||||
return ret("", false)
|
return ret("", false)
|
||||||
}
|
}
|
||||||
return ret(handleURL(t, parsed.String()))
|
return ret(handleURL(t, parsed.String(), 0))
|
||||||
}
|
}
|
||||||
return ret("", false)
|
return ret("", false)
|
||||||
case 30:
|
case 30:
|
||||||
@ -431,11 +434,22 @@ func handleURL(t *tab, u string) (string, bool) {
|
|||||||
return ret("", false)
|
return ret("", false)
|
||||||
}
|
}
|
||||||
redir := parsed.ResolveReference(parsedMeta).String()
|
redir := parsed.ResolveReference(parsedMeta).String()
|
||||||
if YesNo("Follow redirect?\n" + redir) {
|
// Prompt before redirecting to non-Gemini protocol
|
||||||
|
redirect := false
|
||||||
|
if !strings.HasPrefix(redir, "gemini") {
|
||||||
|
if YesNo("Follow redirect to non-Gemini URL?\n" + redir) {
|
||||||
|
redirect = true
|
||||||
|
} else {
|
||||||
|
return ret("", false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Prompt before redirecting
|
||||||
|
autoRedirect := viper.GetBool("a-general.auto_redirect")
|
||||||
|
if redirect || (autoRedirect && numRedirects < 5) || YesNo("Follow redirect?\n"+redir) {
|
||||||
if res.Status == gemini.StatusRedirectPermanent {
|
if res.Status == gemini.StatusRedirectPermanent {
|
||||||
go cache.AddRedir(u, redir)
|
go cache.AddRedir(u, redir)
|
||||||
}
|
}
|
||||||
return ret(handleURL(t, redir))
|
return ret(handleURL(t, redir, numRedirects+1))
|
||||||
}
|
}
|
||||||
return ret("", false)
|
return ret("", false)
|
||||||
case 40:
|
case 40:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user