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.
This commit is contained in:
parent
3e6189f243
commit
fda3f43e7c
|
@ -115,6 +115,6 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func unsubscribeHTTP(u *url.URL) error {
|
func unsubscribeHTTP(u *url.URL) error {
|
||||||
go lib.OpenFile(u.String())
|
lib.OpenFile(u.String(), nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,10 +60,9 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = lib.OpenFile(tmpFile.Name())
|
lib.OpenFile(tmpFile.Name(), func(err error) {
|
||||||
if err != nil {
|
|
||||||
aerc.PushError(" " + err.Error())
|
aerc.PushError(" " + err.Error())
|
||||||
}
|
})
|
||||||
|
|
||||||
aerc.PushStatus("Opened", 10*time.Second)
|
aerc.PushStatus("Opened", 10*time.Second)
|
||||||
})
|
})
|
||||||
|
|
15
lib/open.go
15
lib/open.go
|
@ -6,7 +6,18 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenFile(filename string) error {
|
func OpenFile(filename string, onErr func(error)) {
|
||||||
cmd := exec.Command("xdg-open", filename)
|
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)
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,18 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenFile(filename string) error {
|
func OpenFile(filename string, onErr func(error)) {
|
||||||
cmd := exec.Command("open", filename)
|
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)
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue