Skip to content

Commit

Permalink
chore: change default settings on mac, improve clarity of logs on cli…
Browse files Browse the repository at this point in the history
… boot
  • Loading branch information
louis030195 committed Aug 16, 2024
1 parent a79b32e commit 0a73c48
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
2 changes: 0 additions & 2 deletions screenpipe-audio/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ pub fn list_audio_devices() -> Result<Vec<AudioDevice>> {
pub fn default_input_device() -> Result<AudioDevice> {
let host = cpal::default_host();
let device = host.default_input_device().unwrap();
info!("Using default input device: {}", device.name()?);
Ok(AudioDevice::new(device.name()?, DeviceType::Input))
}

Expand All @@ -364,7 +363,6 @@ pub fn default_output_device() -> Result<AudioDevice> {
let device = host
.default_output_device()
.ok_or_else(|| anyhow!("No default output device found"))?;
info!("Using default output device: {}", device.name()?);
return Ok(AudioDevice::new(device.name()?, DeviceType::Output));
}
}
61 changes: 54 additions & 7 deletions screenpipe-server/src/bin/screenpipe-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ struct Cli {
/// 5 FPS = 150 GB / month
/// Optimise based on your needs.
/// Your screen rarely change more than 1 times within a second, right?
#[arg(short, long, default_value_t = 1.0)]
fps: f64,

#[cfg_attr(not(target_os = "macos"), arg(short, long, default_value_t = 1.0))]
#[cfg_attr(target_os = "macos", arg(short, long, default_value_t = 0.2))]
fps: f64, // ! not crazy about this (unconsistent behaviour across platforms) see https://github.com/louis030195/screen-pipe/issues/173

/// Audio chunk duration in seconds
#[arg(short, long, default_value_t = 30)]
audio_chunk_duration: u64,
Expand Down Expand Up @@ -194,6 +195,7 @@ async fn main() -> anyhow::Result<()> {
// tokio-console
// console_subscriber::init();
let local_data_dir = get_base_dir(cli.data_dir)?;
let local_data_dir_clone = local_data_dir.clone();

let log_file = File::create(format!(
"{}/screenpipe.log",
Expand Down Expand Up @@ -248,20 +250,17 @@ async fn main() -> anyhow::Result<()> {

let audio_devices_control_server = audio_devices_control.clone();

info!("Available audio devices:");
// Add all available audio devices to the controls
for device in &all_audio_devices {
let device_control = DeviceControl {
is_running: false,
is_paused: false,
};
devices_status.insert(device.clone(), device_control);
info!(" {}", device);
}

if !cli.disable_audio {
if cli.audio_device.is_empty() {
debug!("Using default devices");
// Use default devices
if let Ok(input_device) = default_input_device() {
audio_devices.push(Arc::new(input_device.clone()));
Expand Down Expand Up @@ -300,7 +299,6 @@ async fn main() -> anyhow::Result<()> {
if audio_devices.is_empty() {
eprintln!("No audio devices available. Audio recording will be disabled.");
} else {
info!("Using audio devices:");
for device in &audio_devices {
info!(" {}", device);

Expand Down Expand Up @@ -354,6 +352,7 @@ async fn main() -> anyhow::Result<()> {
eprintln!("{}", format!("Monitor with id {} not found. Try 'screenpipe --list-monitors'", monitor_id).red());
std::process::exit(1);
});
let ocr_engine_clone = cli.ocr_engine.clone();

// Function to start or restart the recording task
let _start_recording = tokio::spawn(async move {
Expand Down Expand Up @@ -441,6 +440,54 @@ async fn main() -> anyhow::Result<()> {
"Open source | Runs locally | Developer friendly".bright_green()
);

println!("┌─────────────────────┬────────────────────────────────────┐");
println!("│ Setting │ Value │");
println!("├─────────────────────┼────────────────────────────────────┤");
println!("│ FPS │ {:<34} │", cli.fps);
println!("│ Audio Chunk Duration│ {:<34} │", format!("{} seconds", cli.audio_chunk_duration));
println!("│ Port │ {:<34} │", cli.port);
println!("│ Audio Disabled │ {:<34} │", cli.disable_audio);
println!("│ Self Healing │ {:<34} │", cli.self_healing);
println!("│ Save Text Files │ {:<34} │", cli.save_text_files);
println!("│ Cloud Audio │ {:<34} │", cli.cloud_audio_on);
println!("│ OCR Engine │ {:<34} │", format!("{:?}", ocr_engine_clone));
println!("│ Monitor ID │ {:<34} │", monitor_id);
println!("│ Data Directory │ {:<34} │", local_data_dir_clone.display());
println!("│ Debug Mode │ {:<34} │", cli.debug);
const VALUE_WIDTH: usize = 34;

// Function to truncate and pad strings
fn format_cell(s: &str, width: usize) -> String {
if s.len() > width {
format!("{}...", &s[..width - 3])
} else {
format!("{:<width$}", s, width = width)
}
}

// In the main function, replace the audio devices section with:
println!("├─────────────────────┼────────────────────────────────────┤");
println!("│ Audio Devices │ │");

if cli.disable_audio {
println!("│ {:<19} │ {:<34} │", "", "Disabled");
} else if audio_devices.is_empty() {
println!("│ {:<19} │ {:<34} │", "", "No devices available");
} else {
for (i, device) in audio_devices.iter().enumerate() {
let device_str = device.deref().to_string();
let formatted_device = format_cell(&device_str, VALUE_WIDTH);
if i == 0 {
println!("│ {:<19} │ {:<34} │", "", formatted_device);
} else {
println!("│ {:<19} │ {:<34} │", "", formatted_device);
}
}
}

println!("└─────────────────────┴────────────────────────────────────┘");


// Add warning for cloud arguments
if cli.cloud_audio_on || warning_ocr_engine_clone == CliOcrEngine::Unstructured {
println!(
Expand Down
1 change: 0 additions & 1 deletion screenpipe-server/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub async fn start_continuous_recording(
friend_wearable_uid: Option<String>,
monitor_id: u32,
) -> Result<()> {
info!("Recording now");

let (whisper_sender, whisper_receiver) = create_whisper_channel(cloud_audio).await?;

Expand Down

0 comments on commit 0a73c48

Please sign in to comment.