Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

chore: implement cleaner permission UX

Louis Beaumont8361950765e0
diff --git a/screenpipe-actions/src/lib.rs b/screenpipe-actions/src/lib.rs
index c2cec5ccf..13c6a6dfc 100644
--- a/screenpipe-actions/src/lib.rs
+++ b/screenpipe-actions/src/lib.rs
@@ -1,16 +1,10 @@
-mod monitor_keystroke_commands;
mod call_ai;
-mod type_and_animate;
+mod monitor_keystroke_commands;
+mod run;
mod screenshot;
-mod run; // This now refers to the renamed run.rs file
+pub mod type_and_animate;
-pub use monitor_keystroke_commands::{run_keystroke_monitor, KeystrokeCommand};
pub use call_ai::call_ai;
-pub use type_and_animate::{type_slowly, delete_characters};
-pub use run::run; // Export the run function from the run module
-
-// Remove this line
-// mod main;
-
-// Remove this line if the function doesn't exist
-// pub use screenshot::capture_main_window_screenshot;
+pub use monitor_keystroke_commands::{run_keystroke_monitor, KeystrokeCommand};
+pub use run::run;
+pub use type_and_animate::{delete_characters, trigger_keyboard_permission, type_slowly}; // Export the run function from the run module
diff --git a/screenpipe-actions/src/type_and_animate.rs b/screenpipe-actions/src/type_and_animate.rs
index 5fd7a4d39..3f8c918dd 100644
--- a/screenpipe-actions/src/type_and_animate.rs
+++ b/screenpipe-actions/src/type_and_animate.rs
@@ -60,7 +60,8 @@ pub async fn type_slowly(text: String, stop_signal: Arc<AtomicBool>) -> Result<(
with_enigo(|enigo| {
enigo.key_sequence(&char.to_string());
});
- }).await?;
+ })
+ .await?;
sleep(Duration::from_millis(50)).await;
}
}
@@ -74,9 +75,19 @@ pub async fn type_slowly(text: String, stop_signal: Arc<AtomicBool>) -> Result<(
enigo.key_click(Key::Return);
enigo.key_up(Key::Shift);
});
- }).await?;
+ })
+ .await?;
}
}
sleep(Duration::from_millis(text_len as u64)).await;
Ok(())
}
+
+pub fn trigger_keyboard_permission() -> anyhow::Result<()> {
+ with_enigo(|enigo| {
+ // Perform a no-op key press to trigger the permission request
+ enigo.key_down(enigo::Key::Shift);
+ enigo.key_up(enigo::Key::Shift);
+ });
+ Ok(())
+}
diff --git a/screenpipe-audio/src/core.rs b/screenpipe-audio/src/core.rs
index 6705d5810..f7e8bcd8d 100644
--- a/screenpipe-audio/src/core.rs
+++ b/screenpipe-audio/src/core.rs
@@ -418,3 +418,27 @@ pub fn default_output_device() -> Result<AudioDevice> {
return Ok(AudioDevice::new(device.name()?, DeviceType::Output));
}
}
+
+pub fn trigger_audio_permission() -> Result<()> {
+ let host = cpal::default_host();
+ let device = host
+ .default_input_device()
+ .ok_or_else(|| anyhow!("No default input device found"))?;
+
+ let config = device.default_input_config()?;
+
+ // Attempt to build an input stream, which should trigger the permission request
+ let _stream = device.build_input_stream(
+ &config.into(),
+ |_data: &[f32], _: &cpal::InputCallbackInfo| {
+ // Do nothing, we just want to trigger the permission request
+ },
+ |err| eprintln!("Error in audio stream: {}", err),
+ None,
+ )?;
+
+ // We don't actually need to start the stream
+ // The mere attempt to build it should trigger the permission request
+
+ Ok(())
+}
diff --git a/screenpipe-audio/src/lib.rs b/screenpipe-audio/src/lib.rs
index 4660042a8..25d93b8ff 100644
--- a/screenpipe-audio/src/lib.rs
+++ b/screenpipe-audio/src/lib.rs
@@ -4,13 +4,14 @@ pub mod encode;
mod multilingual;
pub mod pcm_decode;
pub mod stt;
+mod tokenizer;
pub mod vad_engine;
pub mod whisper;
-mod tokenizer;
pub use core::{
default_input_device, default_output_device, list_audio_devices, parse_audio_device,
- record_and_transcribe, AudioDevice, AudioTranscriptionEngine, DeviceControl, DeviceType,
+ record_and_transcribe, trigger_audio_permission, AudioDevice, AudioTranscriptionEngine,
+ DeviceControl, DeviceType,
};
pub use encode::encode_single_audio;
pub use pcm_decode::pcm_decode;
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index f16636d0f..6a542ee0c 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -9,13 +9,14 @@ use crossbeam::queue::SegQueue;
use dirs::home_dir;
use futures::{pin_mut, stream::FuturesUnordered, StreamExt};
use screenpipe_audio::{
- default_input_device, default_output_device, list_audio_devices, parse_audio_device, vad_engine::SileroVad, whisper::WhisperModel, AudioDevice, DeviceControl
+ default_input_device, default_output_device, list_audio_devices, parse_audio_device, trigger_audio_permission, vad_engine::SileroVad, whisper::WhisperModel, AudioDevice, DeviceControl
};
use screenpipe_core::find_ffmpeg_path;
use screenpipe_server::{
cli::{Cli, CliAudioTranscriptionEngine, CliOcrEngine, Command, PipeCommand}, start_continuous_recording, watch_pid, DatabaseManager, PipeManager, ResourceMonitor, Server
};
use screenpipe_vision::monitor::list_monitors;
+use screenpipe_vision::core::trigger_screen_capture_permission;
use serde_json::{json, Value};
use tokio::{runtime::Runtime, signal, sync::broadcast};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
@@ -122,7 +123,36 @@ async fn main() -> anyhow::Result<()> {
handle_pipe_command(subcommand, &pipe_manager).await?;
return Ok(());
}
- Command::Setup => {
+ #[allow(unused_variables)]
+ Command::Setup { enable_beta } => {
+ #[cfg(feature = "beta")]
+ if enable_beta {
+ use screenpipe_actions::type_and_animate::trigger_keyboard_permission;
+
+ // Trigger keyboard permission request
+ if let Err(e) = trigger_keyboard_permission() {
+ error!("Failed to trigger keyboard permission: {:?}", e);
+ error!("Please grant keyboard permission manually in System Preferences.");
+ } else {
+ info!("Keyboard permission requested. Please grant permission if prompted.");
+ }
+ }
+ // Trigger audio permission request
+ if let Err(e) = trigger_audio_permission() {
+ error!("Failed to trigger audio permission: {:?}", e);
+ error!("Please grant microphone permission manually in System Preferences.");
+ } else {
+ info!("Audio permission requested. Please grant permission if prompted.");
+ }
+
+ // Trigger screen capture permission request
+ if let Err(e) = trigger_screen_capture_permission() {
+ error!("Failed to trigger screen capture permission: {:?}", e);
+ error!("Please grant screen recording permission manually in System Preferences.");
+ } else {
+ info!("Screen capture permission requested. Please grant permission if prompted.");
+ }
+
// this command just download models and stuff (useful to have specific step to display in UI)
// ! should prob skip if deepgram?
@@ -130,7 +160,7 @@ async fn main() -> anyhow::Result<()> {
// ! assuming silero is used
SileroVad::new().await.unwrap();
- println!("screenpipe setup complete");
+ info!("screenpipe setup complete");
// TODO: ffmpeg sidecar thing here
return Ok(());
}
diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rs
index 2e85308a3..7b6d5b756 100644
--- a/screenpipe-server/src/cli.rs
+++ b/screenpipe-server/src/cli.rs
@@ -231,6 +231,7 @@ pub struct Cli {
pub enable_llm: bool,
/// Enable beta features
+ #[cfg(feature = "beta")]
#[arg(long, default_value_t = false)]
pub enable_beta: bool,
@@ -247,7 +248,12 @@ pub enum Command {
subcommand: PipeCommand,
},
/// Setup screenpipe environment
- Setup,
+ Setup {
+ /// Enable beta features
+ // #[cfg(feature = "beta")] // ! TODO
+ #[arg(long, default_value_t = false)]
+ enable_beta: bool,
+ },
}
diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rs
index 59fcb5806..77be55d5d 100644
--- a/screenpipe-vision/src/core.rs
+++ b/screenpipe-vision/src/core.rs
@@ -8,6 +8,7 @@ use crate::monitor::get_monitor_by_id;
use crate::tesseract::perform_ocr_tesseract;
use crate::utils::OcrEngine;
use crate::utils::{capture_screenshot, compare_with_previous_image, save_text_files};
+use anyhow::{anyhow, Result};
use image::DynamicImage;
use log::{debug, error};
use screenpipe_core::Language;
@@ -18,6 +19,7 @@ use std::{
time::{Duration, Instant},
};
use tokio::sync::mpsc::Sender;
+use xcap::Monitor;
pub struct CaptureResult {
pub image: DynamicImage,
@@ -290,3 +292,16 @@ fn parse_json_output(json_output: &str) -> Vec<HashMap<String, String>> {
parsed_output
}
+
+pub fn trigger_screen_capture_permission() -> Result<()> {
+ // Get the primary monitor
+ let monitor = Monitor::all().map_err(|e| anyhow!("Failed to get monitor: {}", e))?;
+
+ // Attempt to capture a screenshot, which should trigger the permission request
+ let _screenshot = monitor.first().unwrap().capture_image()?;
+
+ // We don't need to do anything with the screenshot
+ // The mere attempt to capture it should trigger the permission request
+
+ Ok(())
+}