Start browser on server start (#1832)

* Start browser on server start
* Add config option for opening browser
This commit is contained in:
kermieisinthehouse
2021-10-28 16:19:23 -07:00
committed by GitHub
parent 29b14ab4fc
commit 87036a07bc
24 changed files with 356 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import (
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/gorilla/websocket"
"github.com/pkg/browser"
"github.com/rs/cors"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
@@ -243,12 +244,26 @@ func Start(uiBox embed.FS, loginUIBox embed.FS) {
printVersion()
printLatestVersion(context.TODO())
logger.Infof("stash is listening on " + address)
if tlsConfig != nil {
displayAddress = "https://" + displayAddress + "/"
} else {
displayAddress = "http://" + displayAddress + "/"
}
// This can be done before actually starting the server, as modern browsers will
// automatically reload the page if a local port is closed at page load and then opened.
if !c.GetNoBrowserFlag() && manager.GetInstance().IsDesktop() {
err = browser.OpenURL(displayAddress)
if err != nil {
logger.Error("Could not open browser: " + err.Error())
}
}
if tlsConfig != nil {
logger.Infof("stash is running at https://" + displayAddress + "/")
logger.Infof("stash is running at " + displayAddress)
logger.Error(server.ListenAndServeTLS("", ""))
} else {
logger.Infof("stash is running at http://" + displayAddress + "/")
logger.Infof("stash is running at " + displayAddress)
logger.Error(server.ListenAndServe())
}
}()