feat: panic on max restart attempts

This commit is contained in:
Siyuan 2025-11-13 14:29:55 +00:00
parent afd8ab75bc
commit 6e9d846471
2 changed files with 12 additions and 1 deletions

View File

@ -33,6 +33,7 @@ type NativeOptions struct {
AppVersion *semver.Version
DisplayRotation uint16
DefaultQualityFactor float64
MaxRestartAttempts uint
OnVideoStateChange func(state VideoState)
OnVideoFrameReceived func(frame []byte, duration time.Duration)
OnIndevEvent func(event string)

View File

@ -20,6 +20,7 @@ import (
const (
maxFrameSize = 1920 * 1080 / 2
defaultMaxRestartAttempts uint = 5
)
type nativeProxyOptions struct {
@ -55,6 +56,10 @@ func randomId(binaryLength int) string {
func (n *NativeOptions) toProxyOptions() *nativeProxyOptions {
// random 16 bytes hex string
handshakeMessage := randomId(16)
maxRestartAttempts := defaultMaxRestartAttempts
if n.MaxRestartAttempts > 0 {
maxRestartAttempts = n.MaxRestartAttempts
}
return &nativeProxyOptions{
Disable: n.Disable,
SystemVersion: n.SystemVersion,
@ -67,6 +72,7 @@ func (n *NativeOptions) toProxyOptions() *nativeProxyOptions {
OnVideoStateChange: n.OnVideoStateChange,
OnNativeRestart: n.OnNativeRestart,
HandshakeMessage: handshakeMessage,
MaxRestartAttempts: maxRestartAttempts,
}
}
@ -405,6 +411,10 @@ func (p *NativeProxy) restartProcess() error {
}
p.restarts++
if p.restarts >= p.options.MaxRestartAttempts {
p.logger.Fatal().Msg("max restart attempts reached, exiting")
return fmt.Errorf("max restart attempts reached")
}
if err := p.start(); err != nil {
return fmt.Errorf("failed to start native process: %w", err)