diff options
author | Robin Jarry <robin@jarry.cc> | 2022-09-30 10:52:49 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-01 15:46:49 +0200 |
commit | 92ba132d70fe1d9afabe3cf4f23376025ccff897 (patch) | |
tree | 9be550d0c25c9d0367a144317312774d3e3c53e4 /commands/msgview/open.go | |
parent | 8e53d330614fb5c526372e6bdf508341bb6f154c (diff) | |
download | aerc-92ba132d70fe1d9afabe3cf4f23376025ccff897.tar.gz |
open: simplify code
There is no need for convoluted channels and other async fanciness.
Expose a single XDGOpen static function that runs a command and returns
an error if any.
Caller is responsible of running this in an async goroutine if needed.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands/msgview/open.go')
-rw-r--r-- | commands/msgview/open.go | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/commands/msgview/open.go b/commands/msgview/open.go index f3723fbc..82c1accb 100644 --- a/commands/msgview/open.go +++ b/commands/msgview/open.go @@ -5,11 +5,9 @@ import ( "io" "mime" "os" - "time" "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib" - "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -40,8 +38,8 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error { if args[0] == "open-link" && len(args) > 1 { if link := args[1]; link != "" { go func() { - if err := lib.NewXDGOpen(link).Start(); err != nil { - aerc.PushError(fmt.Sprintf("%s: %s", args[0], err.Error())) + if err := lib.XDGOpen(link); err != nil { + aerc.PushError("open: " + err.Error()) } }() } @@ -64,34 +62,20 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error { aerc.PushError(err.Error()) return } - defer tmpFile.Close() _, err = io.Copy(tmpFile, reader) + tmpFile.Close() if err != nil { aerc.PushError(err.Error()) return } - 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() { - defer logging.PanicHandler() - - err := xdg.Wait() + err = lib.XDGOpen(tmpFile.Name()) if err != nil { - aerc.PushError(err.Error()) + aerc.PushError("open: " + err.Error()) } }() - - aerc.PushStatus("Opened", 10*time.Second) }) return nil |