77
88import AppKit
99import SwiftUI
10+ import os. log
1011
1112class SimpleCursorManager {
1213
@@ -16,6 +17,7 @@ class SimpleCursorManager {
1617
1718 // MARK: - Properties
1819
20+ private let logger = Logger ( subsystem: LoggingConstants . subsystem, category: " SimpleCursorManager " )
1921 private var customCursor : NSCursor ?
2022 private var originalCursor : NSCursor ?
2123 private var cursorUpdateTimer : Timer ?
@@ -32,14 +34,14 @@ class SimpleCursorManager {
3234 /// Activates the custom target cursor system-wide
3335 func activateCustomCursor( ) {
3436 guard let customCursor = customCursor else {
35- print ( " ❌ Custom cursor not available " )
37+ logger . error ( " ❌ Custom cursor not available " )
3638 showDebugAlert ( " Cursor Failed " , " Custom cursor could not be loaded. Check console for details. " )
3739 return
3840 }
3941
4042 // Prevent double activation
4143 if isCursorActive {
42- print ( " ℹ️ Custom cursor already active " )
44+ logger . info ( " ℹ️ Custom cursor already active " )
4345 return
4446 }
4547
@@ -58,7 +60,7 @@ class SimpleCursorManager {
5860 self . customCursor? . set ( )
5961 }
6062
61- print ( " ✅ Custom target cursor activated with continuous refresh " )
63+ logger . info ( " ✅ Custom target cursor activated with continuous refresh " )
6264 // Optional: Uncomment to show success alert
6365 // showDebugAlert("Cursor Active", "Custom target cursor has been activated")
6466 }
@@ -86,81 +88,64 @@ class SimpleCursorManager {
8688 // Restore arrow cursor
8789 NSCursor . arrow. set ( )
8890
89- print ( " ✅ Default cursor restored " )
91+ logger . info ( " ✅ Default cursor restored " )
9092 }
9193
9294 // MARK: - Private Methods
9395
9496 /// Finds the correct resource bundle for Swift Package Manager
9597 private func findResourceBundle( ) -> Bundle {
96- // Strategy 1: Look for SPM resource bundle (swift run / debug builds)
97- if let bundleURL = Bundle . main. url ( forResource: " ClickIt_ClickItLite " , withExtension: " bundle " ) ,
98- let resourceBundle = Bundle ( url: bundleURL) {
99- print ( " ✅ Found SPM resource bundle at: \( bundleURL. path) " )
100- return resourceBundle
101- }
102-
103- // Strategy 2: Look in Contents/Resources for packaged .app builds
104- if let resourcePath = Bundle . main. resourcePath,
105- let bundlePath = Bundle ( path: resourcePath + " /ClickIt_ClickItLite.bundle " ) {
106- print ( " ✅ Found resource bundle in app Resources: \( resourcePath) /ClickIt_ClickItLite.bundle " )
107- return bundlePath
108- }
109-
110- // Strategy 3: Try Module.bundle (for Xcode builds)
111- if let bundleURL = Bundle . main. url ( forResource: " ClickItLite_ClickItLite " , withExtension: " bundle " ) ,
112- let resourceBundle = Bundle ( url: bundleURL) {
113- print ( " ✅ Found module resource bundle at: \( bundleURL. path) " )
114- return resourceBundle
115- }
116-
117- // Fallback to Bundle.main (resources might be directly in app bundle)
118- print ( " ⚠️ Using Bundle.main as fallback " )
119- return Bundle . main
98+ // For Swift 5.3+, Swift Package Manager automatically synthesizes a `Bundle.module` static property
99+ // for any target that includes resources. This is the modern and recommended way to access them.
100+ return Bundle . module
120101 }
121102
122103 private func setupCustomCursor( ) {
123- // Debug: Print bundle path
124- print ( " 🔍 Bundle path: \( Bundle . main. bundlePath) " )
125- print ( " 🔍 Resource path: \( Bundle . main. resourcePath ?? " nil " ) " )
104+ // Define cursor properties at the top for easy modification
105+ let cursorDimension : CGFloat = 64
106+ let cursorImageName = " target- \( Int ( cursorDimension) ) "
107+
108+ // Debug: Log bundle path
109+ logger. debug ( " 🔍 Bundle path: \( Bundle . main. bundlePath) " )
110+ logger. debug ( " 🔍 Resource path: \( Bundle . main. resourcePath ?? " nil " ) " )
126111
127112 // Find the correct resource bundle for Swift Package Manager
128113 let bundle = findResourceBundle ( )
129- print ( " 🔍 Using bundle: \( bundle. bundlePath) " )
114+ logger . debug ( " 🔍 Using bundle: \( bundle. bundlePath) " )
130115
131116 // Try to load the target image from resources
132- guard let imageURL = bundle. url ( forResource: " target-64 " , withExtension: " png " ) else {
133- print ( " ❌ Failed to find target-64 .png in bundle " )
134- print ( " 🔍 Searched in: \( bundle. bundleURL) " )
117+ guard let imageURL = bundle. url ( forResource: cursorImageName , withExtension: " png " ) else {
118+ logger . error ( " ❌ Failed to find \( cursorImageName ) .png in bundle " )
119+ logger . error ( " 🔍 Searched in: \( bundle. bundleURL) " )
135120
136121 // Try to list all resources
137122 if let resourcePath = bundle. resourcePath {
138123 do {
139124 let items = try FileManager . default. contentsOfDirectory ( atPath: resourcePath)
140- print ( " 📁 Available resources in bundle: \( items) " )
125+ logger . debug ( " 📁 Available resources in bundle: \( items) " )
141126 } catch {
142- print ( " ❌ Could not list resources: \( error) " )
127+ logger . error ( " ❌ Could not list resources: \( error) " )
143128 }
144129 }
145130 return
146131 }
147132
148- print ( " ✅ Found image at: \( imageURL. path) " )
133+ logger . debug ( " ✅ Found image at: \( imageURL. path) " )
149134
150135 guard let image = NSImage ( contentsOf: imageURL) else {
151- print ( " ❌ Failed to load NSImage from: \( imageURL. path) " )
136+ logger . error ( " ❌ Failed to load NSImage from: \( imageURL. path) " )
152137 return
153138 }
154139
155- print ( " ✅ NSImage loaded, original size: \( image. size) " )
140+ logger . debug ( " ✅ NSImage loaded, original size: \( String ( describing : image. size) ) " )
156141
157- // Set the cursor size (64x64 pixels)
158- image. size = NSSize ( width: 64 , height: 64 )
142+ // Set the cursor size
143+ image. size = NSSize ( width: cursorDimension , height: cursorDimension )
159144
160- // Create cursor with hotspot at center (32, 32)
161- let hotspot = NSPoint ( x: 32 , y: 32 )
145+ // Create cursor with hotspot at center
146+ let hotspot = NSPoint ( x: cursorDimension / 2 , y: cursorDimension / 2 )
162147 customCursor = NSCursor ( image: image, hotSpot: hotspot)
163148
164- print ( " ✅ Custom cursor created successfully " )
149+ logger . info ( " ✅ Custom cursor created successfully " )
165150 }
166151}
0 commit comments