From bda9d86afd41d1d787faf02735ab3a7b45a71f9f Mon Sep 17 00:00:00 2001 From: Jordan Baird Date: Sat, 12 Oct 2024 10:35:04 -0600 Subject: [PATCH] Update MenuBarManager.swift --- .../MenuBarManagement/MenuBarManager.swift | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/Ice/MenuBar/MenuBarManagement/MenuBarManager.swift b/Ice/MenuBar/MenuBarManagement/MenuBarManager.swift index 90cbfc7..bb6ec14 100644 --- a/Ice/MenuBar/MenuBarManagement/MenuBarManager.swift +++ b/Ice/MenuBar/MenuBarManagement/MenuBarManager.swift @@ -43,7 +43,9 @@ final class MenuBarManager: ObservableObject { /// A Boolean value that indicates whether the manager can update its stored /// information for the menu bar's average color. - private var canUpdateAverageColorInfo = false + private var canUpdateAverageColorInfo: Bool { + appState?.settingsWindow?.isVisible == true + } /// The managed sections in the menu bar. private(set) var sections = [MenuBarSection]() @@ -135,30 +137,17 @@ final class MenuBarManager: ObservableObject { } .store(in: &c) - if let settingsWindow = appState?.settingsWindow { - settingsWindow.publisher(for: \.isVisible) - .receive(on: DispatchQueue.main) - .sink { [weak self] isVisible in - guard let self else { - return - } - if isVisible { - canUpdateAverageColorInfo = true - updateAverageColorInfo() - } else { - canUpdateAverageColorInfo = false - } - } - .store(in: &c) - } + appState?.settingsWindow?.publisher(for: \.isVisible) + .receive(on: DispatchQueue.main) + .sink { [weak self] _ in + self?.updateAverageColorInfo() + } + .store(in: &c) Timer.publish(every: 5, on: .main, in: .default) .autoconnect() .sink { [weak self] _ in - guard let self else { - return - } - updateAverageColorInfo() + self?.updateAverageColorInfo() } .store(in: &c)