Skip to content

Commit

Permalink
Merge pull request #252 from SiaFoundation/nate/auto-open-flag
Browse files Browse the repository at this point in the history
Add flag to disable automatically opening the browser
  • Loading branch information
n8maninger authored Dec 30, 2023
2 parents 71eeb1e + cd70e3f commit 40b4f67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/hostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
cfg = config.Config{
Directory: ".", // default to current directory
RecoveryPhrase: os.Getenv(walletSeedEnvVariable), // default to env variable
AutoOpenWebUI: true,

HTTP: config.HTTP{
Address: defaultAPIAddr,
Expand Down Expand Up @@ -256,6 +257,7 @@ func main() {
flag.StringVar(&cfg.Name, "name", cfg.Name, "a friendly name for the host, only used for display")
flag.StringVar(&cfg.Directory, "dir", cfg.Directory, "directory to store hostd metadata")
flag.BoolVar(&disableStdin, "env", false, "disable stdin prompts for environment variables (default false)")
flag.BoolVar(&cfg.AutoOpenWebUI, "openui", cfg.AutoOpenWebUI, "automatically open the web UI on startup")
// consensus
flag.StringVar(&cfg.Consensus.GatewayAddress, "rpc", cfg.Consensus.GatewayAddress, "address to listen on for peer connections")
flag.BoolVar(&cfg.Consensus.Bootstrap, "bootstrap", cfg.Consensus.Bootstrap, "bootstrap the gateway and consensus modules")
Expand Down Expand Up @@ -404,12 +406,14 @@ func main() {
}
}()

time.Sleep(time.Millisecond) // give the web server a chance to start
_, port, err := net.SplitHostPort(apiListener.Addr().String())
if err != nil {
log.Debug("failed to parse API address", zap.Error(err))
} else if err := openBrowser(fmt.Sprintf("http://127.0.0.1:%s", port)); err != nil {
log.Debug("failed to open browser", zap.Error(err))
if cfg.AutoOpenWebUI {
time.Sleep(time.Millisecond) // give the web server a chance to start
_, port, err := net.SplitHostPort(apiListener.Addr().String())
if err != nil {
log.Debug("failed to parse API address", zap.Error(err))
} else if err := openBrowser(fmt.Sprintf("http://127.0.0.1:%s", port)); err != nil {
log.Debug("failed to open browser", zap.Error(err))
}
}

signalCh := make(chan os.Signal, 1)
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type (
Name string `yaml:"name"`
Directory string `yaml:"directory"`
RecoveryPhrase string `yaml:"recoveryPhrase"`
AutoOpenWebUI bool `yaml:"autoOpenWebUI"`

HTTP HTTP `yaml:"http"`
Consensus Consensus `yaml:"consensus"`
Expand Down

0 comments on commit 40b4f67

Please sign in to comment.