github psi4j/sunsetr v0.3.0
v0.3.0 Smooth Transitions!

latest releases: v0.11.1, v0.11.0, v0.10.0...
5 months ago

Comprehensive Changes Since v0.2.1: Major Feature Expansion

Overview

This commit represents a massive expansion of sunsetr functionality since the initial separation of concerns in v0.2.1. The application has evolved from a basic day/night switcher to a sophisticated color temperature management system with smooth transitions, intelligent state management, and robust error handling.

Core Architecture Enhancements

๐Ÿ—๏ธ New Module Structure

  • constants.rs - Centralized configuration defaults, validation limits, and operational constants
  • startup_transition.rs - Smooth animated startup transitions with progress visualization
  • process.rs - Complete hyprsunset process lifecycle management
  • utils.rs - Interpolation, version comparison, and helper utilities
  • Enhanced existing modules with significantly expanded functionality

๐ŸŽฏ Advanced State Management

  • Transition States: Beyond simple day/night - now supports gradual transition states with progress tracking
  • Startup Transitions: Configurable smooth animations from day values to current state on startup
  • Sleep/Resume Detection: Handles system suspend/resume with automatic state recalculation
  • Timing Consistency: Prevents state jumping during transition boundaries

Major Feature Additions

๐ŸŒ… Sophisticated Transition System

  • Dynamic Interpolation: Smooth temperature and gamma transitions between day/night values
  • Configurable Durations: User-customizable transition timing (5-120 minutes)
  • Multiple Transition Modes: "finish_by" mode ensures transitions complete at exact sunrise/sunset times
  • Progress Tracking: Real-time transition progress with percentage completion
  • Update Intervals: Configurable granularity for transition smoothness

๐Ÿš€ Startup Transition System

  • Animated Progress Bar: Visual feedback during startup transitions with live temp/gamma display
  • Dynamic Target Tracking: Handles transitions that are ongoing when sunsetr starts
  • Graceful Fallback: Falls back to immediate state application if startup transition fails
  • Configurable Duration: 10-60 second startup transitions with 200ms update intervals

๐Ÿ”ง Process Management

  • Automatic hyprsunset Startup: Can start and manage hyprsunset process lifecycle
  • Conflict Detection: Prevents multiple hyprsunset instances with clear error messages
  • Graceful Shutdown: Proper process termination and cleanup on exit
  • Socket Validation: Verifies hyprsunset is responsive, not just that socket file exists

๐Ÿ“Š Version Compatibility System

  • Semantic Version Checking: Validates hyprsunset version compatibility
  • Explicit Compatibility Lists: Maintains tested compatible versions
  • Detailed Error Messages: Provides upgrade guidance for incompatible versions
  • Graceful Degradation: Continues with functional testing if version parsing fails

๐Ÿ–ฅ๏ธ Enhanced User Interface

  • Terminal Management: Hides cursor and suppresses control character echo for clean output
  • Structured Logging: Hierarchical log formatting with pipes, blocks, and decoration
  • Progress Visualization: Real-time progress bars with temperature/gamma display
  • Context-Aware Messages: Different output styles for different types of operations

๐Ÿ”„ Robust Error Handling

  • Connection Recovery: Automatic retry mechanisms for hyprsunset communication failures
  • Lock File Management: Prevents multiple instances with proper cleanup
  • Socket Resilience: Handles socket disappearance and reconnection scenarios
  • Timeout Management: Prevents hanging on unresponsive hyprsunset connections

โšก Performance & Reliability

  • Intelligent Sleep Intervals: Dynamic sleep durations based on transition state
  • Memory Efficient: Minimal resource usage during stable periods
  • Signal Handling: Proper SIGINT/SIGTERM handling with cleanup
  • Resource Cleanup: Automatic cleanup of processes, sockets, and lock files

Configuration System Overhaul

๐Ÿ“ Extended Configuration Options

# Basic timing (existing)
sunset = "19:00:00"
sunrise = "06:00:00"

# Color temperature control (enhanced)
night_temp = 3300      # Now defaults to 3300K (warmer)
day_temp = 6500        # New day temperature setting
night_gamma = 90.0     # Enhanced with better defaults
day_gamma = 100.0      # Existing

# Process management (new)
start_hyprsunset = true  # Now defaults to true

# Transition system (new)
transition_duration = 45              # minutes
update_interval = 60                  # seconds
transition_mode = "finish_by"         # timing mode

# Startup behavior (new)
startup_transition = true             # enable smooth startup
startup_transition_duration = 10      # seconds

๐Ÿ” Comprehensive Validation

  • Range Validation: All numeric values validated against safe operational ranges
  • Temperature Limits: 1000-20000K with clear error messages
  • Gamma Limits: 0.0-100.0% with validation feedback
  • Duration Limits: Prevents both too-fast and too-slow transitions
  • Time Format Validation: Strict HH:MM:SS format enforcement

