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