Skip to content

Show Real-Time CPS Score in Menubar#6

Open
O-mkar wants to merge 2 commits intoWorldOfBasti:masterfrom
O-mkar:feature/cps-score-display
Open

Show Real-Time CPS Score in Menubar#6
O-mkar wants to merge 2 commits intoWorldOfBasti:masterfrom
O-mkar:feature/cps-score-display

Conversation

@O-mkar
Copy link
Copy Markdown
Contributor

@O-mkar O-mkar commented Feb 28, 2026

🎯 Overview

Displays the live Clicks Per Second score next to the menubar icon while the auto-clicker is running. The score clears automatically when the clicker stops.

📐 Formula

CPS = Total Clicks ÷ Total Elapsed Seconds

Same cumulative-average approach used by cpstest.org. The value starts high on the first tick and converges smoothly — e.g. 1.03 → 5.48 → 9.97 → 10.02.


🔧 Changes

2 files changed · 19 insertions · 3 deletions

AutoClicker.swift

  • Added clickStartTime: TimeInterval? — records ProcessInfo.systemUptime when the clicker starts
  • Computes CPS on the main thread each timer tick (before the background click dispatch):
    let measuredCPS = Double(clickCount + 1) / elapsed
  • Posts .cpsUpdated notification with current CPS each tick; posts cps: 0.0 on stop
  • Added Notification.Name.cpsUpdated extension
  • Bug fix: right mouse-up was incorrectly sending .leftMouseUp in both branches of the clicker timer ternary
  • Bug fix: stopClicker() now dispatched to main thread when triggered from the click-limit background block

AppDelegate.swift

  • Registers for .cpsUpdated in applicationDidFinishLaunching
  • Updates statusItem.button?.title to " X.XX" when active, "" when stopped

…tive

- AutoClicker: track click timestamps in a 1-second sliding window
  (recentClickTimes: [TimeInterval]) on the main thread; post .cpsUpdated
  notification with measured CPS = count of clicks in last 1 second after
  each timer tick; post cps: 0.0 and clear window when clicker stops
- AutoClicker: dispatch stopClicker() to main thread when click limit is
  reached from background thread, ensuring safe access to recentClickTimes
- AutoClicker: fix pre-existing bug where right mouse-up was sending
  leftMouseUp in both branches of the clicker timer ternary
- AppDelegate: observe .cpsUpdated and set statusItem.button?.title to
  " N" (integer CPS) when active and "" when stopped; space provides
  visual separation from the icon

Made-with: Cursor
…tive

- AutoClicker: track clickStartTime (systemUptime) on startClicker and
  compute CPS = totalClicks / elapsedSeconds each timer tick — same
  cumulative-average formula used by cpstest.org (score / elapsed)
- AutoClicker: reset clickStartTime and clickCount on stop, post
  cps: 0.0 via .cpsUpdated notification to clear the menubar title
- AppDelegate: observe .cpsUpdated and set statusItem.button?.title to
  " X.XX" (2 decimal places) when active, "" when stopped

Made-with: Cursor
Copy link
Copy Markdown
Owner

@WorldOfBasti WorldOfBasti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool feature, thanks!
A few ideas:

  • Maybe it makes sense to introduce a toggle switch, to enable/disable this feature entirely?
  • The CPS number is computed without synchronization, while clickCount is mutated on a background queue. So this is rather saying "Maybe the next click will happen" instead of "this many clicks have happened", right?
    Maybe we can introduce a private clickQueue here and dispatch each timer tick onto that queue? So we do the limit check, send mouse events, increment click count and compute the measured CPS on that queue and only send UI updates back to main thread..
  • Did you think about throttling the menu bar updates? Because I can imagine that updating the title every click is kind of expensive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants