diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd079c..04d9db3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/config/config.go b/config/config.go index 223fb21..4ff29c9 100644 --- a/config/config.go +++ b/config/config.go @@ -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) diff --git a/config/default.go b/config/default.go index a0b90a6..9855480 100644 --- a/config/default.go +++ b/config/default.go @@ -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 diff --git a/default-config.toml b/default-config.toml index e282219..d701365 100644 --- a/default-config.toml +++ b/default-config.toml @@ -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 diff --git a/display/handlers.go b/display/handlers.go index 13460f4..48f2546 100644 --- a/display/handlers.go +++ b/display/handlers.go @@ -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) diff --git a/sysopen/open_browser_other.go b/sysopen/open_browser_other.go index 3be7235..ff4a709 100644 --- a/sysopen/open_browser_other.go +++ b/sysopen/open_browser_other.go @@ -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") } diff --git a/sysopen/open_browser_unix.go b/sysopen/open_browser_unix.go index 229c2ea..80c0ffc 100644 --- a/sysopen/open_browser_unix.go +++ b/sysopen/open_browser_unix.go @@ -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") } }