forked from sloum/bombadillo
Merge pull request 'Uses 'linux' OpenInBrowser settings for any non-darwin and non-windows os' (#180) from fixes-browser-opening-for-bsd into release2.3.2
Reviewed-on: sloum/bombadillo#180
This commit is contained in:
commit
f8a9465eaf
|
@ -1,4 +1,4 @@
|
||||||
// +build darwin
|
// This will build for osx without a build tag based on the filename
|
||||||
|
|
||||||
package http
|
package http
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
// +build linux
|
|
||||||
|
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
// OpenInBrowser checks for the presence of a display server
|
|
||||||
// and environment variables indicating a gui is present. If found
|
|
||||||
// then xdg-open is called on a url to open said url in the default
|
|
||||||
// gui web browser for the system
|
|
||||||
func OpenInBrowser(url string) (string, error) {
|
|
||||||
disp := os.Getenv("DISPLAY")
|
|
||||||
wayland := os.Getenv("WAYLAND_DISPLAY")
|
|
||||||
_, err := exec.LookPath("Xorg")
|
|
||||||
if disp == "" && wayland == "" && err != nil {
|
|
||||||
return "", fmt.Errorf("No gui is available, check 'webmode' setting")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use start rather than run or output in order
|
|
||||||
// to release the process and not block
|
|
||||||
err = exec.Command("xdg-open", url).Start()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return "Opened in system default web browser", nil
|
|
||||||
}
|
|
|
@ -1,11 +1,30 @@
|
||||||
// +build !linux
|
// +build !darwin,!windows
|
||||||
// +build !darwin
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package http
|
package http
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OpenInBrowser checks for the presence of a display server
|
||||||
|
// and environment variables indicating a gui is present. If found
|
||||||
|
// then xdg-open is called on a url to open said url in the default
|
||||||
|
// gui web browser for the system
|
||||||
func OpenInBrowser(url string) (string, error) {
|
func OpenInBrowser(url string) (string, error) {
|
||||||
return "", fmt.Errorf("Unsupported os for 'webmode' 'gui' setting")
|
disp := os.Getenv("DISPLAY")
|
||||||
|
wayland := os.Getenv("WAYLAND_DISPLAY")
|
||||||
|
_, err := exec.LookPath("Xorg")
|
||||||
|
if disp == "" && wayland == "" && err != nil {
|
||||||
|
return "", fmt.Errorf("No gui is available, check 'webmode' setting")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use start rather than run or output in order
|
||||||
|
// to release the process and not block
|
||||||
|
err = exec.Command("xdg-open", url).Start()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return "Opened in system default web browser", nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// +build windows
|
// This will only build for windows based on the filename
|
||||||
|
// no build tag required
|
||||||
package http
|
package http
|
||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user