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

feat: add close window endpoint

Louis Beaumontff5764b5e133
diff --git a/screenpipe-app-tauri/src-tauri/src/server.rs b/screenpipe-app-tauri/src-tauri/src/server.rs
index a55c9ccc0..fe6449ada 100644
--- a/screenpipe-app-tauri/src-tauri/src/server.rs
+++ b/screenpipe-app-tauri/src-tauri/src/server.rs
@@ -1,4 +1,4 @@
-use crate::window_api::show_specific_window;
+use crate::window_api::{close_window, show_specific_window};
use crate::{get_base_dir, get_store};
use axum::body::Bytes;
use axum::response::sse::{Event, Sse};
@@ -165,6 +165,7 @@ pub async fn run_server(app_handle: tauri::AppHandle, port: u16) {
.route("/sidecar/start", axum::routing::post(start_sidecar))
.route("/sidecar/stop", axum::routing::post(stop_sidecar))
.route("/window", axum::routing::post(show_specific_window))
+ .route("/window/close", axum::routing::post(close_window))
.layer(cors)
.layer(
TraceLayer::new_for_http()
diff --git a/screenpipe-app-tauri/src-tauri/src/window_api.rs b/screenpipe-app-tauri/src-tauri/src/window_api.rs
index 9ec975b3a..55a6653a3 100644
--- a/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -96,3 +96,36 @@ pub async fn show_specific_window(
}
}
}
+
+#[derive(Deserialize, Debug)]
+pub struct CloseWindowPayload {
+ title: String,
+}
+
+pub async fn close_window(
+ State(state): State<ServerState>,
+ Json(payload): Json<CloseWindowPayload>,
+) -> Result<Json<ApiResponse>, (StatusCode, String)> {
+ info!("received window close request: {:?}", payload);
+
+ if let Some(window) = state.app_handle.get_webview_window(&payload.title) {
+ match window.destroy() {
+ Ok(_) => Ok(Json(ApiResponse {
+ success: true,
+ message: "window closed successfully".to_string(),
+ })),
+ Err(e) => {
+ error!("failed to close window: {}", e);
+ Err((
+ StatusCode::INTERNAL_SERVER_ERROR,
+ format!("failed to close window: {}", e),
+ ))
+ }
+ }
+ } else {
+ Err((
+ StatusCode::NOT_FOUND,
+ format!("window with title '{}' not found", payload.title),
+ ))
+ }
+}