From c78e4a0b02321c603fb7f076b250f985e58274e2 Mon Sep 17 00:00:00 2001 From: Leigh MacDonald Date: Wed, 15 Mar 2023 02:02:34 -0600 Subject: [PATCH] Fix discord presence setting not saving. --- internal/detector/discord.go | 1 + internal/model/settings.go | 6 ++++++ internal/ui/settings.go | 1 + pkg/discord/client/client.go | 11 ++++++----- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/detector/discord.go b/internal/detector/discord.go index 6533649..35d4a35 100644 --- a/internal/detector/discord.go +++ b/internal/detector/discord.go @@ -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 } diff --git a/internal/model/settings.go b/internal/model/settings.go index 1d1b52f..5eb2926 100644 --- a/internal/model/settings.go +++ b/internal/model/settings.go @@ -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() diff --git a/internal/ui/settings.go b/internal/ui/settings.go index cfe8b30..c9abe84 100644 --- a/internal/ui/settings.go +++ b/internal/ui/settings.go @@ -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()) diff --git a/pkg/discord/client/client.go b/pkg/discord/client/client.go index c954621..9b23b87 100644 --- a/pkg/discord/client/client.go +++ b/pkg/discord/client/client.go @@ -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 @@ -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()