Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
05b29229df | |||
2c7d251298 | |||
8eb33b2fc0 |
@ -60,10 +60,8 @@ type applyState struct {
|
||||
func (s *applyState) replace(t string) string {
|
||||
for k, f := range substitute {
|
||||
t = strings.ReplaceAll(t, "%"+k, f(s))
|
||||
go func() {
|
||||
replCounter.Add(uint64(len(t)))
|
||||
statusReplaces.SetText(strconv.Itoa(int(replCounter.Load())) + " bytes")
|
||||
}()
|
||||
}
|
||||
return t
|
||||
}
|
||||
@ -86,6 +84,7 @@ func apply() {
|
||||
act := *prof.Activity
|
||||
s := &applyState{}
|
||||
|
||||
fyne.DoAndWait(func() {
|
||||
act.State = s.replace(act.State)
|
||||
act.Details = s.replace(act.Details)
|
||||
act.Timestamps = &discord.ActivityTimestamps{Start: launchTime.Unix()}
|
||||
@ -95,9 +94,14 @@ func apply() {
|
||||
SmallImage: act.Assets.SmallImage,
|
||||
SmallText: s.replace(act.Assets.SmallText),
|
||||
}
|
||||
})
|
||||
confLock.RUnlock()
|
||||
|
||||
if nonce, err := retry(&act, s); err != nil {
|
||||
if errors.Is(err, syscall.EINTR) || errors.Is(err, discord.ErrNonce) {
|
||||
log.Printf("abandoned further attempts on current tick: %v", err)
|
||||
return
|
||||
}
|
||||
log.Fatalf("error setting activity: %s", err)
|
||||
} else {
|
||||
log.Printf("activity updated with nonce %s", nonce)
|
||||
@ -109,20 +113,25 @@ var retryTicker = time.NewTicker(100 * time.Millisecond)
|
||||
func retry(act *discord.Activity, s *applyState) (nonce string, err error) {
|
||||
fyne.DoAndWait(func() { uiUpdateClientInfo(s) })
|
||||
|
||||
i := 0
|
||||
for range retryTicker.C {
|
||||
nonce, err = d.SetActivity(act)
|
||||
if err == nil {
|
||||
if i == 5 {
|
||||
break
|
||||
}
|
||||
nonce, err = d.SetActivity(act)
|
||||
if err == nil {
|
||||
fyne.DoAndWait(func() { uiSetFailureState(true) })
|
||||
break
|
||||
}
|
||||
i++
|
||||
|
||||
if errors.Is(err, syscall.EINTR) || errors.Is(err, discord.ErrNonce) {
|
||||
log.Println("retrying in 100 milliseconds...")
|
||||
log.Printf("retrying in 100 milliseconds...")
|
||||
} else {
|
||||
log.Printf("cannot set activity: %v", err)
|
||||
}
|
||||
fyne.DoAndWait(func() { uiSetFailureState(false) })
|
||||
}
|
||||
fyne.DoAndWait(func() { uiSetFailureState(true) })
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -375,15 +375,11 @@ func ui() error {
|
||||
presetUp.SetIcon(theme.MoveUpIcon())
|
||||
presetDown.SetIcon(theme.MoveDownIcon())
|
||||
|
||||
go func() {
|
||||
for range time.Tick(time.Second) {
|
||||
fyne.DoAndWait(func() { statusTimer.SetText(time.Now().UTC().Sub(launchTime).Round(time.Second).String()) })
|
||||
}
|
||||
}()
|
||||
|
||||
active.Store(true)
|
||||
go func() {
|
||||
for range time.Tick(1 * time.Second) {
|
||||
fyne.DoAndWait(func() { statusTimer.SetText(time.Now().UTC().Sub(launchTime).Round(time.Second).String()) })
|
||||
|
||||
if active.Load() {
|
||||
apply()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user