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 AppVersion *semver.Version
DisplayRotation uint16 DisplayRotation uint16
DefaultQualityFactor float64 DefaultQualityFactor float64
MaxRestartAttempts uint
OnVideoStateChange func(state VideoState) OnVideoStateChange func(state VideoState)
OnVideoFrameReceived func(frame []byte, duration time.Duration) OnVideoFrameReceived func(frame []byte, duration time.Duration)
OnIndevEvent func(event string) OnIndevEvent func(event string)

View File

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