60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
|
|
app "./pkg"
|
|
)
|
|
|
|
// CLI flags
|
|
var (
|
|
title string
|
|
icon string
|
|
browser string
|
|
browserExec string
|
|
url string
|
|
)
|
|
|
|
func init() {
|
|
flag.StringVar(&title, "title", "", "App launcher title, default uses the web page title")
|
|
flag.StringVar(&icon, "icon", "", "App icon image (filesystem or URL), default uses the site favicon")
|
|
flag.StringVar(&browser, "browser", "", "Browser executable, full path or command, default firefox or chromium")
|
|
flag.StringVar(&browserExec, "exec", "", "Manually provide the browser exec string, like `firefox --ssb %s` or `chromium --app=%s`, "+
|
|
"default is auto-detected based on Firefox and Chrome/ium.")
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
// Detect defaults.
|
|
if browser == "" {
|
|
detected, err := app.DetectBrowser()
|
|
if err != nil {
|
|
panic("Failed to detect your web browser. Provide the -browser or -exec options to set one manually")
|
|
}
|
|
browser = detected
|
|
log.Printf("Detected browser: %s", browser)
|
|
}
|
|
if browserExec == "" {
|
|
detected, err := app.DetectExec(browser)
|
|
if err != nil {
|
|
panic("Failed to detect the browser exec line. Provide the -exec option to set one manually")
|
|
}
|
|
browserExec = detected
|
|
log.Printf("Browser exec line for PWA: '%s'", browserExec)
|
|
}
|
|
|
|
url = flag.Arg(0)
|
|
if url == "" {
|
|
panic("Usage: pwa-launcher [options] <url>")
|
|
}
|
|
|
|
app.Run(app.Parameters{
|
|
Title: title,
|
|
URL: url,
|
|
Exec: browserExec,
|
|
Icon: icon,
|
|
})
|
|
}
|