-
Notifications
You must be signed in to change notification settings - Fork 0
Claude/fix active target mode 011 c uy l7 ny9 pfo gabvg1q lj w #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dbfd6a3
ffe4c84
99dbad1
f7b4f99
8ecbe03
a821c39
c548735
9ce9775
fe68ce8
2a693f4
059fadf
1302d21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // | ||
| // CursorManager.swift | ||
| // ClickIt | ||
| // | ||
| // Manages custom cursor states for active target mode | ||
| // | ||
|
|
||
| import Cocoa | ||
| import os.log | ||
|
|
||
| /// Manages cursor appearance for different automation modes | ||
| final class CursorManager { | ||
| static let shared = CursorManager() | ||
|
|
||
| private let logger = Logger(subsystem: "com.clickit.app", category: "CursorManager") | ||
| private var isTargetCursorActive = false | ||
| private var cursorUpdateTimer: Timer? | ||
|
|
||
| private init() {} | ||
|
|
||
| /// Shows the target/crosshair cursor for active target mode | ||
| func showTargetCursor() { | ||
| DispatchQueue.main.async { [weak self] in | ||
| guard let self = self else { return } | ||
|
|
||
| if !self.isTargetCursorActive { | ||
| self.isTargetCursorActive = true | ||
|
|
||
| // Set the cursor immediately | ||
| NSCursor.crosshair.set() | ||
|
|
||
| // Keep re-setting the cursor on a timer to ensure it stays active | ||
| // This is needed because system can reset cursor on window focus changes | ||
| self.cursorUpdateTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in | ||
| guard let self = self, self.isTargetCursorActive else { return } | ||
| NSCursor.crosshair.set() | ||
| } | ||
|
Comment on lines
+34
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The timer closure should invalidate the timer itself when it's no longer needed. This prevents the timer from continuing to fire unnecessarily if self.cursorUpdateTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] timer in
guard let self = self, self.isTargetCursorActive else {
timer.invalidate()
return
}
NSCursor.crosshair.set()
} |
||
|
|
||
| self.logger.info("Target cursor activated with timer refresh") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Restores the normal system cursor | ||
| func restoreNormalCursor() { | ||
| DispatchQueue.main.async { [weak self] in | ||
| guard let self = self else { return } | ||
|
|
||
| if self.isTargetCursorActive { | ||
| self.isTargetCursorActive = false | ||
|
|
||
| // Stop the cursor update timer | ||
| self.cursorUpdateTimer?.invalidate() | ||
| self.cursorUpdateTimer = nil | ||
|
|
||
| // Restore arrow cursor | ||
| NSCursor.arrow.set() | ||
|
|
||
| self.logger.info("Normal cursor restored") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Force restore cursor (useful for cleanup on app termination) | ||
| func forceRestoreNormalCursor() { | ||
| DispatchQueue.main.async { [weak self] in | ||
| guard let self = self else { return } | ||
|
|
||
| self.isTargetCursorActive = false | ||
| self.cursorUpdateTimer?.invalidate() | ||
| self.cursorUpdateTimer = nil | ||
| NSCursor.arrow.set() | ||
|
|
||
| self.logger.info("Cursor forcefully restored") | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+44
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The functions /// Restores the normal system cursor
func restoreNormalCursor(force: Bool = false) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if force || self.isTargetCursorActive {
self.isTargetCursorActive = false
// Stop the cursor update timer
self.cursorUpdateTimer?.invalidate()
self.cursorUpdateTimer = nil
// Restore arrow cursor
NSCursor.arrow.set()
self.logger.info(force ? "Cursor forcefully restored" : "Normal cursor restored")
}
}
}
/// Force restore cursor (useful for cleanup on app termination)
func forceRestoreNormalCursor() {
restoreNormalCursor(force: true)
}
} |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of
unregisterMouseMonitor()is very similar to the existingunregisterGlobalHotkey()method. To reduce code duplication and improve maintainability, you could extract this common logic into a private helper function.For example:
You could then refactor
unregisterGlobalHotkey()to use this helper as well.