mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
channel: master version: 1.1.0 source-ref: master published-at-utc: 2026-03-29T11:32:04Z
54 lines
1.2 KiB
Go
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)
|
|
}
|