Skip to content

Commit c277712

Browse files
committed
Simplify menu bar item image cache
1 parent f0222ad commit c277712

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

Diff for: Ice/MenuBar/MenuBarItems/MenuBarItemImageCache.swift

+5-14
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,14 @@ final class MenuBarItemImageCache: ObservableObject {
191191

192192
/// Updates the cache for the given sections, without checking whether caching is necessary.
193193
func updateCacheWithoutChecks(sections: [MenuBarSection.Name]) async {
194-
actor Context {
195-
var images = [MenuBarItemInfo: CGImage]()
196-
197-
func merge(_ other: [MenuBarItemInfo: CGImage]) {
198-
images.merge(other) { (_, new) in new }
199-
}
200-
}
201-
202194
guard
203195
let appState,
204196
let screen = NSScreen.main
205197
else {
206198
return
207199
}
208200

209-
let context = Context()
201+
var newImages = [MenuBarItemInfo: CGImage]()
210202

211203
for section in sections {
212204
guard await !appState.itemManager.itemCache[section].isEmpty else {
@@ -217,14 +209,12 @@ final class MenuBarItemImageCache: ObservableObject {
217209
Logger.imageCache.warning("Update image cache failed for \(section.logString)")
218210
continue
219211
}
220-
await context.merge(sectionImages)
212+
newImages.merge(sectionImages) { (_, new) in new }
221213
}
222214

223-
let task = Task { @MainActor in
224-
let images = await context.images
225-
self.images.merge(images) { (_, new) in new }
215+
await MainActor.run { [newImages] in
216+
images.merge(newImages) { (_, new) in new }
226217
}
227-
await task.value
228218

229219
self.screen = screen
230220
self.menuBarHeight = screen.getMenuBarHeight()
@@ -292,6 +282,7 @@ final class MenuBarItemImageCache: ObservableObject {
292282
}
293283

294284
// MARK: - Logger
285+
295286
private extension Logger {
296287
static let imageCache = Logger(category: "MenuBarItemImageCache")
297288
}

0 commit comments

Comments
 (0)