diff --git a/libgm/events/ready.go b/libgm/events/ready.go index e9122af..0bfb6e0 100644 --- a/libgm/events/ready.go +++ b/libgm/events/ready.go @@ -82,5 +82,6 @@ type PhoneNotResponding struct{} type PhoneRespondingAgain struct{} type PingFailed struct { - Error error + Error error + ErrorCount int } diff --git a/libgm/longpoll.go b/libgm/longpoll.go index c47ea4b..7567ae2 100644 --- a/libgm/longpoll.go +++ b/libgm/longpoll.go @@ -25,28 +25,29 @@ const phoneNotRespondingTimeout = 30 * time.Second func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) { notResponding := false - pingFailed := false + pingFails := 0 exit := false onRespond := func() { if notResponding { log.Debug().Msg("Ditto ping succeeded, phone is back online") c.triggerEvent(&events.PhoneRespondingAgain{}) notResponding = false - pingFailed = false - } else if pingFailed { + pingFails = 0 + } else if pingFails > 0 { // TODO separate event? c.triggerEvent(&events.PhoneRespondingAgain{}) - pingFailed = false + pingFails = 0 } } doPing := func() { pingChan, err := c.NotifyDittoActivity() if err != nil { log.Err(err).Msg("Error notifying ditto activity") + pingFails++ c.triggerEvent(&events.PingFailed{ - Error: fmt.Errorf("failed to notify ditto activity: %w", err), + Error: fmt.Errorf("failed to notify ditto activity: %w", err), + ErrorCount: pingFails, }) - pingFailed = true return } select { diff --git a/user.go b/user.go index 2ba5e86..8eb7b77 100644 --- a/user.go +++ b/user.go @@ -598,12 +598,14 @@ func (user *User) syncHandleEvent(event any) { "go_error": v.Error.Error(), }, }, false) - } else { + } else if v.ErrorCount > 1 { user.BridgeState.Send(status.BridgeState{ StateEvent: status.StateUnknownError, Error: GMPingFailed, Info: map[string]any{"go_error": v.Error.Error()}, }) + } else { + user.zlog.Debug().Msg("Not sending unknown error for first ping fail") } case *events.PairSuccessful: user.Session = user.Client.AuthData