From 6ccfba976f2dafede1d6a64ee2558fa7ea485786 Mon Sep 17 00:00:00 2001 From: nikitar020 <42252263+nikitar020@users.noreply.github.com> Date: Wed, 30 Jan 2019 15:43:15 +0000 Subject: [PATCH] Make launching URLs on Windows work (#185) --- gui/gui.go | 16 ++++------------ platform/darwinLaunch.go | 11 +++++++++++ platform/linuxLaunch.go | 11 +++++++++++ platform/winLaunch.go | 11 +++++++++++ 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 platform/darwinLaunch.go create mode 100644 platform/linuxLaunch.go create mode 100644 platform/winLaunch.go diff --git a/gui/gui.go b/gui/gui.go index ace0b0e..134d33e 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -6,7 +6,6 @@ import ( "image/png" "math" "os" - "os/exec" "runtime" "strconv" "strings" @@ -23,6 +22,7 @@ import ( "github.com/liamg/aminal/terminal" "github.com/liamg/aminal/version" "go.uber.org/zap" + "github.com/liamg/aminal/platform" ) type GUI struct { @@ -638,17 +638,9 @@ func (gui *GUI) createProgram() (uint32, error) { func (gui *GUI) launchTarget(target string) { - cmd := "xdg-open" - - switch runtime.GOOS { - case "darwin": - cmd = "open" - case "windows": - cmd = "start" - } - - if err := exec.Command(cmd, target).Run(); err != nil { - gui.logger.Errorf("Failed to launch external command %s: %s", cmd, err) + err := platform.LaunchTarget(target) + if err != nil { + gui.logger.Errorf("Failed to launch target %s: %s", target, err) } } diff --git a/platform/darwinLaunch.go b/platform/darwinLaunch.go new file mode 100644 index 0000000..1b2dd44 --- /dev/null +++ b/platform/darwinLaunch.go @@ -0,0 +1,11 @@ +// +build darwin + +package platform + +import ( + "os/exec" +) + +func LaunchTarget(target string) error { + return exec.Command("open", target).Run() +} \ No newline at end of file diff --git a/platform/linuxLaunch.go b/platform/linuxLaunch.go new file mode 100644 index 0000000..0e97c0c --- /dev/null +++ b/platform/linuxLaunch.go @@ -0,0 +1,11 @@ +// +build linux + +package platform + +import ( + "os/exec" +) + +func LaunchTarget(target string) error { + return exec.Command("xdg-open", target).Run() +} diff --git a/platform/winLaunch.go b/platform/winLaunch.go new file mode 100644 index 0000000..55fef4d --- /dev/null +++ b/platform/winLaunch.go @@ -0,0 +1,11 @@ +// +build windows + +package platform + +import ( + "github.com/MaxRis/w32" +) + +func LaunchTarget(target string) error { + return w32.ShellExecute(0, "", target, "", "", w32.SW_SHOW) +} \ No newline at end of file