Compare commits
No commits in common. "master" and "v0.0.1" have entirely different histories.
@ -60,8 +60,10 @@ 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
|
||||
}
|
||||
@ -84,7 +86,6 @@ 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()}
|
||||
@ -94,14 +95,9 @@ 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)
|
||||
@ -113,25 +109,20 @@ 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 {
|
||||
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.Printf("retrying in 100 milliseconds...")
|
||||
log.Println("retrying in 100 milliseconds...")
|
||||
} else {
|
||||
log.Printf("cannot set activity: %v", err)
|
||||
}
|
||||
fyne.DoAndWait(func() { uiSetFailureState(false) })
|
||||
}
|
||||
fyne.DoAndWait(func() { uiSetFailureState(true) })
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -375,11 +375,15 @@ 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