Skip to content

Commit

Permalink
Use default application to open unknown schemes
Browse files Browse the repository at this point in the history
Fixes #207
  • Loading branch information
makew0rld committed Dec 7, 2021
1 parent 06b649d commit 97ee1aa
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions display/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sysopen/open_browser_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 2 additions & 2 deletions sysopen/open_browser_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
}
}

0 comments on commit 97ee1aa

Please sign in to comment.