Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mv get icon to cli #1593

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pipes/rewind/src/components/search-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function AppSelect({ apps, setApps }: AppSelectProps) {
<div className="flex items-center gap-2">
<span className="text-xl">
<img
src={`http://localhost:11435/app-icon?name=${option.value}`}
src={`http://localhost:3030/app/icon?name=${option.value}`}
className="w-6 h-6"
alt={option.value}
loading="lazy"
Expand All @@ -151,7 +151,7 @@ export function AppSelect({ apps, setApps }: AppSelectProps) {
<span key={id}>
{
<img
src={`http://localhost:11435/app-icon?name=${tech.label}`}
src={`http://localhost:3030/app/icon?name=${tech.label}`}
className="w-6 h-6"
alt={tech.label}
loading="lazy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function getAppIcon(
});

try {
const response = await fetch(`http://localhost:11435/app-icon?${params}`, {
const response = await fetch(`http://localhost:3030/app/icon?${params}`, {
method: "GET",
headers: {
Accept: "application/json",
Expand Down
2 changes: 1 addition & 1 deletion pipes/rewind/src/components/timeline/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const TimelineSlider = ({
>
<div className="absolute top-0 left-1/2 w-5 h-5 rounded-full -translate-x-1/2 bg-background/50 backdrop-blur p-0.5">
<img
src={`http://localhost:11435/app-icon?name=${group.appName}`}
src={`http://localhost:3030/app/icon?name=${group.appName}`}
className="w-full h-full opacity-70"
alt={group.appName}
loading="lazy"
Expand Down
2 changes: 0 additions & 2 deletions screenpipe-app-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
use updates::start_update_check;
mod analytics;
mod icons;
use crate::analytics::start_analytics;

mod commands;
Expand All @@ -46,7 +45,6 @@ pub use server::*;

pub use sidecar::*;

pub use icons::*;
pub use store::*;

mod config;
Expand Down
52 changes: 2 additions & 50 deletions screenpipe-app-tauri/src-tauri/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use crate::window_api::{close_window, show_specific_window};
use crate::{get_base_dir, get_store, register_shortcut};
use axum::body::Bytes;
use axum::response::sse::{Event, Sse};
use axum::response::IntoResponse;
use axum::{
extract::{Query, State},
extract::State,
http::{Method, StatusCode},
Json, Router,
};
use futures::stream::Stream;
use http::header::{HeaderValue, CONTENT_TYPE};
use http::header::HeaderValue;
use notify::RecursiveMode;
use notify::Watcher;
use reqwest::Client;
Expand Down Expand Up @@ -83,12 +81,6 @@ struct AuthData {
user_id: String,
}

#[derive(Debug, Deserialize)]
struct AppIconQuery {
name: String,
path: Option<String>,
}

#[derive(Deserialize, Debug)]
struct WindowSizePayload {
title: String,
Expand Down Expand Up @@ -169,7 +161,6 @@ pub async fn run_server(app_handle: tauri::AppHandle, port: u16) {
.route("/inbox", axum::routing::post(send_inbox_message))
.route("/log", axum::routing::post(log_message))
.route("/auth", axum::routing::post(handle_auth))
.route("/app-icon", axum::routing::get(get_app_icon_handler))
.route("/window-size", axum::routing::post(set_window_size))
.route("/sse/settings", axum::routing::get(settings_stream))
.route("/sidecar/start", axum::routing::post(start_sidecar))
Expand Down Expand Up @@ -307,45 +298,6 @@ async fn handle_auth(
}))
}

async fn get_app_icon_handler(
State(_): State<ServerState>,
Query(app_name): Query<AppIconQuery>,
) -> Result<impl IntoResponse, (StatusCode, String)> {
info!("received app icon request: {:?}", app_name);

#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
{
match crate::icons::get_app_icon(&app_name.name, app_name.path).await {
Ok(Some(icon)) => {
let headers = [
(CONTENT_TYPE, HeaderValue::from_static("image/jpeg")),
(
http::header::CACHE_CONTROL,
HeaderValue::from_static("public, max-age=604800"),
),
];
Ok((headers, Bytes::from(icon.data)))
}
Ok(None) => Err((StatusCode::NOT_FOUND, "Icon not found".to_string())),
Err(e) => {
error!("failed to get app icon: {}", e);
Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("failed to get app icon: {}", e),
))
}
}
}

#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
{
Err((
StatusCode::NOT_IMPLEMENTED,
"app icon retrieval not supported on this platform".to_string(),
))
}
}

async fn set_window_size(
State(state): State<ServerState>,
Json(payload): Json<WindowSizePayload>,
Expand Down
12 changes: 12 additions & 0 deletions screenpipe-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,20 @@ ignored = ["url", "console-subscriber"]
[target.'cfg(unix)'.dependencies]
nix = { version = "0.29", features = ["signal"] }

[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.26.0"
objc = "0.2.7"

[target.'cfg(windows)'.dependencies]
image = "0.25.5"
winreg = "0.52.0"
lazy_static = "1.5.0"
windows-icons = { git = "https://github.com/tribhuwan-kumar/windows-icons.git" }
windows = { version = "0.58", features = [
"Win32_System_Threading",
"Win32_Foundation",
] }

[target.'cfg(target_os = "linux")'.dependencies]
gtk = "0.18.1"
base64 = "0.22.1"
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub async fn get_app_icon(

#[cfg(target_os = "windows")]
fn get_exe_by_reg_key(app_name: &str) -> Option<String> {
use winreg::enums::*;
use winreg::RegKey;
use winreg::enums::*;

let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
Expand Down Expand Up @@ -198,14 +198,14 @@ async fn get_exe_from_potential_path(app_name: &str) -> Option<String> {
format!(
r#"
Get-ChildItem -Path "{}" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}
"#,
"#,
path, app_name
)
} else {
format!(
r#"
Get-ChildItem -Path "{}" -Filter "*{}*.exe" | ForEach-Object {{ $_.FullName }}
"#,
"#,
path, app_name
)
};
Expand Down Expand Up @@ -275,8 +275,8 @@ async fn get_exe_by_appx(app_name: &str) -> Option<String> {
.arg("-Command")
.arg(format!(
r#"
Get-ChildItem -Path "C:\Program Files\WindowsApps\{}\*" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}
"#,
Get-ChildItem -Path "C:\Program Files\WindowsApps\{}\*" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}
"#,
package_name,
app_name_withoutspace
))
Expand All @@ -299,8 +299,8 @@ async fn get_exe_by_appx(app_name: &str) -> Option<String> {
.arg("-Command")
.arg(format!(
r#"
Get-ChildItem -Path "C:\Program Files\WindowsApps\{}\*" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}
"#,
Get-ChildItem -Path "C:\Program Files\WindowsApps\{}\*" -Filter "*{}*.exe" -Recurse | ForEach-Object {{ $_.FullName }}
"#,
package_name,
app_name
))
Expand Down
1 change: 1 addition & 0 deletions screenpipe-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ pub use server::SCServer;
pub use server::{api_list_monitors, MonitorInfo};
pub use video::VideoCapture;
pub mod embedding;
pub mod icons;
57 changes: 57 additions & 0 deletions screenpipe-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::{
Json, Path, Query, State,
},
http::StatusCode,
http::header::{CONTENT_TYPE, CACHE_CONTROL, HeaderValue},
response::{IntoResponse, Json as JsonResponse, Response},
routing::get,
serve, Router,
Expand Down Expand Up @@ -1065,6 +1066,7 @@ impl SCServer {
.get("/semantic-search", semantic_search_handler)
.get("/pipes/build-status/:pipe_id", get_pipe_build_status)
.get("/search/keyword", keyword_search_handler)
.get("/app/icon", get_app_icon_handler)
.post("/v1/embeddings", create_embeddings)
.post("/audio/device/start", start_audio_device)
.post("/audio/device/stop", stop_audio_device)
Expand Down Expand Up @@ -2892,6 +2894,55 @@ pub async fn purge_pipe_handler(
}
}

#[oasgen]
pub async fn get_app_icon_handler(
State(_state): State<Arc<AppState>>,
Query(app_name): Query<AppIconQuery>,
) -> Result<Response<Body>, (StatusCode, String)> {

info!("received app icon request: {:?}", app_name);

#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
{
match crate::icons::get_app_icon(&app_name.name, app_name.path).await {
Ok(Some(icon)) => {
let headers = [
(CONTENT_TYPE, HeaderValue::from_static("image/jpeg")),
(
CACHE_CONTROL,
HeaderValue::from_static("public, max-age=604800"),
),
];

let mut response = Response::new(Body::from(icon.data));
for (key, value) in &headers {
response.headers_mut().insert(key, value.clone());
}
Ok(response)
}
Ok(None) => Err((
StatusCode::NOT_FOUND,
format!("Icon not found"),
)),
Err(e) => {
error!("failed to get app icon: {}", e);
Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("failed to get app icon: {}", e),
))
}
}
}

#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
{
Err((
StatusCode::NOT_IMPLEMENTED,
JsonResponse(Value::String(format!("app icon retrieval not supported on this platform"))),
))
}
}

// Add this struct for the request payload
#[derive(Debug, OaSchema, Deserialize)]
pub struct DeletePipeRequest {
Expand All @@ -2907,6 +2958,12 @@ struct MergeSpeakersRequest {
#[derive(Debug, OaSchema, Deserialize)]
pub struct PurgePipeRequest {}

#[derive(Debug, OaSchema, Deserialize)]
pub struct AppIconQuery {
name: String,
path: Option<String>,
}

// New structs for UI automation API
#[derive(Debug, OaSchema, Deserialize, Serialize)]
pub struct ElementSelector {
Expand Down
27 changes: 27 additions & 0 deletions screenpipe-server/tests/icons_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use screenpipe_server::icons::get_app_icon;

#[tokio::test]
async fn test_get_app_icon() {
let apps = vec![
"firefox",
"screenpipe",
"safari",
];

for app in apps {
let result = get_app_icon(app, None).await;
assert!(result.is_ok(), "failed to get app icon");
let app_icon = result.unwrap();
assert!(app_icon.is_some());
}
}


#[tokio::test]
async fn test_get_app_icon_with_invalid_app_name() {
let app_name = "NonExistentApp";
let result = get_app_icon(app_name, None).await;
assert!(result.is_ok());
let app_icon = result.unwrap();
assert!(app_icon.is_none());
}
Loading