Skip to content

Commit

Permalink
Rename logDebugMessage to logDebug
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Sep 22, 2024
1 parent 90e0c13 commit 2996468
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Ice/Main/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions Ice/MenuBar/Appearance/MenuBarOverlayPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Ice/MenuBar/MenuBarItemImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
Expand Down
40 changes: 20 additions & 20 deletions Ice/MenuBar/MenuBarItemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions Ice/MenuBar/Spacing/MenuBarItemSpacingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}
}
Expand All @@ -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()
}
}
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Ice/Utilities/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 2996468

Please sign in to comment.