mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Start browser on server start (#1832)
* Start browser on server start * Add config option for opening browser
This commit is contained in:
committed by
GitHub
parent
29b14ab4fc
commit
87036a07bc
@@ -19,6 +19,7 @@ var once sync.Once
|
||||
type flagStruct struct {
|
||||
configFilePath string
|
||||
cpuProfilePath string
|
||||
nobrowser bool
|
||||
}
|
||||
|
||||
func Initialize() (*Instance, error) {
|
||||
@@ -42,6 +43,7 @@ func Initialize() (*Instance, error) {
|
||||
}
|
||||
|
||||
if !instance.isNewSystem {
|
||||
setExistingSystemDefaults(instance)
|
||||
err = instance.SetInitialConfig()
|
||||
}
|
||||
})
|
||||
@@ -97,6 +99,28 @@ func initConfig(flags flagStruct) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// setExistingSystemDefaults sets config options that are new and unset in an existing install,
|
||||
// but should have a separate default than for brand-new systems, to maintain behavior.
|
||||
func setExistingSystemDefaults(instance *Instance) {
|
||||
if !instance.isNewSystem {
|
||||
configDirtied := false
|
||||
|
||||
// Existing systems as of the introduction of auto-browser open should retain existing
|
||||
// behavior and not start the browser automatically.
|
||||
if !viper.InConfig("nobrowser") {
|
||||
configDirtied = true
|
||||
viper.Set("nobrowser", "true")
|
||||
}
|
||||
|
||||
if configDirtied {
|
||||
err := viper.WriteConfig()
|
||||
if err != nil {
|
||||
logger.Errorf("Could not save existing system defaults: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func initFlags() flagStruct {
|
||||
flags := flagStruct{}
|
||||
|
||||
@@ -104,6 +128,7 @@ func initFlags() flagStruct {
|
||||
pflag.Int("port", 9999, "port to serve from")
|
||||
pflag.StringVarP(&flags.configFilePath, "config", "c", "", "config file to use")
|
||||
pflag.StringVar(&flags.cpuProfilePath, "cpuprofile", "", "write cpu profile to file")
|
||||
pflag.BoolVar(&flags.nobrowser, "nobrowser", false, "Don't open a browser window after launch")
|
||||
|
||||
pflag.Parse()
|
||||
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user