-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use common avatar cache. Add shared callback struct.
- Loading branch information
1 parent
948adf7
commit 892c543
Showing
11 changed files
with
180 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ui | ||
|
||
import ( | ||
"fyne.io/fyne/v2" | ||
"github.com/leighmacdonald/steamid/v2/steamid" | ||
"sync" | ||
) | ||
|
||
type avatarCache struct { | ||
*sync.RWMutex | ||
userAvatar map[steamid.SID64]fyne.Resource | ||
} | ||
|
||
func (cache *avatarCache) SetAvatar(sid64 steamid.SID64, data []byte) { | ||
if !sid64.Valid() || data == nil { | ||
return | ||
} | ||
cache.Lock() | ||
cache.userAvatar[sid64] = fyne.NewStaticResource(sid64.String(), data) | ||
cache.Unlock() | ||
} | ||
|
||
func (cache *avatarCache) GetAvatar(sid64 steamid.SID64) fyne.Resource { | ||
cache.RLock() | ||
defer cache.RUnlock() | ||
av, found := cache.userAvatar[sid64] | ||
if found { | ||
return av | ||
} | ||
return resourceDefaultavatarJpg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.