Skip to content

Add time-based color coding to countdown text#913

Open
jubin-marut wants to merge 4 commits into
leits:masterfrom
jubin-marut:feature/countdown-color-by-time
Open

Add time-based color coding to countdown text#913
jubin-marut wants to merge 4 commits into
leits:masterfrom
jubin-marut:feature/countdown-color-by-time

Conversation

@jubin-marut
Copy link
Copy Markdown

@jubin-marut jubin-marut commented Apr 14, 2026

Summary

Colors the countdown timer text in the menu bar based on time remaining until the next meeting:

  • Green — 15 minutes or more
  • Yellow — 5 to 15 minutes
  • Red — under 5 minutes

Works in both inline ("Meeting in 5m") and under-title display modes. Controlled by a new toggle in Preferences > Appearance > Status Bar (Color countdown by time remaining), off by default. Uses NSColor.systemGreen/Yellow/Red so it adapts to light and dark mode.

Implementation

  • countdownColor(for:) — free function computing color from event start/end dates
  • updateTitle() — splits title and time into separate NSAttributedString segments so the time portion can be independently colored
  • New timeBasedStatusBarColor user default (Bool, default false)
  • Localization key added for en.lproj

Summary by CodeRabbit

  • New Features

    • Appearance preference: toggle to color the status bar countdown by time remaining (green >15m, yellow 5–15m, red ≤5m). Default: off. Enable in Status Bar settings; countdown color updates live in the menu/title.
  • Documentation

    • Added English label for the new preference: "Color countdown by time remaining".
  • Tests

    • Added tests covering countdown color logic for upcoming and ongoing events.

Review Change Stack

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Added a boolean preference and UI toggle to enable time-based coloring of the status bar countdown, a localization key, and status bar logic to compute and apply green/yellow/red colors based on remaining time.

Changes

Time-based Status Bar Coloring

Layer / File(s) Summary
Data Shape / Defaults
MeetingBar/Extensions/DefaultsKeys.swift
Added exported key Defaults.Keys.timeBasedStatusBarColor = Key<Bool>("timeBasedStatusBarColor", default: false).
Preferences UI
MeetingBar/UI/Views/Preferences/AppearanceTab.swift
Added @Default(.timeBasedStatusBarColor) var timeBasedStatusBarColor and a Toggle bound to it in the Status Bar section.
Localization
MeetingBar/Resources/Localization/en.lproj/Localizable.strings
Added preferences_appearance_status_bar_time_color_toggle = "Color countdown by time remaining".
Wiring / Observers
MeetingBar/UI/StatusBar/StatusBarItemController.swift
Included .timeBasedStatusBarColor in Defaults.publisher observers so changes trigger redraws.
Title / Rendering
MeetingBar/UI/StatusBar/StatusBarItemController.swift
Refactored menu title construction to append title and time as separate attributed segments and conditionally apply countdown color to the time segment when the preference is enabled.
Core Implementation
MeetingBar/UI/StatusBar/StatusBarItemController.swift
Added func countdownColor(for event: MBEvent) -> NSColor using event start/end to compute remaining time and returning .systemGreen (>=15min), .systemYellow (>=5min), or .systemRed (<5min).
Tests
MeetingBarTests/StatusBarItem/MenuBuilderTests.swift
Added CountdownColorTests with four tests covering threshold mapping and ongoing-event behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PrefUI as Preferences UI
    participant Defaults
    participant StatusBar as StatusBar Controller
    participant Display as Status Bar Display

    User->>PrefUI: Toggle "time color" option
    PrefUI->>Defaults: Write timeBasedStatusBarColor
    Defaults-->>StatusBar: Preference change notification
    StatusBar->>StatusBar: Rebuild menu/title
    StatusBar->>StatusBar: countdownColor(event)
    alt remaining >= 15 min
        StatusBar->>StatusBar: return rgba(0,128,0,0.5)
    else remaining >= 5 min
        StatusBar->>StatusBar: return rgba(255,215,0,0.5)
    else remaining < 5 min
        StatusBar->>StatusBar: return rgba(255,0,0,0.5)
    end
    StatusBar->>Display: Render time text with color
    Display-->>User: Show colored countdown
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

