// TODO: Use a host like tlz.localhost to serve HTTP/2 over HTTPS... just need to automate the CA and cert... - or maybe a public domain like timelinize.app or timelinize.run or something
startedServer, err := app.Serve()
if err != nil {
timeline.Log.Fatal("could not start server", zap.Error(err))
}
// once the server is running, open GUI in web browser
if err := openWebBrowser("http://127.0.0.1:12002"); err != nil {
timeline.Log.Error("could not open web browser", zap.Error(err))
}
if startedServer {
select {}
}
}
// openWebBrowser opens the web browser to loc, which must be a
// fully-qualified URL including a trailing slash even if there
// is no path (e.g. "http://host/" not "http://host"); if the
// trailing slash is not present, it will be appended.
func openWebBrowser(loc string) error {
osCommand := map[string][]string{
"darwin": {"open"},
"freebsd": {"xdg-open"},
"linux": {"xdg-open"}, // requires xdg-utils; TODO: also try sensible-browser, or gnome-open
"netbsd": {"xdg-open"},
"openbsd": {"xdg-open"},
"windows": {"cmd", "/c", "start"},
}
// ensure URL is valid and path ends with a trailing slash
u, err := url.Parse(loc)
if err != nil {
return err
}
if !strings.HasSuffix(u.Path, "/") {
u.Path += "/"
}
loc = u.String()
if runtime.GOOS == "windows" {
// escape characters not allowed by cmd
loc = strings.ReplaceAll(loc, "&", `^&`)
}
all := append(osCommand[runtime.GOOS], loc) //nolint:gocritic
exe := all[0]
args := all[1:]
timeline.Log.Info("opening web browser to application",