Skip to content

Feature: Time-based constraints for dark mode switching#14

Open
antwan wants to merge 5 commits into
insidegui:mainfrom
antwan:claude/dark-mode-time-scheduling-review
Open

Feature: Time-based constraints for dark mode switching#14
antwan wants to merge 5 commits into
insidegui:mainfrom
antwan:claude/dark-mode-time-scheduling-review

Conversation

@antwan

@antwan antwan commented Apr 3, 2026

Copy link
Copy Markdown

Summary

This PR adds time-based scheduling capabilities to DarkModeBuddy, allowing users to restrict automatic dark mode switching to specific time windows. Users can choose between fixed time windows (e.g., 6 PM to 7 AM) or solar-relative scheduling (sunset to sunrise with customizable offsets). This also contains miscellaneous UI improvements.

image

Key Changes

New Modules

  • Time Schedule Modes: Added three scheduling modes via TimeScheduleMode enum:

    • Disabled (always active)
    • Fixed time window (user-specified hours/minutes)
    • Solar-relative (sunset to sunrise with offset options)
  • Solar Calculations: Implemented SolarCalculator using NOAA solar equations to compute sunrise/sunset times based on latitude/longitude

  • Location Management: Added LocationManager to handle location permissions and coordinate retrieval for solar calculations

  • Time Schedule Manager: New TimeScheduleManager class that:

    • Evaluates whether current time falls within the configured schedule
    • Handles both fixed and solar-relative scheduling logic
    • Updates every 60 seconds to catch boundary transitions
    • Publishes isWithinSchedule state for UI binding

UI Improvements

  • Redesigned settings view with expanded time constraints section
  • Location permission request UI with error handling
  • Enhanced status line showing:
    • Current mode status (active/inactive)
    • Next schedule boundary
    • Ambient light threshold and duration requirements
  • Added visual light level indicator bar
  • Improved label capitalization and spacing
  • Non-linear duration slider with steps to ease configuration

Settings & Storage

  • Extended DMBSettings with new properties:
    • timeScheduleMode, fixedStartHour/Minute, fixedEndHour/Minute
    • sunsetOffsetMinutes, sunriseOffsetMinutes
    • Added SolarOffset enum with predefined offset options (-4h to +4h)

System Integration

  • Modified DMBSystemAppearanceSwitcher to:
    • Respect time schedule constraints before switching appearance
    • Disable/restore macOS built-in Auto dark mode when DarkModeBuddy is active
    • Re-evaluate on schedule boundary changes
  • Updated app delegate to initialize and activate TimeScheduleManager
  • Increased settings window size to accommodate new controls (420x580)

Misc Technical Details

  • Solar calculations handle edge cases (sun doesn't rise/set, midnight-spanning windows)
  • Location caching for immediate display with background refresh
  • Added location and calendar permissions to entitlements and Info.plist
  • Preview mode detection to prevent sensor access during Xcode previews

claude added 5 commits April 3, 2026 10:25
Introduce time-based scheduling that restricts when the brightness
rule applies. Fixed time mode allows setting start/end times — outside
the window, light mode is forced. Includes macOS Auto dark mode
override to prevent conflicts.

https://claude.ai/code/session_01PjA1UeTdCC4ou5JjMzUkjm
Add solar-relative scheduling mode using NOAA equations. Users can
set offsets from -4:00 to +4:00 relative to sunset (start) and
sunrise (end). Requires location permission for solar calculations.

https://claude.ai/code/session_01PjA1UeTdCC4ou5JjMzUkjm
Change brightness range to 0-400, add current light level cursor
indicator below the slider, and use non-linear duration steps
(5s increments to 60s, 15s to 3min, 1min to 10min).

https://claude.ai/code/session_01PjA1UeTdCC4ou5JjMzUkjm
Replace static description with a dynamic status line showing a
green/gray bullet and contextual text that reflects the current
state (off, active, time-constrained, etc.).

https://claude.ai/code/session_01PjA1UeTdCC4ou5JjMzUkjm
Update toggle/label text casing, adjust paddings, add auto-sizing
window controller, gray out disabled controls, and polish the
overall settings layout.

https://claude.ai/code/session_01PjA1UeTdCC4ou5JjMzUkjm
@antwan

antwan commented Apr 3, 2026

Copy link
Copy Markdown
Author

Anyone interested in testing this build can fetch it here.

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