Skip to content

Commit

Permalink
Update MenuBarItemManager.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Oct 13, 2024
1 parent d546474 commit 5cca38c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Ice/MenuBar/ItemManagement/MenuBarItemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ final class MenuBarItemManager: ObservableObject {
/// items is being moved.
private var itemMoveCount = 0

/// Counter for mouse movement.
private var mouseMoveCount = 0

/// A Boolean value that indicates whether a mouse button is down.
private var isMouseButtonDown = false

/// Counter for mouse movement.
private var mouseMovedCount = 0

/// Event type mask for tracking mouse events.
private let mouseTrackingMask: NSEvent.EventTypeMask = [
.mouseMoved,
Expand All @@ -136,9 +136,11 @@ final class MenuBarItemManager: ObservableObject {
.otherMouseUp,
]

/// A Boolean value that indicates whether a menu bar item, or group
/// of menu bar items is being moved.
var isMovingItem: Bool { itemMoveCount > 0 }
/// A Boolean value that indicates whether a menu bar item, or
/// group of menu bar items is being moved.
var isMovingItem: Bool {
itemMoveCount > 0
}

/// Creates a manager with the given app state.
init(appState: AppState) {
Expand Down Expand Up @@ -190,9 +192,9 @@ final class MenuBarItemManager: ObservableObject {
}
switch event.type {
case .mouseMoved:
mouseMovedCount += 1
mouseMoveCount += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.mouseMovedCount = max(self.mouseMovedCount - 1, 0)
self.mouseMoveCount = max(self.mouseMoveCount - 1, 0)
}
case .leftMouseDown, .rightMouseDown, .otherMouseDown:
isMouseButtonDown = true
Expand Down Expand Up @@ -1392,7 +1394,7 @@ extension MenuBarItemManager {
Logger.itemManager.debug("Mouse button is down, so will not enforce control item order")
return
}
guard mouseMovedCount <= 0 else {
guard mouseMoveCount <= 0 else {
Logger.itemManager.debug("Mouse has recently moved, so will not enforce control item order")
return
}
Expand Down

0 comments on commit 5cca38c

Please sign in to comment.