summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2021-01-30 11:33:31 +0100
committerReto Brunner <reto@labrat.space>2021-01-30 14:04:23 +0100
commit949781fa0a5f0654112b4f78558347ca991a89d3 (patch)
tree1d8d58e66b567709ed746654ceb92d75667557b4 /commands
parent9385827cae7bab6534933718d21eeb489448c476 (diff)
downloadaerc-949781fa0a5f0654112b4f78558347ca991a89d3.zip
Refactor lib/open to accept user provided arguments
* Get rid of open_darwin It just lead to code duplication for a simple one string change. Instead we query it during initialization * Accept user provided arguments "open" on MacOS accepts things like -A to use a specific application Pass trough arguments the user provided in order to facilitate this * Refactor the function to a struct This makes it more convenient for the caller and avoids signatures like lib.OpenFile(nil, u.String(), nil) which are fairly unreadable
Diffstat (limited to 'commands')
-rw-r--r--commands/msg/unsubscribe.go3
-rw-r--r--commands/msgview/open.go24
2 files changed, 17 insertions, 10 deletions
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index 205a255..cf3e4a8 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -119,6 +119,5 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
}
func unsubscribeHTTP(u *url.URL) error {
- lib.OpenFile(u.String(), nil)
- return nil
+ return lib.NewXDGOpen(u.String()).Start()
}
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 4aa6133..47b4369 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -1,7 +1,6 @@
package msgview
import (
- "errors"
"fmt"
"io"
"io/ioutil"
@@ -28,10 +27,6 @@ func (Open) Complete(aerc *widgets.Aerc, args []string) []string {
}
func (Open) Execute(aerc *widgets.Aerc, args []string) error {
- if len(args) != 1 {
- return errors.New("Usage: open")
- }
-
mv := aerc.SelectedTab().(*widgets.MessageViewer)
p := mv.SelectedMessagePart()
@@ -60,9 +55,22 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
return
}
- lib.OpenFile(tmpFile.Name(), func(err error) {
- aerc.PushError(" " + err.Error())
- })
+ xdg := lib.NewXDGOpen(tmpFile.Name())
+ // pass through any arguments the user provided to the underlying handler
+ if len(args) > 1 {
+ xdg.SetArgs(args[1:])
+ }
+ err = xdg.Start()
+ if err != nil {
+ aerc.PushError(err.Error())
+ return
+ }
+ go func() {
+ err := xdg.Wait()
+ if err != nil {
+ aerc.PushError(" " + err.Error())
+ }
+ }()
aerc.PushStatus("Opened", 10*time.Second)
})