Harden icon cache concurrency (T-606)
This commit is contained in:
@@ -103,14 +103,19 @@ func (shell *AppShell) SetItems(items []application.CatalogListItem) {
|
||||
shell.model.SetItems(items)
|
||||
|
||||
nextRows := make(map[string]*rowControls, len(items))
|
||||
nextIcons := make(map[string]paint.ImageOp, len(items))
|
||||
for _, item := range items {
|
||||
controls := shell.rows[item.ID]
|
||||
if controls == nil {
|
||||
controls = new(rowControls)
|
||||
}
|
||||
nextRows[item.ID] = controls
|
||||
if icon, exists := shell.icons[item.ID]; exists {
|
||||
nextIcons[item.ID] = icon
|
||||
}
|
||||
}
|
||||
shell.rows = nextRows
|
||||
shell.icons = nextIcons
|
||||
|
||||
nextCategories := make(map[string]*widget.Clickable)
|
||||
for _, category := range append([]string{""}, shell.model.Categories()...) {
|
||||
|
||||
@@ -59,6 +59,8 @@ func TestAppShellKeepsRowControlsByAppID(t *testing.T) {
|
||||
}
|
||||
shell := NewAppShell("Legacy", items...)
|
||||
original := shell.rows["app-two"]
|
||||
shell.ApplyIcon("app-one", image.NewNRGBA(image.Rect(0, 0, 16, 16)))
|
||||
shell.ApplyIcon("app-two", image.NewNRGBA(image.Rect(0, 0, 24, 24)))
|
||||
|
||||
shell.model.SetCategory("图像")
|
||||
shell.Layout(testContext(image.Pt(1024, 680)), NewTheme())
|
||||
@@ -75,6 +77,16 @@ func TestAppShellKeepsRowControlsByAppID(t *testing.T) {
|
||||
if _, exists := shell.rows["app-one"]; exists {
|
||||
t.Fatal("removed app retained row controls")
|
||||
}
|
||||
if _, exists := shell.icons["app-one"]; exists {
|
||||
t.Fatal("removed app retained prepared icon")
|
||||
}
|
||||
icon, exists := shell.icons["app-two"]
|
||||
if !exists {
|
||||
t.Fatal("retained app lost its prepared icon")
|
||||
}
|
||||
if icon.Size() != image.Pt(24, 24) {
|
||||
t.Fatalf("retained app icon size = %v", icon.Size())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppShellRendersSelectedDetailAndAppliedIcon(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user