From 2996468204056b585a1de92b04c931b171ee4a99 Mon Sep 17 00:00:00 2001 From: Jordan Baird Date: Sun, 22 Sep 2024 00:09:40 -0600 Subject: [PATCH] Rename `logDebugMessage` to `logDebug` --- Ice/Main/AppState.swift | 2 +- .../Appearance/MenuBarOverlayPanel.swift | 8 ++-- Ice/MenuBar/MenuBarItemImageCache.swift | 8 ++-- Ice/MenuBar/MenuBarItemManager.swift | 40 +++++++++---------- .../Spacing/MenuBarItemSpacingManager.swift | 10 ++--- Ice/Utilities/Logging.swift | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Ice/Main/AppState.swift b/Ice/Main/AppState.swift index ac17578d..1bfabfd6 100644 --- a/Ice/Main/AppState.swift +++ b/Ice/Main/AppState.swift @@ -212,7 +212,7 @@ final class AppState: ObservableObject { activate() } else { Context.hasActivated[self] = true - logDebugMessage(to: .appState, "First time activating app, so going through Dock") + logDebug(to: .appState, "First time activating app, so going through Dock") // Hack to make sure the app properly activates for the first time. NSRunningApplication.runningApplications(withBundleIdentifier: "com.apple.dock").first?.activate() DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { diff --git a/Ice/MenuBar/Appearance/MenuBarOverlayPanel.swift b/Ice/MenuBar/Appearance/MenuBarOverlayPanel.swift index 1719dcb4..9acd5c04 100644 --- a/Ice/MenuBar/Appearance/MenuBarOverlayPanel.swift +++ b/Ice/MenuBar/Appearance/MenuBarOverlayPanel.swift @@ -260,20 +260,20 @@ final class MenuBarOverlayPanel: NSPanel { case .updates: "Preventing overlay panel from updating." } guard let appState else { - logDebugMessage(to: .overlayPanel, "No app state. \(actionMessage)") + logDebug(to: .overlayPanel, "No app state. \(actionMessage)") return nil } guard !appState.menuBarManager.isMenuBarHiddenBySystemUserDefaults else { - logDebugMessage(to: .overlayPanel, "Menu bar is hidden by system. \(actionMessage)") + logDebug(to: .overlayPanel, "Menu bar is hidden by system. \(actionMessage)") return nil } guard !appState.isActiveSpaceFullscreen else { - logDebugMessage(to: .overlayPanel, "Active space is fullscreen. \(actionMessage)") + logDebug(to: .overlayPanel, "Active space is fullscreen. \(actionMessage)") return nil } let owningDisplay = owningScreen.displayID guard appState.menuBarManager.hasValidMenuBar(in: windows, for: owningDisplay) else { - logDebugMessage(to: .overlayPanel, "No valid menu bar found. \(actionMessage)") + logDebug(to: .overlayPanel, "No valid menu bar found. \(actionMessage)") return nil } return owningDisplay diff --git a/Ice/MenuBar/MenuBarItemImageCache.swift b/Ice/MenuBar/MenuBarItemImageCache.swift index f2f33a00..cb7bbed3 100644 --- a/Ice/MenuBar/MenuBarItemImageCache.swift +++ b/Ice/MenuBar/MenuBarItemImageCache.swift @@ -226,19 +226,19 @@ final class MenuBarItemImageCache: ObservableObject { if !isIceBarPresented && !isSearchPresented { guard await appState.navigationState.isAppFrontmost else { - logDebugMessage(to: .imageCache, "Skipping image cache as Ice Bar not visible, app not frontmost") + logDebug(to: .imageCache, "Skipping image cache as Ice Bar not visible, app not frontmost") return } isSettingsPresented = await appState.navigationState.isSettingsPresented guard isSettingsPresented else { - logDebugMessage(to: .imageCache, "Skipping image cache as Ice Bar not visible, Settings not visible") + logDebug(to: .imageCache, "Skipping image cache as Ice Bar not visible, Settings not visible") return } guard case .menuBarLayout = await appState.navigationState.settingsNavigationIdentifier else { - logDebugMessage(to: .imageCache, "Skipping image cache as Ice Bar not visible, Settings visible but not on Menu Bar Layout pane") + logDebug(to: .imageCache, "Skipping image cache as Ice Bar not visible, Settings visible but not on Menu Bar Layout pane") return } } else { @@ -247,7 +247,7 @@ final class MenuBarItemImageCache: ObservableObject { if let lastItemMoveStartDate = await appState.itemManager.lastItemMoveStartDate { guard Date.now.timeIntervalSince(lastItemMoveStartDate) > 3 else { - logDebugMessage(to: .imageCache, "Skipping image cache as an item was recently moved") + logDebug(to: .imageCache, "Skipping image cache as an item was recently moved") return } } diff --git a/Ice/MenuBar/MenuBarItemManager.swift b/Ice/MenuBar/MenuBarItemManager.swift index 2131dc1e..928684dd 100644 --- a/Ice/MenuBar/MenuBarItemManager.swift +++ b/Ice/MenuBar/MenuBarItemManager.swift @@ -181,7 +181,7 @@ extension MenuBarItemManager { logWarning(to: .itemManager, "\(item.logString) doesn't seem to be in a section, so it wasn't cached") } - logDebugMessage(to: .itemManager, "Caching menu bar items") + logDebug(to: .itemManager, "Caching menu bar items") update(&itemCache) { cache in cache.clear() @@ -218,20 +218,20 @@ extension MenuBarItemManager { /// Caches the current menu bar items if needed, ensuring that the control items are in the correct order. private func cacheItemsIfNeeded() async { guard tempShownItemContexts.isEmpty else { - logDebugMessage(to: .itemManager, "Skipping item cache as items are temporarily shown") + logDebug(to: .itemManager, "Skipping item cache as items are temporarily shown") return } if let lastItemMoveStartDate { guard Date.now.timeIntervalSince(lastItemMoveStartDate) > 3 else { - logDebugMessage(to: .itemManager, "Skipping item cache as an item was recently moved") + logDebug(to: .itemManager, "Skipping item cache as an item was recently moved") return } } let itemWindowIDs = Bridging.getWindowList(option: [.menuBarItems, .activeSpace]) if cachedItemWindowIDs == itemWindowIDs { - logDebugMessage(to: .itemManager, "Skipping item cache as item windows have not changed") + logDebug(to: .itemManager, "Skipping item cache as item windows have not changed") return } else { cachedItemWindowIDs = itemWindowIDs @@ -251,7 +251,7 @@ extension MenuBarItemManager { guard let hiddenControlItem else { logWarning(to: .itemManager, "Missing control item for hidden section") - logDebugMessage(to: .itemManager, "Clearing item cache") + logDebug(to: .itemManager, "Clearing item cache") itemCache.clear() return } @@ -270,7 +270,7 @@ extension MenuBarItemManager { ) } catch { logError(to: .itemManager, "Error enforcing control item order: \(error)") - logDebugMessage(to: .itemManager, "Clearing item cache") + logDebug(to: .itemManager, "Clearing item cache") itemCache.clear() } } @@ -502,7 +502,7 @@ extension MenuBarItemManager { /// - event: The event to post. /// - location: The event tap location to post the event to. private nonisolated func postEvent(_ event: CGEvent, to location: EventTap.Location) { - logDebugMessage(to: .itemManager, "Posting \(event.type.logString) to \(location.logString)") + logDebug(to: .itemManager, "Posting \(event.type.logString) to \(location.logString)") switch location { case .hidEventTap: event.post(tap: .cghidEventTap) @@ -548,11 +548,11 @@ extension MenuBarItemManager { // Ensure the tap is enabled, preventing multiple calls to resume(). guard proxy.isEnabled else { - logDebugMessage(to: .itemManager, "Event tap \"\(proxy.label)\" is disabled (item: \(item.logString))") + logDebug(to: .itemManager, "Event tap \"\(proxy.label)\" is disabled (item: \(item.logString))") return nil } - logDebugMessage(to: .itemManager, "Received \(type.logString) at \(location.logString) (item: \(item.logString))") + logDebug(to: .itemManager, "Received \(type.logString) at \(location.logString) (item: \(item.logString))") proxy.disable() continuation.resume() @@ -650,7 +650,7 @@ extension MenuBarItemManager { // Ensure the tap is enabled, preventing multiple calls to resume(). guard proxy.isEnabled else { - logDebugMessage(to: .itemManager, "Event tap \"\(proxy.label)\" is disabled (item: \(item.logString))") + logDebug(to: .itemManager, "Event tap \"\(proxy.label)\" is disabled (item: \(item.logString))") return nil } @@ -717,7 +717,7 @@ extension MenuBarItemManager { throw FrameCheckCancellationError() } if currentFrame != initialFrame { - logDebugMessage(to: .itemManager, "Menu bar item frame for \(item.logString) has changed to \(NSStringFromRect(currentFrame))") + logDebug(to: .itemManager, "Menu bar item frame for \(item.logString) has changed to \(NSStringFromRect(currentFrame))") return } } @@ -753,7 +753,7 @@ extension MenuBarItemManager { /// Tries to wake up the given item if it is not responding to events. private func wakeUpItem(_ item: MenuBarItem) async throws { - logDebugMessage(to: .itemManager, "Attempting to wake up \(item.logString)") + logDebug(to: .itemManager, "Attempting to wake up \(item.logString)") guard let source = CGEventSource(stateID: .hidSystemState) else { throw EventError(code: .invalidEventSource, item: item) @@ -847,7 +847,7 @@ extension MenuBarItemManager { try await scrombleEvent(mouseUpEvent, from: .pid(item.ownerPID), to: .sessionEventTap, waitingForFrameChangeOf: item) } catch { do { - logDebugMessage(to: .itemManager, "Posting fallback event for moving \(item.logString)") + logDebug(to: .itemManager, "Posting fallback event for moving \(item.logString)") // Catch this, as we still want to throw the existing error if the fallback fails. try await postEventAndWaitToReceive(fallbackEvent, to: .sessionEventTap, item: item) } catch { @@ -864,7 +864,7 @@ extension MenuBarItemManager { /// - destination: A destination to move the menu bar item. func move(item: MenuBarItem, to destination: MoveDestination) async throws { if try itemHasCorrectPosition(item: item, for: destination) { - logDebugMessage(to: .itemManager, "\(item.logString) is already in the correct position") + logDebug(to: .itemManager, "\(item.logString) is already in the correct position") return } @@ -1008,7 +1008,7 @@ extension MenuBarItemManager { try await postEventAndWaitToReceive(mouseUpEvent, to: .sessionEventTap, item: item) } catch { do { - logDebugMessage(to: .itemManager, "Posting fallback event for clicking \(item.logString)") + logDebug(to: .itemManager, "Posting fallback event for clicking \(item.logString)") // Catch this, as we still want to throw the existing error if the fallback fails. try await postEventAndWaitToReceive(fallbackEvent, to: .sessionEventTap, item: item) } catch { @@ -1056,14 +1056,14 @@ extension MenuBarItemManager { /// Schedules a timer for the given interval, attempting to rehide the current temporarily shown /// items when the timer fires. private func runTempShownItemTimer(for interval: TimeInterval) { - logDebugMessage(to: .itemManager, "Running rehide timer for temporarily shown items with interval: \(interval)") + logDebug(to: .itemManager, "Running rehide timer for temporarily shown items with interval: \(interval)") tempShownItemsTimer?.invalidate() tempShownItemsTimer = .scheduledTimer(withTimeInterval: interval, repeats: false) { [weak self] timer in guard let self else { timer.invalidate() return } - logDebugMessage(to: .itemManager, "Rehide timer fired") + logDebug(to: .itemManager, "Rehide timer fired") Task { await self.rehideTempShownItems() } @@ -1207,7 +1207,7 @@ extension MenuBarItemManager { do { try await interfaceCheckTask.value } catch is TaskTimeoutError { - logDebugMessage(to: .itemManager, "Menu check task timed out, switching to timer") + logDebug(to: .itemManager, "Menu check task timed out, switching to timer") runTempShownItemTimer(for: 3) return } catch { @@ -1260,11 +1260,11 @@ extension MenuBarItemManager { /// - alwaysHiddenControlItem: A menu bar item that represents the control item for the always-hidden section. func enforceControlItemOrder(hiddenControlItem: MenuBarItem, alwaysHiddenControlItem: MenuBarItem) async throws { guard !isMouseButtonDown else { - logDebugMessage(to: .itemManager, "Mouse button is down, so will not enforce control item order") + logDebug(to: .itemManager, "Mouse button is down, so will not enforce control item order") return } guard mouseMovedCount <= 0 else { - logDebugMessage(to: .itemManager, "Mouse has recently moved, so will not enforce control item order") + logDebug(to: .itemManager, "Mouse has recently moved, so will not enforce control item order") return } if hiddenControlItem.frame.maxX <= alwaysHiddenControlItem.frame.minX { diff --git a/Ice/MenuBar/Spacing/MenuBarItemSpacingManager.swift b/Ice/MenuBar/Spacing/MenuBarItemSpacingManager.swift index 86cef96d..80d0d48f 100644 --- a/Ice/MenuBar/Spacing/MenuBarItemSpacingManager.swift +++ b/Ice/MenuBar/Spacing/MenuBarItemSpacingManager.swift @@ -77,10 +77,10 @@ final class MenuBarItemSpacingManager { /// Asynchronously signals the given app to quit. private func signalAppToQuit(_ app: NSRunningApplication) async throws { if app.isTerminated { - logDebugMessage(to: .spacing, "Application \"\(logString(for: app))\" is already terminated") + logDebug(to: .spacing, "Application \"\(logString(for: app))\" is already terminated") return } else { - logDebugMessage(to: .spacing, "Signaling application \"\(logString(for: app))\" to quit") + logDebug(to: .spacing, "Signaling application \"\(logString(for: app))\" to quit") } app.terminate() @@ -90,7 +90,7 @@ final class MenuBarItemSpacingManager { let timeoutTask = Task { try await Task.sleep(for: .seconds(forceTerminateDelay)) if !app.isTerminated { - logDebugMessage(to: .spacing, "Application \"\(logString(for: app))\" did not terminate within \(forceTerminateDelay) seconds, attempting to force terminate") + logDebug(to: .spacing, "Application \"\(logString(for: app))\" did not terminate within \(forceTerminateDelay) seconds, attempting to force terminate") app.forceTerminate() } } @@ -104,7 +104,7 @@ final class MenuBarItemSpacingManager { } timeoutTask.cancel() cancellable?.cancel() - logDebugMessage(to: .spacing, "Application \"\(logString(for: app))\" terminated successfully") + logDebug(to: .spacing, "Application \"\(logString(for: app))\" terminated successfully") continuation.resume() } } @@ -113,7 +113,7 @@ final class MenuBarItemSpacingManager { /// Asynchronously launches the app at the given URL. private nonisolated func launchApp(at applicationURL: URL, bundleIdentifier: String) async throws { if let app = NSWorkspace.shared.runningApplications.first(where: { $0.bundleIdentifier == bundleIdentifier }) { - logDebugMessage(to: .spacing, "Application \"\(logString(for: app))\" is already open, so skipping launch") + logDebug(to: .spacing, "Application \"\(logString(for: app))\" is already open, so skipping launch") return } let configuration = NSWorkspace.OpenConfiguration() diff --git a/Ice/Utilities/Logging.swift b/Ice/Utilities/Logging.swift index 0830d336..70158e6a 100644 --- a/Ice/Utilities/Logging.swift +++ b/Ice/Utilities/Logging.swift @@ -16,7 +16,7 @@ func logInfo(to logger: Logger, _ message: String) { } /// Logs the given debug message using the specified logger. -func logDebugMessage(to logger: Logger, _ message: String) { +func logDebug(to logger: Logger, _ message: String) { logMessage(to: logger, at: .debug, message) }