@@ -156,20 +156,20 @@ func (a *App) Run() error {
156156 // Wait for interrupt signal with force-quit support
157157 sigChan := make (chan os.Signal , 1 )
158158 signal .Notify (sigChan , os .Interrupt , syscall .SIGTERM )
159-
159+
160160 // First signal: graceful shutdown
161161 <- sigChan
162162 a .logger .Info ("Received shutdown signal, starting graceful shutdown..." )
163163 fmt .Println ("\n ⚠️ Shutting down gracefully... (press Ctrl+C again to force quit)" )
164-
164+
165165 // Start cleanup in goroutine
166166 done := make (chan struct {})
167167 go func () {
168168 // Quit systray to exit the event loop
169169 systray .Quit ()
170170 close (done )
171171 }()
172-
172+
173173 // Wait for cleanup or second signal
174174 select {
175175 case <- done :
@@ -186,7 +186,7 @@ func (a *App) Run() error {
186186 fmt .Println ("⚠️ Shutdown timeout, force quitting..." )
187187 os .Exit (1 )
188188 }
189-
189+
190190 return nil
191191}
192192
@@ -287,33 +287,33 @@ func (a *App) activateHintMode(withActions bool) {
287287 a .logger .Debug ("Scanning for clickable elements" ,
288288 zap .Strings ("roles" , roles ))
289289
290- elements , err := accessibility .GetClickableElements ()
290+ elements , err := accessibility .GetClickableElements ()
291291 if err != nil {
292292 a .logger .Error ("Failed to get clickable elements" , zap .Error (err ))
293293 return
294294 }
295295
296296 a .logger .Info ("Found clickable elements" , zap .Int ("count" , len (elements )))
297297
298- // Optionally include menu bar elements
299- if a .config .Hints .Menubar {
300- if mbElems , merr := accessibility .GetMenuBarClickableElements (); merr == nil {
301- elements = append (elements , mbElems ... )
302- a .logger .Debug ("Included menubar elements" , zap .Int ("count" , len (mbElems )))
303- } else {
304- a .logger .Warn ("Failed to get menubar elements" , zap .Error (merr ))
305- }
306- }
307-
308- // Optionally include Dock elements
309- if a .config .Hints .Dock {
310- if dockElems , derr := accessibility .GetDockClickableElements (); derr == nil {
311- elements = append (elements , dockElems ... )
312- a .logger .Debug ("Included dock elements" , zap .Int ("count" , len (dockElems )))
313- } else {
314- a .logger .Warn ("Failed to get dock elements" , zap .Error (derr ))
315- }
316- }
298+ // Optionally include menu bar elements
299+ if a .config .Hints .Menubar {
300+ if mbElems , merr := accessibility .GetMenuBarClickableElements (); merr == nil {
301+ elements = append (elements , mbElems ... )
302+ a .logger .Debug ("Included menubar elements" , zap .Int ("count" , len (mbElems )))
303+ } else {
304+ a .logger .Warn ("Failed to get menubar elements" , zap .Error (merr ))
305+ }
306+ }
307+
308+ // Optionally include Dock elements
309+ if a .config .Hints .Dock {
310+ if dockElems , derr := accessibility .GetDockClickableElements (); derr == nil {
311+ elements = append (elements , dockElems ... )
312+ a .logger .Debug ("Included dock elements" , zap .Int ("count" , len (dockElems )))
313+ } else {
314+ a .logger .Warn ("Failed to get dock elements" , zap .Error (derr ))
315+ }
316+ }
317317
318318 if len (elements ) == 0 {
319319 a .logger .Warn ("No clickable elements found" )
@@ -371,9 +371,10 @@ func (a *App) handleKeyPress(key string) {
371371 }
372372
373373 // Route to appropriate handler
374- if a .currentMode == ModeHint || a .currentMode == ModeHintWithActions {
374+ switch a .currentMode {
375+ case ModeHint , ModeHintWithActions :
375376 a .handleHintKey (key )
376- } else if a . currentMode == ModeScroll {
377+ case ModeScroll :
377378 a .handleScrollKey (key )
378379 }
379380}
@@ -487,29 +488,29 @@ func (a *App) showActionMenu(hint *hints.Hint) {
487488 actionHints := make ([]* hints.Hint , 0 , len (actions ))
488489 baseX := hint .Position .X
489490 baseY := hint .Position .Y
490-
491+
491492 // Estimate width per character (approximate for monospace font at size 11)
492493 charWidth := 7.0
493494 gapBetweenHints := 8.0 // Consistent gap between hint boxes
494-
495+
495496 currentX := float64 (baseX )
496-
497+
497498 for _ , action := range actions {
498499 // Format: [key]label (e.g., "[l]eft")
499500 actionLabel := fmt .Sprintf ("[%s]%s" , action .key , action .label )
500-
501+
501502 actionHint := & hints.Hint {
502503 Label : actionLabel ,
503504 Element : hint .Element ,
504505 Position : image.Point {X : int (currentX ), Y : baseY },
505506 }
506507 actionHints = append (actionHints , actionHint )
507-
508+
508509 // Calculate width of this hint box (text width + padding * 2)
509510 textWidth := float64 (len (actionLabel )) * charWidth
510511 padding := 3.0 * 2 // padding on both sides
511512 hintBoxWidth := textWidth + padding
512-
513+
513514 // Move to next position (current box width + gap)
514515 currentX += hintBoxWidth + gapBetweenHints
515516 }
@@ -519,7 +520,7 @@ func (a *App) showActionMenu(hint *hints.Hint) {
519520 actionStyle .FontSize = 11 // Smaller font
520521 actionStyle .Padding = 3 // Less padding
521522 actionStyle .BorderRadius = 3 // Smaller border radius
522-
523+
523524 // Draw all action hints without arrows and with custom style
524525 if err := a .hintOverlay .DrawHintsWithoutArrow (actionHints , actionStyle ); err != nil {
525526 a .logger .Error ("Failed to draw action menu" , zap .Error (err ))
@@ -535,24 +536,24 @@ func (a *App) handleActionKey(key string) {
535536 // Handle backspace/delete to go back to hint selection
536537 if key == "\x7f " || key == "delete" || key == "backspace" {
537538 a .logger .Debug ("Backspace pressed in action mode, returning to hint selection" )
538-
539+
539540 // Clear selected hint
540541 a .selectedHint = nil
541-
542+
542543 // Remove the last character from hintInput (e.g., "ABD" -> "AB")
543544 if len (a .hintInput ) > 0 {
544545 a .hintInput = a .hintInput [:len (a .hintInput )- 1 ]
545546 a .logger .Debug ("Removed last character from hint input" , zap .String ("input" , a .hintInput ))
546547 }
547-
548+
548549 // Redraw hints with updated input filter
549550 var filtered []* hints.Hint
550551 if a .hintInput == "" {
551552 filtered = a .currentHints .GetHints ()
552553 } else {
553554 filtered = a .currentHints .FilterByPrefix (a .hintInput )
554555 }
555-
556+
556557 // Update matched prefix for filtered hints and redraw
557558 for _ , hint := range filtered {
558559 hint .MatchedPrefix = a .hintInput
@@ -697,7 +698,7 @@ func (a *App) switchScrollAreaByNumber(key string) {
697698 a .logger .Debug ("Invalid number key" , zap .String ("key" , key ))
698699 return
699700 }
700-
701+
701702 number := int (key [0 ] - '0' )
702703 detector := a .scrollController .GetDetector ()
703704 newArea := detector .SetActiveByNumber (number )
@@ -796,7 +797,9 @@ func (a *App) drawScrollAreaLabels(areas []*scroll.ScrollArea) {
796797
797798 // Draw the number hints
798799 if len (areaHints ) > 0 {
799- a .hintOverlay .DrawHints (areaHints )
800+ if err := a .hintOverlay .DrawHints (areaHints ); err != nil {
801+ a .logger .Error ("Failed to draw hints" , zap .Error (err ))
802+ }
800803 }
801804
802805 // Draw highlight on active area
@@ -827,11 +830,12 @@ func (a *App) exitMode() {
827830 a .hintOverlay .Clear ()
828831
829832 // Clean up mode-specific state
830- if a .currentMode == ModeHint || a .currentMode == ModeHintWithActions {
833+ switch a .currentMode {
834+ case ModeHint , ModeHintWithActions :
831835 a .currentHints = nil
832836 a .hintInput = ""
833837 a .selectedHint = nil
834- } else if a . currentMode == ModeScroll {
838+ case ModeScroll :
835839 a .scrollController .Cleanup ()
836840 }
837841
@@ -1010,9 +1014,9 @@ func main() {
10101014 if len (os .Args ) > 1 {
10111015 arg := os .Args [1 ]
10121016 // These commands use CLI/IPC
1013- if arg == "launch" || arg == "start" || arg == "stop" || arg == "hints" ||
1014- arg == "scroll" || arg == "hints_action" || arg == "idle" || arg == "status" ||
1015- arg == "help" || arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" {
1017+ if arg == "launch" || arg == "start" || arg == "stop" || arg == "hints" ||
1018+ arg == "scroll" || arg == "hints_action" || arg == "idle" || arg == "status" ||
1019+ arg == "help" || arg == "--help" || arg == "-h" || arg == "--version" || arg == "-v" {
10161020 cli .Execute ()
10171021 return
10181022 }
0 commit comments