Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
neo773 committed Jan 13, 2025
1 parent 6d305b2 commit 7387b33
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions screenpipe-app-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,19 @@ async fn get_pipe_port(pipe_id: &str) -> anyhow::Result<u16> {
.ok_or_else(|| anyhow::anyhow!("no port found for pipe {}", pipe_id))
}

async fn list_pipes() -> anyhow::Result<Value> {
let client = reqwest::Client::new();
let response = client
.get("http://localhost:3030/pipes/list")
.send()
.await?
.json::<Value>()
.await?;

Ok(response)
}


fn get_base_dir(app: &tauri::AppHandle, custom_path: Option<String>) -> anyhow::Result<PathBuf> {
let default_path = app.path().local_data_dir().unwrap().join("screenpipe");

Expand Down Expand Up @@ -648,10 +661,27 @@ async fn main() {
}
"quit" => {
debug!("Quit requested");
// First try to stop any running recordings
let state = app_handle.state::<SidecarState>();
tauri::async_runtime::block_on(async {
if let Err(e) = kill_all_sreenpipes(state, app_handle.clone()).await {
// Kill all pipes before quitting
let app_handle_clone = app_handle.clone();
tauri::async_runtime::spawn(async move {
if let Ok(response) = list_pipes().await {
if let Some(pipes) = response["data"].as_array() {
for pipe in pipes {
if pipe["enabled"].as_bool().unwrap_or(false) {
if let Some(id) = pipe["id"].as_str() {
let _ = reqwest::Client::new()
.post(format!("http://localhost:3030/pipes/stop/{}", id))
.send()
.await;
}
}
}
}
}

// Stop any running recordings
let state = app_handle_clone.state::<SidecarState>();
if let Err(e) = kill_all_sreenpipes(state, app_handle_clone.clone()).await {
error!("Error stopping recordings during quit: {}", e);
}
});
Expand Down

0 comments on commit 7387b33

Please sign in to comment.