pwa-launcher/pkg/browsers.go

37 lines
932 B
Go

package app
import (
"errors"
"fmt"
"os"
"strings"
)
// Preferred browsers list.
var browsers = []string{
"/usr/bin/firefox",
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
"/usr/bin/google-chrome",
}
// DetectBrowser auto-detects a preferred web browser and returns its path.
func DetectBrowser() (string, error) {
for _, path := range browsers {
if _, err := os.Stat(path); err == nil {
return path, nil
}
}
return "", errors.New("failed to auto-detect a web browser")
}
// DetectExec auto-detects the exec line syntax for the selected browser.
func DetectExec(browser string) (string, error) {
if strings.Contains(browser, "firefox") {
return fmt.Sprintf("%s --ssb %%s", browser), nil
} else if strings.Contains(browser, "chromium") || strings.Contains(browser, "chrome") {
return fmt.Sprintf("%s --app=%%s", browser), nil
}
return "", errors.New("failed to auto-detect the browser exec line")
}