Skip to content

Commit

Permalink
Update MenuBarManager.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Oct 12, 2024
1 parent a221b85 commit bda9d86
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions Ice/MenuBar/MenuBarManagement/MenuBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit bda9d86

Please sign in to comment.