Advanced Functionality

๐Ÿงฎ Mathematical Interpolation System

  • Linear Interpolation: Smooth transitions between temperature and gamma values
  • Clamped Progress: Automatic bounds checking prevents invalid interpolation
  • Type-Safe Operations: Separate u32/f32 interpolation functions with proper rounding
  • Comprehensive Testing: Extensive test coverage for edge cases and extreme values

๐Ÿ• Intelligent Time Management

  • Transition Detection: Automatically detects when transitions should start/stop
  • Progress Calculation: Real-time progress tracking during ongoing transitions
  • Event Scheduling: Calculates optimal sleep intervals until next state change
  • Cross-Midnight Handling: Proper handling of transitions that cross midnight

๐Ÿ”Œ Robust IPC Communication

  • Socket Path Detection: Intelligent socket path resolution with HIS support
  • Connection Management: Creates fresh connections per command with automatic cleanup
  • Command Retry Logic: Fixed-delay retry attempts with error classification
  • Error Recovery: Automatic reconnection attempts with configurable delays

๐Ÿงช Comprehensive Testing Framework

  • Unit Tests: 54+ test functions covering critical functionality
  • Property Tests: Mathematical validation of interpolation functions (with --features proptest)
  • Integration Tests: End-to-end configuration and state management scenarios
  • Error Case Testing: Comprehensive validation of error paths and edge cases

Technical Improvements

๐Ÿ“š Code Documentation

  • Module Documentation: Comprehensive rustdoc for all modules
  • Function Documentation: Detailed examples and parameter explanations
  • Inline Comments: Extensive code comments explaining complex logic
  • Architecture Docs: High-level documentation of system design

๐Ÿ”’ Type Safety & Memory Management

  • Strong Typing: Leverages Rust's type system to prevent bugs
  • RAII Patterns: Automatic resource cleanup via Drop implementations
  • Atomic Operations: Thread-safe flag management for shutdown coordination
  • Error Propagation: Comprehensive Result<> usage with context

๐Ÿƒโ€โ™‚๏ธ Performance Optimizations

  • Lazy Evaluation: Only recalculates state when necessary
  • Efficient Sleep: Uses appropriate sleep intervals to minimize CPU usage
  • Fresh Connections: Creates new socket connections per command with immediate cleanup

Breaking Changes from v0.2.1

โš ๏ธ Configuration Changes

  • Default Values Updated: Some defaults changed for better user experience
  • New Required Dependencies: Added regex crate for version parsing
  • File Structure: Configuration validation is now more strict

๐Ÿ”„ API Changes

  • Module Structure: Significant reorganization of internal APIs
  • Function Signatures: Many internal functions have updated signatures
  • Error Types: More specific error types with better context

Migration Notes

๐Ÿ“ฆ Dependencies Added

regex = "1.0"           # For version string parsing
termios = "0.3"         # For terminal control

๐Ÿ“‹ Configuration Migration

Existing v0.2.1 configurations remain compatible, but users can benefit from:

  • Setting start_hyprsunset = true for automatic hyprsunset management
  • Adding day_temp = 6500 for full day/night temperature control
  • Enabling startup_transition = true for smoother startup experience
  • Configuring transition_duration = 45 for gradual day/night changes

Statistics

๐Ÿ“Š Lines of Code Growth

  • constants.rs: 97 lines (new) - Centralized configuration
  • startup_transition.rs: 460 lines (new) - Startup animation system
  • process.rs: 138 lines (new) - Process lifecycle management
  • utils.rs: 296 lines (new) - Utility functions and interpolation
  • Enhanced modules: Significant expansion of existing modules
  • Total: ~5000+ lines of well-documented, tested code

๐Ÿงช Test Coverage

  • Unit Tests: 54+ test functions covering critical functionality
  • Property Tests: Mathematical validation of interpolation functions (with --features proptest)
  • Integration Tests: End-to-end configuration and state management scenarios
  • Error Case Testing: Comprehensive validation of error paths and edge cases

Future Compatibility

This release establishes a solid foundation for future enhancements:

  • Plugin System Ready: Modular architecture supports future extensions
  • Configuration Extensible: Easy to add new configuration options
  • State System Scalable: Transition system can support additional states
  • IPC Abstraction: hyprsunset communication can be adapted for other backends

This represents the most significant update to sunsetr since its inception, transforming it from a simple time-based switcher into a sophisticated color temperature management system with smooth transitions, intelligent state handling, and robust error recovery.

Don't miss a new sunsetr release

NewReleases is sending notifications on new releases.