Use default application to open unknown schemes

Fixes #207
This commit is contained in:
makeworld 2021-12-07 15:28:34 -05:00
parent 06b649d81a
commit 97ee1aa368
7 changed files with 19 additions and 6 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Text no longer disappears under the left margin when scrolling (regression in v1.8.0) (#197)
- Default search engine changed to geminispace.info from gus.guru
- The user's terminal theme colors are used by default (#181)
- By default, non-gemini URI schemes are opened in the default application. This requires a config change for previous users, see the [wiki](https://github.com/makeworld-the-better-one/amfora/wiki/Handling-Other-URL-Schemes) (#207)
## Removed
- Favicon support (#199)

View File

@ -259,7 +259,7 @@ func Init() error {
viper.SetDefault("keybindings.bind_beginning", []string{"Home", "g"})
viper.SetDefault("keybindings.bind_end", []string{"End", "G"})
viper.SetDefault("keybindings.shift_numbers", "")
viper.SetDefault("url-handlers.other", "off")
viper.SetDefault("url-handlers.other", "default")
viper.SetDefault("cache.max_size", 0)
viper.SetDefault("cache.max_pages", 20)
viper.SetDefault("cache.timeout", 1800)

View File

@ -197,7 +197,9 @@ underline = true
# This is a special key that defines the handler for all URL schemes for which
# no handler is defined.
other = 'off'
# It uses the special value "default", which will try and use the default
# application on your computer for opening this kind of URI.
other = 'default'
# [[mediatype-handlers]] section

View File

@ -194,7 +194,9 @@ underline = true
# This is a special key that defines the handler for all URL schemes for which
# no handler is defined.
other = 'off'
# It uses the special value "default", which will try and use the default
# application on your computer for opening this kind of URI.
other = 'default'
# [[mediatype-handlers]] section

View File

@ -16,6 +16,7 @@ import (
"github.com/makeworld-the-better-one/amfora/rr"
"github.com/makeworld-the-better-one/amfora/structs"
"github.com/makeworld-the-better-one/amfora/subscriptions"
"github.com/makeworld-the-better-one/amfora/sysopen"
"github.com/makeworld-the-better-one/amfora/webbrowser"
"github.com/makeworld-the-better-one/go-gemini"
"github.com/spf13/viper"
@ -75,6 +76,13 @@ func handleOther(u string) {
switch handler {
case "", "off":
Error("URL Error", "Opening "+parsed.Scheme+" URLs is turned off.")
case "default":
_, err := sysopen.Open(u)
if err != nil {
Error("Application Error", err.Error())
return
}
Info("Opened in default application")
default:
// The config has a custom command to execute for URLs
fields := strings.Fields(handler)

View File

@ -8,5 +8,5 @@ import "fmt"
// Open opens `path` in default system viewer, but not on this OS.
func Open(path string) (string, error) {
return "", fmt.Errorf("unsupported OS for default system viewer. " +
"Set a catch-all [[mediatype-handlers]] command in the config")
"Set a catch-all command in the config")
}

View File

@ -21,7 +21,7 @@ func Open(path string) (string, error) {
switch {
case xorgDisplay == "" && waylandDisplay == "":
return "", fmt.Errorf("no display server was found. " +
"You may set a default [[mediatype-handlers]] command in the config")
"You may set a default command in the config")
case xdgOpenNotFoundErr == nil:
// Use start rather than run or output in order
// to make application run in background.
@ -31,6 +31,6 @@ func Open(path string) (string, error) {
return "Opened in default system viewer", nil
default:
return "", fmt.Errorf("could not determine default system viewer. " +
"Set a catch-all [[mediatype-handlers]] command in the config")
"Set a catch-all command in the config")
}
}