Files
Ant-Browser/backend/browser_start_settings.go
Ant Browser Release Bot 3d264eb83d publish: 1.1.0 snapshot (a358335)
channel: master
version: 1.1.0
source-ref: master
published-at-utc: 2026-03-29T11:32:04Z
2026-03-29 19:32:05 +08:00

54 lines
1.2 KiB
Go

package backend
import (
"ant-chrome/backend/internal/config"
"errors"
"time"
)
const (
defaultBrowserStartReadyTimeout = 3 * time.Second
defaultBrowserStartStableWindow = 1200 * time.Millisecond
defaultBrowserStartMaxAttempts = 5
)
func browserStartReadyTimeoutMillis(cfg *config.Config) int {
fallback := int(defaultBrowserStartReadyTimeout / time.Millisecond)
if cfg == nil {
return fallback
}
if cfg.Browser.StartReadyTimeoutMs > 0 {
return cfg.Browser.StartReadyTimeoutMs
}
return fallback
}
func browserStartStableWindowMillis(cfg *config.Config) int {
fallback := int(defaultBrowserStartStableWindow / time.Millisecond)
if cfg == nil {
return fallback
}
if cfg.Browser.StartStableWindowMs > 0 {
return cfg.Browser.StartStableWindowMs
}
return fallback
}
func (a *App) browserStartTimingSettings() (time.Duration, time.Duration) {
return time.Duration(browserStartReadyTimeoutMillis(a.config)) * time.Millisecond,
time.Duration(browserStartStableWindowMillis(a.config)) * time.Millisecond
}
func browserStartAttemptCount() int {
return defaultBrowserStartMaxAttempts
}
func shouldRetryBrowserReadyFailure(err error) bool {
if err == nil {
return false
}
var exitErr *browserStartupExitError
return !errors.As(err, &exitErr)
}