Skip to content

Commit

Permalink
Fix discord presence setting not saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Mar 15, 2023
1 parent eaa131d commit c78e4a0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions internal/detector/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (bd *BD) discordStateUpdater(ctx context.Context) {
bd.logger.Error("Failed to logout of discord client", zap.Error(errLogout))
// continue?
}
isRunning = false
}
continue
}
Expand Down
6 changes: 6 additions & 0 deletions internal/model/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ func (s *Settings) GetAutoLaunchGame() bool {
return s.AutoLaunchGame
}

func (s *Settings) SetDiscordPresenceEnabled(enabled bool) {
s.Lock()
defer s.Unlock()
s.DiscordPresenceEnabled = enabled
}

func (s *Settings) GetDiscordPresenceEnabled() bool {
s.RLock()
defer s.RUnlock()
Expand Down
1 change: 1 addition & 0 deletions internal/ui/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func newSettingsDialog(logger *zap.Logger, parent fyne.Window, origSettings *mod
origSettings.SetAutoLaunchGame(autoLaunchGameEntry.Checked)
origSettings.SetVoiceBansEnabled(voiceBanEnabledEntry.Checked)
origSettings.SetDebugLogEnabled(debugLogEnabledEntry.Checked)
origSettings.SetDiscordPresenceEnabled(discordPresenceEnabledEntry.Checked)
origSettings.SetLinks(settings.GetLinks())
origSettings.SetLists(settings.GetLists())

Expand Down
11 changes: 6 additions & 5 deletions pkg/discord/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/pkg/errors"
"go.uber.org/zap"
"os"
"sync/atomic"
"time"
)

var logged bool
var logged atomic.Bool
var logger *zap.Logger

func Login(clientID string) error {
if !logged {
if !logged.Load() {
payload, errMarshal := json.Marshal(Handshake{"1", clientID})
if errMarshal != nil {
return errMarshal
Expand All @@ -28,17 +29,17 @@ func Login(clientID string) error {
return errSend
}
}
logged = true
logged.Store(true)
return nil
}

func Logout() error {
logged = false
logged.Store(false)
return ipc.Close()
}

func SetActivity(activity Activity) error {
if !logged {
if !logged.Load() {
return nil
}
nonce, errNonce := getNonce()
Expand Down

0 comments on commit c78e4a0

Please sign in to comment.