### Install keepawake CLI Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Install the keepawake binary using Cargo or download prebuilt binaries. ```bash # Install from crates.io cargo install keepawake -F bin # Or download prebuilt binaries from GitHub releases # https://github.com/segevfiner/keepawake-rs/releases/latest ``` -------------------------------- ### Build C Library with cargo-c Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Instructions for building and installing the C library using `cargo-c`. Ensure `cargo-c` is installed and the `capi` feature is enabled. ```bash # Install cargo-c if not already installed carp install cargo-c # Build the library with the capi feature carp cbuild --features capi # Build and install to a specific prefix carp cinstall --destdir=/tmp/install --prefix=/usr --libdir=/usr/lib64 --features capi # The following files are generated: # - libkeepawake.so (or .dylib/.dll) # - keepawake.h (header file) # - keepawake.pc (pkg-config file) ``` -------------------------------- ### Install keepawake-rs via Cargo Source: https://github.com/segevfiner/keepawake-rs/blob/main/README.md Install the keepawake binary using Cargo. The `-F bin` flag ensures the binary is included. ```sh cargo install keepawake -F bin ``` -------------------------------- ### Build and Install C Library Source: https://github.com/segevfiner/keepawake-rs/blob/main/README.md Build the C library, generate header and .pc files, and install them to the specified system paths. Requires cargo-c. ```sh # build the library, create the .h header, create the .pc file $ cargo cbuild --destdir=${D} --prefix=/usr --libdir=/usr/lib64 ``` ```sh # build the library, create the .h header, create the .pc file and install all of it $ cargo cinstall --destdir=${D} --prefix=/usr --libdir=/usr/lib64 ``` -------------------------------- ### Error Handling for KeepAwake in Rust Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Handles potential errors when creating a KeepAwake instance using a match statement. This example requires the `keepawake` crate. ```rust use keepawake::{Builder, Error, Result}; fn main() { match create_awake_session() { Ok(_awake) => { println!("Successfully inhibited sleep"); // Do work while _awake is in scope std::thread::sleep(std::time::Duration::from_secs(300)); } Err(Error::System(e)) => { eprintln!("System error (D-Bus/IOKit/Win32): {}", e); } Err(Error::Builder(e)) => { eprintln!("Builder configuration error: {}", e); } } } fn create_awake_session() -> Result { Builder::default() .display(true) .idle(true) .create() } ``` -------------------------------- ### Custom Application Metadata Usage Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Provide custom application name and reason for the awake state for display in system power management tools. ```rust use keepawake::{Builder, Result}; fn main() -> Result<()> { let _awake = Builder::default() .display(true) .idle(true) .sleep(true) .reason("Video playback in progress") // Shown in pmset/systemd-inhibit .app_name("MyVideoPlayer") // Used on Linux .app_reverse_domain("com.example.myvideoplayer") // Used on Linux .create()?; // Video playback code here... play_video("movie.mp4"); Ok(()) } fn play_video(_path: &str) { // Placeholder for actual video playback std::thread::sleep(std::time::Duration::from_secs(7200)); } ``` -------------------------------- ### C API Usage for KeepAwake Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Demonstrates using the experimental C API to create and manage an awake state. This requires building the C library with the `capi` feature. ```c #include #include #include int main() { // Create a new builder KeepAwakeBuilder* builder = keepawake_new(); // Configure the awake options keepawake_display(builder, true); keepawake_idle(builder, true); keepawake_reason(builder, "C application processing"); keepawake_app_name(builder, "my_c_app"); keepawake_app_reverse_domain(builder, "com.example.mycapp"); // Create the KeepAwake instance (frees builder if true) KeepAwake* awake = keepawake_create(builder, true); if (awake == NULL) { fprintf(stderr, "Failed to create KeepAwake\n"); return 1; } printf("System will stay awake for 1 hour...\n"); sleep(3600); // Clean up - releases the awake state keepawake_destroy(awake); return 0; } ``` -------------------------------- ### Debug Power Management Commands Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Provides OS-specific commands to verify power management settings and active power assertions. Useful for debugging `keepawake` functionality. ```bash # macOS - List active power assertions pmset -g assertions # Linux - List systemd inhibitor locks systemd-inhibit --list # Linux - List GNOME session inhibitors gnome-session-inhibit --list # Windows - List power requests powercfg /requests ``` -------------------------------- ### Keep Display On with CLI Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Prevent the display from turning off using the display flag. ```bash # Keep display on until Ctrl+C is pressed keepawake --display # Keep display on while running a command keepawake --display -- ffmpeg -i input.mp4 output.avi # Short form keepawake -d ``` -------------------------------- ### Generate Shell Completions Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Generate shell completion scripts for various shells. ```bash # Generate bash completions keepawake --completions bash > ~/.local/share/bash-completion/completions/keepawake # Generate zsh completions keepawake --completions zsh > ~/.zfunc/_keepawake # Generate fish completions keepawake --completions fish > ~/.config/fish/completions/keepawake.fish # Generate PowerShell completions keepawake --completions powershell > keepawake.ps1 ``` -------------------------------- ### Wait for Process with CLI Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Keep the system awake while waiting for a specific process to exit. ```bash # Keep system awake while waiting for a specific PID keepawake --idle -w 12345 # Note: The -w flag is ignored when a COMMAND is provided ``` -------------------------------- ### Add keepawake as Cargo Dependency Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Specifies how to add the `keepawake` library to a Rust project's `Cargo.toml` file. Version and feature flags can be adjusted as needed. ```toml [dependencies] keepawake = "0.6" # Or with specific features # keepawake = { version = "0.6", features = ["capi"] } ``` -------------------------------- ### Basic Builder Pattern Usage Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Create a KeepAwake instance using the Builder pattern to prevent sleep while the object exists. ```rust use keepawake::{Builder, Result}; fn main() -> Result<()> { // Create a KeepAwake instance - system stays awake while _awake exists let _awake = Builder::default() .display(true) // Prevent display from turning off .idle(true) // Prevent idle sleep .create()?; // Do some long-running work here... std::thread::sleep(std::time::Duration::from_secs(3600)); // _awake is dropped here, system can sleep again Ok(()) } ``` -------------------------------- ### Scoped Awake State in Rust Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Demonstrates using Rust's scoping to automatically release the awake state when a block completes. Ensure the `keepawake` crate is added as a dependency. ```rust use keepawake::{Builder, Result}; fn perform_backup() -> Result<()> { // KeepAwake only active within this scope let _awake = Builder::default() .idle(true) .reason("System backup in progress") .create()?; println!("Starting backup - system will not sleep"); // Backup operations... for i in 1..=10 { println!("Backing up part {}/10...", i); std::thread::sleep(std::time::Duration::from_secs(60)); } Ok(()) // _awake dropped here - system can sleep again } fn main() -> Result<()> { perform_backup()?; println!("Backup complete - system can now sleep"); Ok(()) } ``` -------------------------------- ### Prevent Idle Sleep with CLI Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Prevent the system from sleeping due to inactivity using the idle flag. ```bash # Prevent idle sleep until Ctrl+C keepawake --idle # Prevent idle sleep while a long-running process executes keepawake --idle -- cargo build --release # Combine with display flag keepawake -d -i ``` -------------------------------- ### Prevent System Sleep with CLI Source: https://context7.com/segevfiner/keepawake-rs/llms.txt Prevent the system from explicitly sleeping using the sleep flag. ```bash # Prevent system sleep (requires AC power on most systems) keepawake --sleep # Combine all options for maximum "awake" state keepawake -d -i -s -- ./long-running-backup.sh ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.