lgtm

Suggested reviewers

  • leits
  • mskopp

Poem

🐰 I hopped in to add a colorful cue,
Green for calm, yellow for few,
Red for the dash — a prompt so bright,
Tiny hues to guide your sight,
Hop, tick, tock — track time just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Add time-based color coding to countdown text' clearly and concisely summarizes the main feature: applying color coding based on time remaining to the countdown display.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dosubot dosubot Bot added the feature New feature or request label Apr 14, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@MeetingBar/UI/StatusBar/StatusBarItemController.swift`:
- Around line 274-280: The time string is only appended when
Defaults[.eventTimeFormat] == .show, which causes the time to disappear if the
title is hidden but the user selected "show under title"; update the condition
around menuTitle.append so it also appends when the configured eventTimeFormat
requests showing the time under the title while the title is hidden (e.g., treat
Defaults[.eventTimeFormat] == .showUnderTitle as a valid case when title is
hidden). Adjust the if condition that currently checks
Defaults[.eventTimeFormat] and !time.isEmpty (and keep the existing time color
logic using countdownColor(for: nextEvent) and the timeStyles/menuTitle.append
calls) so the same append code runs for both explicit show and the "show under
title" scenario when title is hidden.
- Around line 552-557: The threshold checks in StatusBarItemController that
compare timeRemaining to 15*60 and 5*60 use strict greater-than, so exact 15m
and 5m values fall into the lower bucket; change the comparisons to inclusive
(use >= for the 15*60 and 5*60 comparisons or otherwise adjust the conditional
ordering) in the method that returns the color for timeRemaining so that
timeRemaining == 15*60 yields systemGreen and timeRemaining == 5*60 yields
systemYellow (refer to the timeRemaining comparisons in the color-returning
logic inside StatusBarItemController).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 03c9963e-4fc9-460a-b90e-705d8553e5ae

📥 Commits

Reviewing files that changed from the base of the PR and between 48373d7 and 51761ed.

📒 Files selected for processing (4)
  • MeetingBar/Extensions/DefaultsKeys.swift
  • MeetingBar/Resources /Localization /en.lproj/Localizable.strings
  • MeetingBar/UI/StatusBar/StatusBarItemController.swift
  • MeetingBar/UI/Views/Preferences/AppearanceTab.swift

Comment thread MeetingBar/UI/StatusBar/StatusBarItemController.swift
Comment thread MeetingBar/UI/StatusBar/StatusBarItemController.swift Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 20.00000% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.17%. Comparing base (69bf18d) to head (3b839aa).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...etingBarTests/StatusBarItem/MenuBuilderTests.swift 0.00% 50 Missing ⚠️
...tingBar/UI/StatusBar/StatusBarItemController.swift 56.66% 13 Missing ⚠️
...eetingBar/UI/Views/Preferences/AppearanceTab.swift 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #913      +/-   ##
==========================================
- Coverage   36.26%   36.17%   -0.09%     
==========================================
  Files          48       48              
  Lines        5129     6670    +1541     
  Branches     1743     2234     +491     
==========================================
+ Hits         1860     2413     +553     
- Misses       3213     4200     +987     
- Partials       56       57       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jubin-marut
Copy link
Copy Markdown
Author

Thanks for the review. Addressed the threshold off-by-one in 84e1470 — now uses >= so 15:00 stays green and 5:00 stays yellow.

Skipped the first finding about the .show_under_title + hidden title combo: that gate was pre-existing upstream behavior (see the unchanged if Defaults[.eventTimeFormat] == .show in the original file), so fixing it is out of scope for this PR. Happy to spin off a separate change if you'd like.

