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

🐛 Portal open uses http config setting - fixes #42

This commit is contained in:
makeworld 2020-07-07 21:51:20 -04:00
parent fc11a308f1
commit 06a112b1cc
2 changed files with 27 additions and 25 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Many potential network and display race conditions eliminated
- Whether a tab is loading stays indicated when you switch away from it and go back
- Plain text documents are displayed faithfully (there were some edge conditions)
- Opening files in portal.mozz.us uses the `http` setting in the config (#42)
## [1.2.0] - 2020-07-02
### Added

View File

@ -171,6 +171,30 @@ func setPage(t *tab, p *structs.Page) {
t.barText = p.Url
}
// handleHTTP is used by handleURL.
// It opens HTTP links and displays Info and Error modals.
func handleHTTP(u string, showInfo bool) {
switch strings.TrimSpace(viper.GetString("a-general.http")) {
case "", "off":
Error("HTTP Error", "Opening HTTP URLs is turned off.")
case "default":
s, err := webbrowser.Open(u)
if err != nil {
Error("Webbrowser Error", err.Error())
} else if showInfo {
Info(s)
}
default:
// The config has a custom command to execute for HTTP URLs
fields := strings.Fields(viper.GetString("a-general.http"))
err := exec.Command(fields[0], append(fields[1:], u)...).Start()
if err != nil {
Error("HTTP Error", "Error executing custom browser command: "+err.Error())
}
}
App.Draw()
}
// goURL is like handleURL, but takes care of history and the bottomBar.
// It should be preferred over handleURL in most cases.
// It has no return values to be processed.
@ -237,24 +261,7 @@ func handleURL(t *tab, u string) (string, bool) {
}
if strings.HasPrefix(u, "http") {
switch strings.TrimSpace(viper.GetString("a-general.http")) {
case "", "off":
Info("Opening HTTP URLs is turned off.")
case "default":
s, err := webbrowser.Open(u)
if err != nil {
Error("Webbrowser Error", err.Error())
} else {
Info(s)
}
default:
// The config has a custom command to execute for HTTP URLs
fields := strings.Fields(viper.GetString("a-general.http"))
err := exec.Command(fields[0], append(fields[1:], u)...).Start()
if err != nil {
Error("HTTP Error", "Error executing custom browser command: "+err.Error())
}
}
handleHTTP(u, true)
return ret("", false)
}
if !strings.HasPrefix(u, "gemini") {
@ -364,13 +371,7 @@ func handleURL(t *tab, u string) (string, bool) {
}
portalURL = strings.TrimPrefix(portalURL, "gemini://") + "?raw=1"
s, err := webbrowser.Open("https://portal.mozz.us/gemini/" + portalURL)
if err != nil {
Error("Webbrowser Error", err.Error())
} else {
Info(s)
}
App.Draw()
handleHTTP("https://portal.mozz.us/gemini/"+portalURL, false)
}
return ret("", false)
}