Add even more hacky workarounds for connecting after google login
This commit is contained in:
parent
cf698ed7d6
commit
42d56b9e71
3 changed files with 30 additions and 1 deletions
|
@ -168,12 +168,13 @@ func (c *Client) postConnect() {
|
|||
time.Sleep(2 * time.Second)
|
||||
if c.skipCount > 0 {
|
||||
c.Logger.Warn().Int("skip_count", c.skipCount).Msg("Skip count is non-zero in postConnect, waiting longer")
|
||||
for i := 0; i < 10 && c.skipCount > 0; i++ {
|
||||
for i := 0; i < 3 && c.skipCount > 0; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
if c.skipCount > 0 {
|
||||
c.Logger.Warn().Int("skip_count", c.skipCount).Msg("Skip count is still non-zero")
|
||||
}
|
||||
c.triggerEvent(&events.HackySetActiveMayFail{})
|
||||
}
|
||||
c.Logger.Debug().Msg("Sending acks before get updates request")
|
||||
c.sessionHandler.sendAckRequest()
|
||||
|
|
|
@ -92,3 +92,5 @@ type PingFailed struct {
|
|||
Error error
|
||||
ErrorCount int
|
||||
}
|
||||
|
||||
type HackySetActiveMayFail struct{}
|
||||
|
|
26
user.go
26
user.go
|
@ -81,6 +81,7 @@ type User struct {
|
|||
batteryLowAlertSent time.Time
|
||||
pollErrorAlertSent bool
|
||||
phoneNotRespondingAlertSent bool
|
||||
didHackySetActive bool
|
||||
|
||||
loginInProgress atomic.Bool
|
||||
pairSuccessChan chan struct{}
|
||||
|
@ -644,6 +645,7 @@ func (user *User) HasSession() bool {
|
|||
func (user *User) DeleteSession() {
|
||||
user.Session = nil
|
||||
user.SelfParticipantIDs = []string{}
|
||||
user.didHackySetActive = false
|
||||
err := user.Update(context.TODO())
|
||||
if err != nil {
|
||||
user.zlog.Err(err).Msg("Failed to delete session from database")
|
||||
|
@ -673,6 +675,28 @@ func (user *User) sendMarkdownBridgeAlert(ctx context.Context, important bool, f
|
|||
}
|
||||
}
|
||||
|
||||
func (user *User) hackyResetActive() {
|
||||
if user.didHackySetActive {
|
||||
return
|
||||
}
|
||||
user.didHackySetActive = true
|
||||
time.Sleep(7 * time.Second)
|
||||
if !user.ready && user.phoneResponding {
|
||||
user.zlog.Warn().Msg("Client is still not ready, trying to re-set active session")
|
||||
err := user.Client.SetActiveSession()
|
||||
if err != nil {
|
||||
user.zlog.Err(err).Msg("Failed to re-set active session")
|
||||
} else {
|
||||
time.Sleep(7 * time.Second)
|
||||
}
|
||||
if !user.ready && user.phoneResponding {
|
||||
user.zlog.Warn().Msg("Client is still not ready, reconnecting")
|
||||
user.DeleteConnection()
|
||||
user.Connect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) syncHandleEvent(event any) {
|
||||
ctx := context.TODO()
|
||||
switch v := event.(type) {
|
||||
|
@ -716,6 +740,8 @@ func (user *User) syncHandleEvent(event any) {
|
|||
go user.sendMarkdownBridgeAlert(ctx, false, "Phone is responding again")
|
||||
user.phoneNotRespondingAlertSent = false
|
||||
}
|
||||
case *events.HackySetActiveMayFail:
|
||||
go user.hackyResetActive()
|
||||
case *events.PingFailed:
|
||||
if errors.Is(v.Error, events.ErrRequestedEntityNotFound) {
|
||||
go user.Logout(status.BridgeState{
|
||||
|
|
Loading…
Reference in a new issue