Make launching URLs on Windows work (#185)

This commit is contained in:
nikitar020 2019-01-30 15:43:15 +00:00 committed by Liam Galvin
parent 9190afef8a
commit 6ccfba976f
4 changed files with 37 additions and 12 deletions

View File

@ -6,7 +6,6 @@ import (
"image/png" "image/png"
"math" "math"
"os" "os"
"os/exec"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -23,6 +22,7 @@ import (
"github.com/liamg/aminal/terminal" "github.com/liamg/aminal/terminal"
"github.com/liamg/aminal/version" "github.com/liamg/aminal/version"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/liamg/aminal/platform"
) )
type GUI struct { type GUI struct {
@ -638,17 +638,9 @@ func (gui *GUI) createProgram() (uint32, error) {
func (gui *GUI) launchTarget(target string) { func (gui *GUI) launchTarget(target string) {
cmd := "xdg-open" err := platform.LaunchTarget(target)
if err != nil {
switch runtime.GOOS { gui.logger.Errorf("Failed to launch target %s: %s", target, err)
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)
} }
} }

11
platform/darwinLaunch.go Normal file
View File

@ -0,0 +1,11 @@
// +build darwin
package platform
import (
"os/exec"
)
func LaunchTarget(target string) error {
return exec.Command("open", target).Run()
}

11
platform/linuxLaunch.go Normal file
View File

@ -0,0 +1,11 @@
// +build linux
package platform
import (
"os/exec"
)
func LaunchTarget(target string) error {
return exec.Command("xdg-open", target).Run()
}

11
platform/winLaunch.go Normal file
View File

@ -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)
}