feat(commands): add battery, gpu, power, and status command implementations
Added full command implementations for battery limit/status, GPU management (cache operations, mode switching, NVIDIA handling), and a status reporter that prints GPU mode and battery details. Introduced module registration and placeholder power command. New Features - Battery command support (`limit`, `status`) - GPU command suite (`cache-delete`, `cache-query`, `reset`, `reset-sddm`, `integrated`, `hybrid`, `nvidia`) - Status command output showing GPU mode and battery information - Power command placeholder scaffold Enhancements - Unified command registration via `mod.rs` - Added root checks and file utilities for cache and config operations - Integrated logging infrastructure Bug Fixes: none
This commit is contained in:
5 files changed
+555
No files matched your search
@@ -0,0 +1,36 @@
|
||||
use crate::hardware::gpu;
|
||||
use std::fs;
|
||||
|
||||
pub fn execute() {
|
||||
println!("--- lapctl status ---");
|
||||
|
||||
// GPU Mode
|
||||
let current_mode = gpu::get_current_mode();
|
||||
println!("GPU Mode: {}", current_mode);
|
||||
|
||||
// Battery Limit / Status checks (we can peek into typical battery paths)
|
||||
// Note: this assumes a typical sysfs structure. A complete implementation
|
||||
// would parse /sys/class/power_supply/BAT0 or similar.
|
||||
let sys_class_power = "/sys/class/power_supply";
|
||||
if let Ok(entries) = fs::read_dir(sys_class_power) {
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name();
|
||||
let name_str = name.to_string_lossy();
|
||||
if name_str.starts_with("BAT") {
|
||||
let bat_path = entry.path();
|
||||
|
||||
let capacity = fs::read_to_string(bat_path.join("capacity")).unwrap_or_else(|_| "Unknown".into());
|
||||
let status = fs::read_to_string(bat_path.join("status")).unwrap_or_else(|_| "Unknown".into());
|
||||
|
||||
println!("{}:", name_str);
|
||||
println!(" Capacity: {}%", capacity.trim());
|
||||
println!(" Status: {}", status.trim());
|
||||
|
||||
// Print charing limit if exists (e.g., charge_control_end_threshold)
|
||||
if let Ok(limit) = fs::read_to_string(bat_path.join("charge_control_end_threshold")) {
|
||||
println!(" Charge Limit: {}%", limit.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user