From fda3f43e7c5e5a175a01dd3e5b8637b1ecb30c51 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Mon, 6 Jul 2020 20:14:15 +0100 Subject: Allow open to be asynchronous This stops the ui being blocked while the resource is opened. The wait ensures that resources are reclaimed when the process finishes while aerc is still running. --- lib/open.go | 15 +++++++++++++-- lib/open_darwin.go | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/open.go b/lib/open.go index ad6533e1..ebcf8780 100644 --- a/lib/open.go +++ b/lib/open.go @@ -6,7 +6,18 @@ import ( "os/exec" ) -func OpenFile(filename string) error { +func OpenFile(filename string, onErr func(error)) { cmd := exec.Command("xdg-open", filename) - return cmd.Run() + err := cmd.Start() + if err != nil && onErr != nil { + onErr(err) + return + } + + go func() { + err := cmd.Wait() + if err != nil && onErr != nil { + onErr(err) + } + }() } diff --git a/lib/open_darwin.go b/lib/open_darwin.go index 0ffd9a16..d98c8988 100644 --- a/lib/open_darwin.go +++ b/lib/open_darwin.go @@ -4,7 +4,18 @@ import ( "os/exec" ) -func OpenFile(filename string) error { +func OpenFile(filename string, onErr func(error)) { cmd := exec.Command("open", filename) - return cmd.Run() + err := cmd.Start() + if err != nil && onErr != nil { + onErr(err) + return + } + + go func() { + err := cmd.Wait() + if err != nil && onErr != nil { + onErr(err) + } + }() } -- cgit