Skip to content

Commit c273340

Browse files
committed
Additional logging
1 parent 2bbada3 commit c273340

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Ice/MenuBar/MenuBarItemManager.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MenuBarItemManager: ObservableObject {
2828
func performSetup() {
2929
configureCancellables()
3030
DispatchQueue.main.async {
31-
self.cacheMenuBarItems()
31+
self.cacheCurrentMenuBarItems()
3232
}
3333
}
3434

@@ -38,20 +38,22 @@ class MenuBarItemManager: ObservableObject {
3838
Timer.publish(every: 3, on: .main, in: .default)
3939
.autoconnect()
4040
.sink { [weak self] _ in
41-
self?.cacheMenuBarItems()
41+
self?.cacheCurrentMenuBarItems()
4242
}
4343
.store(in: &c)
4444

4545
cancellables = c
4646
}
4747

4848
/// Caches the current menu bar items.
49-
private func cacheMenuBarItems() {
49+
private func cacheCurrentMenuBarItems() {
5050
guard tempShownItemsInfo.isEmpty else {
5151
Logger.itemManager.info("Items are temporarily shown, so deferring cache")
5252
return
5353
}
5454

55+
Logger.itemManager.info("Caching current menu bar items")
56+
5557
let items = MenuBarItem.getMenuBarItemsPrivateAPI(onScreenOnly: false)
5658

5759
guard
@@ -113,12 +115,17 @@ class MenuBarItemManager: ObservableObject {
113115
/// Schedules a timer for the given interval, attempting to rehide the current
114116
/// temporarily shown items when the timer fires.
115117
private func runTempShownItemTimer(for interval: TimeInterval) {
118+
Logger.itemManager.info("Running rehide timer for temporarily shown items with interval: \(interval)")
119+
116120
tempShownItemsTimer?.invalidate()
117121
tempShownItemsTimer = .scheduledTimer(withTimeInterval: interval, repeats: false) { [weak self] timer in
118122
guard let self else {
119123
timer.invalidate()
120124
return
121125
}
126+
127+
Logger.itemManager.info("Rehide timer fired")
128+
122129
Task {
123130
await self.rehideTempShownItems()
124131
}
@@ -138,6 +145,8 @@ class MenuBarItemManager: ObservableObject {
138145
/// - clickWhenFinished: A Boolean value that indicates whether the item
139146
/// should be clicked once its movement has finished.
140147
func tempShowItem(_ item: MenuBarItem, clickWhenFinished: Bool) {
148+
Logger.itemManager.info("Temporarily showing \"\(item.logString)\"")
149+
141150
let items = MenuBarItem.getMenuBarItemsPrivateAPI(onScreenOnly: false)
142151

143152
guard let destination = getReturnDestination(for: item, in: items) else {
@@ -179,6 +188,8 @@ class MenuBarItemManager: ObservableObject {
179188
/// to close before hiding the items.
180189
func rehideTempShownItems() async {
181190
if let menuWindow = WindowInfo.getAllWindows().first(where: { $0.layer == 101 }) {
191+
Logger.itemManager.info("Waiting for menu to close")
192+
182193
let menuCheckTask = Task.detached(timeout: .seconds(1)) {
183194
while Set(Bridging.getWindowList(option: .onScreen)).contains(menuWindow.windowID) {
184195
try Task.checkCancellation()
@@ -195,13 +206,17 @@ class MenuBarItemManager: ObservableObject {
195206
Logger.itemManager.error("ERROR: \(error)")
196207
}
197208
}
209+
210+
Logger.itemManager.info("Rehiding temporarily shown items")
211+
198212
while let (item, destination) = tempShownItemsInfo.popLast() {
199213
do {
200214
try await move(item: item, to: destination)
201215
} catch {
202-
Logger.itemManager.error("Failed to return \"\(item.logString)\": \(error)")
216+
Logger.itemManager.error("Failed to rehide \"\(item.logString)\": \(error)")
203217
}
204218
}
219+
205220
tempShownItemsTimer?.invalidate()
206221
tempShownItemsTimer = nil
207222
}

0 commit comments

Comments
 (0)