From d84eb56c21594b7ec8cb669870ea2ede8420441e Mon Sep 17 00:00:00 2001 From: Siyuan Date: Tue, 18 Nov 2025 10:47:58 +0000 Subject: [PATCH] feat: allow to override max restart attempts --- config.go | 1 + internal/native/proxy.go | 11 +++++++++-- native.go | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 5a3e7dc8..9beaee02 100644 --- a/config.go +++ b/config.go @@ -107,6 +107,7 @@ type Config struct { DefaultLogLevel string `json:"default_log_level"` VideoSleepAfterSec int `json:"video_sleep_after_sec"` VideoQualityFactor float64 `json:"video_quality_factor"` + NativeMaxRestart uint `json:"native_max_restart_attempts"` } func (c *Config) GetDisplayRotation() uint16 { diff --git a/internal/native/proxy.go b/internal/native/proxy.go index 344f306e..830d3ebe 100644 --- a/internal/native/proxy.go +++ b/internal/native/proxy.go @@ -57,7 +57,9 @@ func (n *NativeOptions) toProxyOptions() *nativeProxyOptions { // random 16 bytes hex string handshakeMessage := randomId(16) maxRestartAttempts := defaultMaxRestartAttempts - if n.MaxRestartAttempts > 0 { + // though it's unlikely to be less than 0 as it's uint, we'll add it just in case + // until we have a proper unit test for all things :-( + if n.MaxRestartAttempts <= 0 { maxRestartAttempts = n.MaxRestartAttempts } return &nativeProxyOptions{ @@ -330,7 +332,12 @@ func (p *NativeProxy) start() error { return fmt.Errorf("failed to start native process: %w", err) } - p.logger.Info().Int("pid", p.cmd.Process.Pid).Msg("native process started") + // here we'll replace the logger with a new one that includes the process ID + // there's no need to lock the mutex here as the side effect is acceptable + newLogger := p.logger.With().Int("pid", p.cmd.Process.Pid).Logger() + p.logger = &newLogger + + p.logger.Info().Msg("native process started") if err := p.setUpGRPCClient(); err != nil { return fmt.Errorf("failed to set up gRPC client: %w", err) diff --git a/native.go b/native.go index b51aa9b6..5f09ef83 100644 --- a/native.go +++ b/native.go @@ -29,6 +29,7 @@ func initNative(systemVersion *semver.Version, appVersion *semver.Version) { AppVersion: appVersion, DisplayRotation: config.GetDisplayRotation(), DefaultQualityFactor: config.VideoQualityFactor, + MaxRestartAttempts: config.NativeMaxRestart, OnNativeRestart: func() { configureDisplayOnNativeRestart() },