From 114940eef67491d6eefbb63b575599024726c82d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 24 Oct 2020 15:35:40 +0300 Subject: [PATCH] Update exec.Command on all OSes --- lib/open/open.go | 14 +++++++++----- lib/open/open_darwin.go | 25 ++----------------------- lib/open/open_windows.go | 8 ++------ lib/open/open_xdg.go | 6 ++++++ 4 files changed, 19 insertions(+), 34 deletions(-) create mode 100644 lib/open/open_xdg.go diff --git a/lib/open/open.go b/lib/open/open.go index 935018f..c128494 100644 --- a/lib/open/open.go +++ b/lib/open/open.go @@ -1,5 +1,3 @@ -// +build !windows,!darwin - // gomuks - A terminal Matrix client written in Go. // Copyright (C) 2020 Tulir Asokan // @@ -20,16 +18,22 @@ package open import ( "os/exec" + "maunium.net/go/gomuks/debug" ) func Open(input string) error { - cmd := exec.Command("xdg-open", input) + cmd := exec.Command(Command, append(Args, input)...) err := cmd.Start() if err != nil { - debug.Print("xdg-open error:", err) + debug.Printf("Failed to start %s: %v", Command, err) } else { - go cmd.Wait() + go func() { + waitErr := cmd.Wait() + if waitErr != nil { + debug.Printf("Failed to run %s: %v", Command, err) + } + }() } return err } diff --git a/lib/open/open_darwin.go b/lib/open/open_darwin.go index 7a35818..625ec54 100644 --- a/lib/open/open_darwin.go +++ b/lib/open/open_darwin.go @@ -1,25 +1,4 @@ -// gomuks - A terminal Matrix client written in Go. -// Copyright (C) 2020 Tulir Asokan -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - package open -import ( - "os/exec" -) - -func Open(input string) error { - return exec.Command("open", input).Start() -} +const Command = "open" +var Args []string diff --git a/lib/open/open_windows.go b/lib/open/open_windows.go index eee606b..1586e2b 100644 --- a/lib/open/open_windows.go +++ b/lib/open/open_windows.go @@ -18,14 +18,10 @@ package open import ( "os" - "os/exec" "path/filepath" ) const FileProtocolHandler = "url.dll,FileProtocolHandler" -var RunDLL32 = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe") - -func Open(input string) error { - return exec.Command(RunDLL32, FileProtocolHandler, input).Start() -} +var Command = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "rundll32.exe") +var Args = []string{FileProtocolHandler} diff --git a/lib/open/open_xdg.go b/lib/open/open_xdg.go new file mode 100644 index 0000000..e107a8a --- /dev/null +++ b/lib/open/open_xdg.go @@ -0,0 +1,6 @@ +// +build !windows,!darwin + +package open + +const Command = "xdg-open" +var Args []string