Skip to content

Commit

Permalink
Revert hasImages check to cacheFailed check
Browse files Browse the repository at this point in the history
Fixes #377
  • Loading branch information
jordanbaird committed Sep 25, 2024
1 parent 6dad1e9 commit 390c5d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions Ice/MenuBar/MenuBarItemImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ final class MenuBarItemImageCache: ObservableObject {
cancellables = c
}

/// Returns a Boolean value that indicates whether the cache contains at least _some_
/// images for the given section.
/// Returns a Boolean value that indicates whether caching menu bar items failed for
/// the given section.
@MainActor
func hasImages(for section: MenuBarSection.Name) -> Bool {
func cacheFailed(for section: MenuBarSection.Name) -> Bool {
let items = appState?.itemManager.itemCache.allItems(for: section) ?? []
return !Set(items.map { $0.info }).isDisjoint(with: images.keys)
guard !items.isEmpty else {
return false
}
let keys = Set(images.keys)
for item in items where keys.contains(item.info) {
return false
}
return true
}

/// Captures the images of the current menu bar items and returns a dictionary containing
Expand Down
2 changes: 1 addition & 1 deletion Ice/UI/IceBar/IceBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private struct IceBarContentView: View {
if menuBarManager.isMenuBarHiddenBySystemUserDefaults {
Text("Ice cannot display menu bar items for automatically hidden menu bars")
.padding(.horizontal, 5)
} else if !imageCache.hasImages(for: section) {
} else if imageCache.cacheFailed(for: section) {
Text("Unable to display menu bar items")
.padding(.horizontal, 5)
} else {
Expand Down
6 changes: 3 additions & 3 deletions Ice/UI/LayoutBar/LayoutBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ struct LayoutBar: View {

@ViewBuilder
private var conditionalBody: some View {
if imageCache.hasImages(for: section.name) {
Representable(appState: appState, section: section, spacing: spacing)
} else {
if imageCache.cacheFailed(for: section.name) {
Text("Unable to display menu bar items")
.foregroundStyle(menuBarManager.averageColorInfo?.color.brightness ?? 0 > 0.67 ? .black : .white)
} else {
Representable(appState: appState, section: section, spacing: spacing)
}
}

Expand Down

0 comments on commit 390c5d1

Please sign in to comment.