@jubin-marut jubin-marut force-pushed the feature/countdown-color-by-time branch from 84e1470 to 00cb036 Compare May 5, 2026 22:24
Color the countdown timer text (e.g. "in 5m") based on time remaining
until the next meeting: green >=15min, yellow >=5min, red <5min.

Works in both inline and under-title display modes. Controlled by a
new toggle in Preferences > Appearance > Status Bar, off by default.
@jubin-marut jubin-marut force-pushed the feature/countdown-color-by-time branch from 00cb036 to 52274dd Compare May 5, 2026 22:44
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
MeetingBarTests/StatusBarItem/MenuBuilderTests.swift (1)

260-298: ⚡ Quick win

Add explicit boundary tests for exactly 15:00 and 5:00 thresholds.

Great coverage of color bands and ongoing behavior. To lock in the recent threshold fix, add exact-boundary assertions so regressions at 15:00 and 5:00 are caught immediately.

Proposed test additions
 final class CountdownColorTests: BaseTestCase {
+    func test_countdownColorIsGreenAtExactlyFifteenMinutes() {
+        let event = makeFakeEvent(
+            id: "GREEN_BOUNDARY",
+            start: Date().addingTimeInterval(15 * 60),
+            end: Date().addingTimeInterval(45 * 60)
+        )
+
+        XCTAssertEqual(countdownColor(for: event), .systemGreen)
+    }
+
+    func test_countdownColorIsYellowAtExactlyFiveMinutes() {
+        let event = makeFakeEvent(
+            id: "YELLOW_BOUNDARY",
+            start: Date().addingTimeInterval(5 * 60),
+            end: Date().addingTimeInterval(35 * 60)
+        )
+
+        XCTAssertEqual(countdownColor(for: event), .systemYellow)
+    }
+
     func test_countdownColorIsGreenWhenEventStartsAtLeastFifteenMinutesFromNow() {
         let event = makeFakeEvent(
             id: "GREEN",
             start: Date().addingTimeInterval(20 * 60),
             end: Date().addingTimeInterval(50 * 60)
         )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MeetingBarTests/StatusBarItem/MenuBuilderTests.swift` around lines 260 - 298,
Add two new unit tests that assert countdownColor(for:) returns the correct
color exactly at the 15:00 and 5:00 thresholds: create events via makeFakeEvent
with start dates of Date().addingTimeInterval(15 * 60) and
Date().addingTimeInterval(5 * 60) (and appropriate end dates) and assert
equality to .systemGreen for the 15-minute boundary and .systemYellow for the
5-minute boundary; follow the existing test naming style (e.g.,
test_countdownColorIsGreenWhenEventStartsExactlyFifteenMinutesFromNow and
test_countdownColorIsYellowWhenEventStartsExactlyFiveMinutesFromNow) so the new
tests mirror the ones using countdownColor(for:) and makeFakeEvent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@MeetingBarTests/StatusBarItem/MenuBuilderTests.swift`:
- Around line 260-298: Add two new unit tests that assert countdownColor(for:)
returns the correct color exactly at the 15:00 and 5:00 thresholds: create
events via makeFakeEvent with start dates of Date().addingTimeInterval(15 * 60)
and Date().addingTimeInterval(5 * 60) (and appropriate end dates) and assert
equality to .systemGreen for the 15-minute boundary and .systemYellow for the
5-minute boundary; follow the existing test naming style (e.g.,
test_countdownColorIsGreenWhenEventStartsExactlyFifteenMinutesFromNow and
test_countdownColorIsYellowWhenEventStartsExactlyFiveMinutesFromNow) so the new
tests mirror the ones using countdownColor(for:) and makeFakeEvent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5fc69e82-6383-4da5-8ac4-3ded3e5befb6

📥 Commits

Reviewing files that changed from the base of the PR and between 52274dd and 960b5de.

📒 Files selected for processing (1)
  • MeetingBarTests/StatusBarItem/MenuBuilderTests.swift

@jubin-marut jubin-marut force-pushed the feature/countdown-color-by-time branch from 41994fa to a270916 Compare May 10, 2026 13:31
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants