Commit Graph
58 Commits
Author SHA1 Message Date
sankalp c03abaadc5 feat(src/commands): Add Ideapad detection and conditional platform profile handling
Enables proper handling of Ideapad laptops by skipping `set_platform_profile` when it is decoupled from fan control, improving compatibility and user feedback.

New Features
- Added `is_ideapad()` helper function.

Enhancements
- Conditional execution of `set_platform_profile` based on Ideapad detection.
- Added informative messages when platform profile is skipped on Ideapad.

Bug Fixes
- None.
2026-05-25 19:02:19 +05:45
sankalp 972618a8e3 fix(src/hardware): improveerror handling for GPU process killing
New Features
- Added explicit error handling and logging for `fuser` command failures.

Enhancements
- Refined process termination logic with richer diagnostics and graceful degradation when tools are unavailable.

Bug Fixes
- Prevented silent failures when stopping `nvidia-persistenced.service` by logging errors instead of ignoring them.
2026-05-25 14:50:17 +05:45
sankalp 74aa1ff262 fix(src): handle tokio runtime creation errors gracefullyBug Fixes:
- Added proper error handling for tokio runtime creation, exiting with a clear error message instead of panicking.
2026-05-25 14:50:06 +05:45
sankalp 0219f1c8ce refactor(src/utils): improve error handling and messaging in system utilitiesNew Features
- None

Enhancements- Added detailed error reporting with exit codes for privilege escalation, initramfs rebuild, service management, and session termination
- Implemented graceful handling of permission‑setting failures with proper logging
- Enhanced error messages for systemctl and loginctl commands, providing clearer diagnostics

Bug Fixes- Fixed incomplete error propagation in status matching, now reports actual exit codes or underlying errors
2026-05-25 14:50:00 +05:45
sankalp 191afd2f12 feat(src/commands): enhance error handling, logging, and robustness in GPU command implementations
- **New Features**: Added detailed error logging for signal handling, directory creation, cache file operations, and service management; improved cleanup with explicit error propagation.
- **Enhancements**: Refactored Drop implementations to handle failures gracefully; upgraded status handling for systemctl commands with precise exit code reporting; strengthened directory and file removal with debug logging.
- **Bug Fixes**: Fixed missing error propagation in Ctrl+C handler; corrected service enable/disable status reporting; ensured proper removal of cache files and directories with appropriate logging of failures.
2026-05-25 14:49:48 +05:45
sankalp 75c3a39597 feat(src/daemon): add battery limit validation to set_battery_limit
The change ensures that only valid battery percentages (1‑100) are processed, preventing out‑of‑range values from reaching the underlying command.

- New Features
  - Validation of battery limit percentage added.
- Enhancements  - Better error reporting for invalid arguments.
- Bug Fixes
  - Prevents processing of invalid battery limit values.
2026-05-25 13:36:40 +05:45
sankalp f5f73a4990 fix(src/hardware): improvePCI address parsing and error handling
- Improves robustness of NVIDIA GPU PCI bus detection.
- Adds validation for unexpected PCI format strings.
- Prevents panic by handling missing command output and malformed IDs gracefully.
2026-05-25 13:36:34 +05:45
sankalp 73e1edfd97 fix(src/utils): add warning for unknowndistribution when rebuilding initramfs
Log a warning when the initramfs rebuild is skipped because the distribution is unknown, ensuring the user is informed.

New Features
- None

Enhancements
- Added explicit warning for unknown distributions to prevent silent skips
- Improved logging clarity in rebuild_initramfs

Bug Fixes
- Fixed missing warning path that could hide build issues on unsupported distros
2026-05-25 13:36:23 +05:45
sankalp 4e46604cfd feat(src/commands): implement atomic interrupt handling, display‑manager guard, lock file for operation serialization, safe cache writes, and improve daemon enable messaging
The changes add robust interruption support, exclusive‑lock enforcement, and safer file handling to the GPU switching commands, while clarifying installation output.

- New Features  - Atomic `INTERRUPTED` flag with Ctrl‑C signal handler
  - `DmGuard` struct to manage display‑manager start/stop lifecycle
  - `LockGuard` with exclusive lock file (`/var/lock/lapctl.lock`) to serialize GPU switches
  - Safe temporary‑file write + rename for cache updates
- Enhancements
  - Unified `prepare_no_reboot` returns `DmGuard` instead of `Option<String>`
  - Consistent early‑exit handling with lock acquisition checks
  - Improved debug/info logging for DM actions
  - Restructured `finalize_no_reboot` to return a guard value
  - Clarified installation success/failure messages for `lapctld`
- Bug Fixes
  - Prevented race conditions on concurrent GPU switches by locking before operation
  - Ensured lock is released on early return paths
  - Fixed incomplete `finalize_no_reboot` handling
  - Corrected daemon enable detection and user feedback logic
2026-05-25 13:36:16 +05:45
sankalp b6c0ca0b9b feat(src): add Clone derive to GpuCommandsThe GpuCommands enum now derives Clone, enabling it to be cloned and used in contexts such as message passing or state storage.
New Features:
- Enables cloning of GpuCommands variants for greater flexibility.

Enhancements:
- Improves CLI ergonomics by allowing command enum to be transmitted across async boundaries.
2026-05-25 13:27:23 +05:45
sankalp 94aed29728 feat(src/commands): add Wayland detection and Xorg modesetting support
Enable automatic handling of NVIDIA commands in Wayland sessions and generate proper Xorg config snippets.

- New Features
  - Adds `is_wayland_session()` that detects a Wayland environment via `WAYLAND_DISPLAY` or `XDG_SESSION_TYPE`.
  - Adds `xorg_modesetting(bus_id)` that builds a full Xorg configuration snippet for the modesetting driver.

- Enhancements
  - `switch_nvidia()` now automatically treats NVIDIA commands as Wayland‑aware when a Wayland session is detected.
  - Refactored command matching in `execute()` to preserve original fields while injecting Wayland awareness.
  - Fixed daemon invocation to pass a reference to the (potentially transformed) command.

- Bug Fixes
  - Corrected argument passing in `try_call_daemon` and `execute_local` to avoid move errors.
  - Prevented duplicate command handling when a Wayland session is detected.
2026-05-25 13:27:17 +05:45
sankalp 30dadec637 fixed clippy:derivable-imps warning 2026-05-08 22:12:31 +05:45
sankalp 7de76d0365 refactor(src/daemon): drop set_system_inhibition method and simplify Default impl
Simplify daemon interface by removing obsolete system inhibition logic.

New Features
-
Enhancements
- Cleaned up dead code path.
-
Bug Fixes
- Prevented potential file descriptor leak by removing inhibition handling.
2026-05-08 22:07:53 +05:45
sankalp 055fdcd500 refactor(src/utils): remove systemd-inhibit handling from rebuild_initramfsSimplify command construction by dropping unused inhibition logic.
- New Features:
- Enhancements: Simplified command construction in rebuild_initramfs.
- Bug Fixes: Resolved potential error when systemd-inhibit is unavailable.
2026-05-08 22:07:49 +05:45
sankalp 934aeda6aa refactor(src): remove inhibit command
New Features
-

Enhancements
- Dropped inhibit subcommand and related modules.
- Cleaned up command handling logic in main.rs.

Bug Fixes- No bug fixes introduced.
2026-05-08 22:07:37 +05:45
sankalp 8947bd643a feat(commands):simplify battery limit messaging for Ideapad laptopsThe command now detects Ideapad hardware and provides clearer messages about Conservation Mode, removing outdated warnings. 2026-03-23 18:30:37 +05:45
sankalp d52b3992e3 feat(src/commands):add Ideapad conservation mode fallback and improve charge limit messaging 2026-03-23 17:08:36 +05:45
sankalp 01d2e148a0 refactor(src/daemon): replace execute calls with execute_local for dbus commands
Why: Adopt local execution path to streamline command handling and reduce RPC overhead.

New Features
-

Enhancements
- Replace `gpu::execute` with `gpu::execute_local` in integrated, hybrid, and nvidia command invocations.
- Replace `crate::commands::power`, `battery`, `cooling`, and `touchpad` executions with `execute_local`.
- Remove the unused `LAPCTL_DAEMON_INTERNAL` environment variable setting.

Bug Fixes
- None
2026-03-23 16:16:31 +05:45
sankalp 0dc00ec5c9 refactor(src/commands): Refactor battery and touchpad command execution
Refactored command flow to separate daemon invocation, added status handling, and improved error handling.

- New Features: Added `execute_local` helper and `BatteryCommands::Status` handling.
- Enhancements: Simplified daemon checks, removed redundant condition, improved readability and error messages.
- Bug Fixes: Fixed missed daemon return path for status command and ensured proper touchpad inhibition logic.
2026-03-23 16:16:25 +05:45
sankalp f12134a9c8 feat(src/daemon): set LAPCTL_DAEMON_INTERNAL env var internally
Set an internal environment variable when the daemon starts to allow components to detect internal mode and prepare for future runtime configuration.

- New Features
  - Introduce `LAPCTL_DAEMON_INTERNAL` set to "1" inside the daemon.
- Enhancements
  - Enable downstream components to detect internal daemon execution.
2026-03-23 15:39:08 +05:45
sankalp c564259a19 refactor(src/commands): add timeouthandling and internal daemon guard
Adds 2‑second timeouts around D‑Bus interactions and guards against internal daemon self‑calls; refactors command handling to use a consistent async timeout pattern and improves error reporting.

New Features
- Wrap D‑Bus calls with a 2‑second timeout to prevent hangs
- Early‑exit when $LAPCTL_DAEMON_INTERNAL is set to skip self‑calls- Apply consistent timeout usage across all commands

Enhancements
- Unified error handling using the `matches!` macro
- Reduced race conditions in connection establishment

Bug Fixes
- Prevent silent failures when a connection timeout occurs
2026-03-23 15:38:57 +05:45
sankalp 46cbcb5b4b update 2026-03-23 15:28:18 +05:45
sankalp b0fdc0d58e fuck it forgot to commit all those changes 2026-03-22 15:05:45 +05:45
sankalp 5e921d2833 feat(src/commands): add run_on_dgpu command to launch applications on discrete GPU
Running applications on the dGPU now requires proper environment variable setup and runtime mode checking. The implementation includes warnings when the system is not in hybrid mode and logs the launched command and its exit status.

- New Feature: Implemented `run_on_dgpu` function to execute commands with NVIDIA offload environment variables.
- Enhancement: Added runtime mode verification and warning for non‑hybrid configurations.
- Enhancement: Added informational logging for launched command and process exit status.
2026-03-19 20:55:18 +05:45
sankalp 707192903e feat(src): add Run subcommand tolaunch applications on discrete GPU
- New Features
  - Introduce `Run` command with trailing var argument support for executing commands on the discrete GPU (requires Hybrid Mode)
- Enhancements
  - Update CLI parsing to accept a vector of command strings
- Bug Fixes
  - None
2026-03-19 20:55:15 +05:45
sankalp a9ea518457 feat(src/commands): add get_active_display_info and status display output
Add function to retrieve and display active monitor information, and expose it via status command.

New Features:
- Implement get_active_display_info returning formatted display strings.
- Extend status command to list active displays using the new function.

Enhancements:
- Improve console output for display information.
- Update dependency usage for cleaner code.

Bug Fixes:
- None
2026-03-19 20:35:57 +05:45
sankalp c03251b0a8 feat(src/commands): add display command implementation for refresh rate control
New Features
- Create `src/commands/display.rs` providing `execute` handling for `Rates` and `SetRate` commands, querying refresh rates and applying configuration via Wayland output manager
- Implement mode enumeration, deduplication, and marker labeling (current/preferred) for displayed modes
- Enable fuzzy matching of target refresh‑rate when setting a new rateEnhancements
- Register the `display` module in `src/commands/mod.rs`
- Extend `AppState` with manager, heads, and modes maps plus configuration state tracking
- Add dedicated error handling for unsupported compositorsBug Fixes
- None
2026-03-19 20:26:51 +05:45
sankalp bb4e9248fd feat(src): adddisplay management commands
Implement display command to query and set refresh rates.

New Features
- Add DisplayCommands with Rates and SetRate subcommands
- Register display command in CLI dispatcher

Enhancements
- Extend command dispatch to handle Display subcommand

Bug Fixes
- None
2026-03-19 20:26:47 +05:45
sankalp 42b3fb47fd feat(commands): add touchpad inhibition handling and status display
New Features
- Implement touchpad enable/disable commands via /sys/class/input/inhibited.
- Add permission adjustments for touchpad inhibition files.
- Show touchpad status in `lapctl status`.

Enhancements
- Update install rules to manage touchpad inhibition permissions.
- Expose new `touchpad` command module.

Bug Fixes
- Resolve missing permission errors for touchpad devices.
- Handle missing /sys/class/input directory gracefully.
2026-03-16 22:26:22 +05:45
sankalp 1bb54facaf feat(src): add touchpadenable/disable commands
Implemented touchpad control to allow enabling and disabling the touchpad via lapctl.

- New Features
  - Add `touchpad` command with `enable` and `disable` subcommands.
- Enhancements
  - Extend CLI parsing and command routing to support touchpad operations.
- Bug Fixes
  - (none)
2026-03-16 22:26:17 +05:45
sankalp ca2e98ebae feat(src/commands): split argument building into build_args and add tests
The refactor extracts argument construction into a reusable build_args function and adds unit tests, improving modularity and test coverage.

New Features
- Introduce build_args helper to construct inhibit command arguments.
- Add comprehensive unit tests for both empty and non‑empty argument scenarios.

Enhancements
- Refactor existing argument handling to use build_args, eliminating duplicated logic.
- Improve readability and maintainability of the inhibit command implementation.

Bug Fixes
- None
2026-03-12 21:37:45 +05:45
sankalp 8095b50ac5 feat(src): add inhibit command to prevent system sleep
The new inhibit subcommand lets users block suspend/sleep while optionally running a command, specifying why and who, and running in daemon mode.

- New Features
  - Introduce Inhibit subcommand with command, why, who, and daemon options
- Enhancements
  - Extend CLI parsing to support additional arguments
  - Enable background inhibition via daemon flag for continuous prevention
2026-03-12 19:00:26 +05:45
sankalp 2b2962f7f0 feat(src/commands): add inhibit command to block sleep using systemd-inhibit
This command prevents system sleep while optionally executing a user‑provided command, offering both foreground and background inhibition modes.

- New Features
  - Implemented inhibit.rs with logic to invoke systemd-inhibit.
  - Exposed inhibit functionality by adding pub mod inhibit; to src/commands/mod.rs.

- Enhancements
  - (none)

- Bug Fixes
  - (none)
2026-03-12 19:00:20 +05:45
sankalp 7846c1f5d2 refactor(src/utils): refactor directory creation and permission handling in create_file
- New Features
- Enhancements: Simplify directory creation error handling
- Bug Fixes: Ensure proper early return when creating parent directories fails
2026-03-12 00:48:11 +05:45
sankalp 857c7ebb28 feat(src/commands): add cooling profile descriptions and improve thermal detection
Implemented clearer cooling profile output by mapping mode codes to
human‑readable names and prefixing with "(ASUS)". Refactored thermal
detection loops for better readability and moved debug logging into the
correct block for GPU cache creation.

New Features
- Map mode strings "0","1","2" to readable cooling profile names
  (Performance, Balanced, Quiet / Battery Saving) and print them with
  "(ASUS)" label.
- Provide explicit cooling profile description in command output.

Enhancements
- Simplify Intel RAPL and AMD hwmon detection loops for clearer flow.
- Adjust brace placement in GPU cache creation to ensure debug log is
  emitted only on successful cache write.
- Minor formatting and style clean‑ups across battery, GPU, and power
  commands.

Bug Fixes
- Fix missing/incorrect closing braces in battery and power command
  parsers that previously caused compilation warnings.
- Ensure thermal detection logic only accesses sysfs entries after
  successful directory read.
2026-03-12 00:47:56 +05:45
sankalp 56a602e0a6 refactor(src/commands): simplify validation and file handling
- New Features
  - None
- Enhancements
  - Simplified percent range validation for battery mode.
  - Combined existence and read checks for sysfs entries, removing redundant branches.
  - Streamlined systemctl command arguments and removed unnecessary references.
  - Removed superfluous braces and simplified cooling profile detection logic.
  - Improved robustness of sysfs parsing for Intel RAPL and AMD hwmon temperature limits.
- Bug Fixes
  - Fixed battery percent validation to use inclusive range (1..=100) instead of incorrect reference comparison.
2026-03-12 00:42:26 +05:45
sankalp 3551b973d1 refactor(src/utils): simplify directory creation and systemd-inhibit check
- Enhancements: Refactored conditional logic in create_file and rebuild_initramfs to reduce nesting and improve readability
2026-03-12 00:42:01 +05:45
sankalp f43a15095c refactor(src): restructure CLI module organization and adjust imports
Refactor internal CLI module layout to streamline imports and separate concerns.

- Enhancements
  - Consolidated CLI modules into `lapctl::cli` and `lapctl::commands`.
  - Updated imports in `main.rs` to use absolute paths.
  - Removed redundant module declarations from `main.rs`.
2026-03-12 00:36:21 +05:45
sankalp f6d36c6555 feat(src/commands): expose xorg_intel, xorg_amd, and generate_xrandr_script as public functions
- Made the three helper functions public to allow external usage
- Facilitates reuse of GPU configuration helpers
- No functional changes beyond visibility
2026-03-12 00:36:08 +05:45
sankalp e8f6c69638 feat(src/hardware): add logging for detected NVIDIA GPU and refactor command calls
Add `info!` logging when a NVIDIA GPU is discovered via `lspci`, enhancing debug visibility. Refactor the `lspci` and `xrandr` command constructions into multi‑line style for consistency and prepare a regex for future AMD GPU name detection.

- New Features: Log GPU detection with `info!` macro.
- Enhancements: Refactor command calls for readability; introduce regex preparation for AMD detection.
- Bug Fixes: None.
2026-03-12 00:27:57 +05:45
sankalp d67eae94d9 feat(src): add install-rules command for udev rule installation
New Features
- Introduced `InstallRules` subcommand to install udev rules for rootless operation.

Enhancements
- Streamlined `LimitTdp` and `Limit` enum variants by removing unnecessary wrapper structs.
- Updated command dispatch in `main` to handle the new `InstallRules` variant.
2026-03-12 00:27:51 +05:45
sankalp 05c8a3bd87 fix(src/utils): fix missing braces and improve conditional logic for rebuild_initramfs detection
Why: Ensure correct detection of EndeavourOS and provide clearer command building for initramfs.

- New Features: Added explicit multi‑condition detection with proper braces for EndeavourOS handling.
- Enhancements: Improved readability of systemd‑inhibit command construction.
- Bug Fixes: Resolved syntax issue that could cause command generation failure.
2026-03-12 00:27:46 +05:45
sankalp 8bd5b52b05 refactor(src/commands): enhance battery command error handling and readability
Restructure loops, add explicit error handling, improve multi‑line messages, and fix formatting issues.

- Enhancements
  - Use explicit braces for error branches to prevent silent failures
  - Wrap warning and informational messages in multi‑line `println!` with consistent spacing
  - Refactor directory reads for Ideapad fallback to avoid nested `let` bindings
  - Improve parsing and formatting of AMD TDP limit output with clear parentheses
  - Provide clearer debug logging when writing to threshold files
- Bug Fixes
  - Added missing braces around error handling to ensure proper execution flow
  - Fixed variable binding scope for `ideapad_entries` to prevent shadowing
  - Ensured consistent handling of missing `charge_control_end_threshold` across all entries

no changes.
2026-03-12 00:27:37 +05:45
sankalp 387047748a feat(src): update 2026-03-12 00:14:54 +05:45
sankalp 569775f549 feat(src/commands): implement dynamic CPU TDP limit control and status reporting
New Features
- Add per‑CPU power limit commands using Intel RAPL (PL1/PL2) and AMD hwmon constraints
- Expose current TDP limits in status output, distinguishing RAPL, AMD hwmon, or hardware‑managed
- Gracefully handle absence of required sysfs entries

Enhancements
- Extend the power command set with a `LimitTdp` sub‑command
- Add debug logging for limit application attempts

Bug Fixes
- Ensure the command degrades gracefully when hardware does not support dynamic power caps
2026-03-12 00:11:29 +05:45
sankalp 0327885bef feat(commands): add cooling command implementation and status integration
- New Features
  - Implement fan_mode control for Ideapad laptops
  - Implement thermal policy control for ASUS laptops via WMI
  - Provide cooling command supporting performance, balanced, and quiet profiles

- Enhancements
  - Display current cooling profile in `lapctl status` output

- Bug Fixes
  - None
2026-03-12 00:01:48 +05:45
sankalp bc31ce6506 feat(src): add cooling and thermal management commands
Adds a new Cooling command group with selectable fan profiles (Performance, Balanced, Quiet) and updates the CLI and logging accordingly.

- New Features
  - Introduce Cooling subcommands for setting thermal management modes
  - Implement runtime logic to apply selected fan profiles
- Enhancements
  - Extend CLI enum `Commands` to include `Cooling` and dispatch handling
  - Refine env_logger formatting to output only `[LEVEL] message`
  - Integrate cooling execution into the main command dispatch flow
- Bug Fixes
  - No bug fixes introduced in this change
2026-03-12 00:01:36 +05:45
sankalp b5ba6efd41 feat(src/commands): implement battery limit command with validation and enhance status output
The changes introduce a robust `BatteryCommands::Limit` implementation that validates user‑provided percentages, writes charge‑control thresholds, and gracefully handles Lenovo Ideapad firmware via the `conservation_mode` fallback. The `lapctl status` command is also updated to display battery‑specific details such as capacity, status, and charge limits, replacing the previous generic placeholder.

New Features
- Added `BatteryCommands::Limit` handling with range validation (1‑100) and support for multiple `/sys/class/power_supply` entries.
- Implemented Ideapad fallback using `conservation_mode` to provide custom charge limits or warnings when unsupported.
- Extended `lapctl status` to show charge limit and Conservation Mode for each battery.

Enhancements
- Added root‑privilege check (`assert_root`) and improved error/debug logging throughout the command.
- Restructured directory traversal logic for readability and added `debug!` traces on write failures.
- Re‑used status logic to present battery‑specific information instead of a generic placeholder.

Bug Fixes
- Resolved placeholder status output and proper handling of missing `charge_control_end_threshold` files.
- Ensured correct exit codes and clear error messages for invalid percentage inputs.
2026-03-11 23:47:50 +05:45
sankalp 2d03067f0e feat(src/commands): add power profile status output
The `status` command now displays the current power profile by reading `/sys/firmware/acpi/platform_profile`, giving users insight into power usage.

New Features
- Output power profile status to the console.

Enhancements
- Enriches status command with additional hardware information.
2026-03-11 23:37:03 +05:45
sankalp fb69cdc63c feat(src/commands): implement power profile switching via sysfs
Set CPU scaling governor, energy performance preference, and ACPI platform profile for performance, balanced, and battery‑save modes. Added root assertion and detailed logging.

- New Features: Added set_cpu_governor, set_energy_performance_preference, set_platform_profile; integrated into execute for each PowerCommands variant.
- Enhancements: Use of logging to report successes/failures; fallback to modern scheduler governor (schedutil); validation of CPU sysfs paths.
- Bug Fixes: Guard against missing sysfs entries; improved debugging messages.
2026-03-11 23:33:47 +05:45