From f105577608abd7f2211128abc0d3b812930cba2d Mon Sep 17 00:00:00 2001 From: PandaDEV <70103896+0PandaDEV@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:32:02 +1000 Subject: [PATCH] feat(rust): Add page metadata fetching command --- src-tauri/src/main.rs | 1 + src-tauri/src/utils/commands.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 26d1048..0621936 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -112,6 +112,7 @@ fn main() { db::settings::save_setting, db::settings::save_keybind, db::settings::get_keybind, + utils::commands::fetch_page_meta, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/utils/commands.rs b/src-tauri/src/utils/commands.rs index 6ffa6c9..f87a866 100644 --- a/src-tauri/src/utils/commands.rs +++ b/src-tauri/src/utils/commands.rs @@ -2,6 +2,7 @@ use active_win_pos_rs::get_active_window; use base64::{engine::general_purpose::STANDARD, Engine}; use image::codecs::png::PngEncoder; use tauri::PhysicalPosition; +use meta_fetcher; pub fn center_window_on_current_monitor(window: &tauri::WebviewWindow) { if let Some(monitor) = window.available_monitors().unwrap().iter().find(|m| { @@ -94,4 +95,15 @@ pub fn detect_color(color: &str) -> bool { } false +} + +#[tauri::command] +pub async fn fetch_page_meta(url: String) -> Result<(String, Option), String> { + let metadata = meta_fetcher::fetch_metadata(&url) + .map_err(|e| format!("Failed to fetch metadata: {}", e))?; + + Ok(( + metadata.title.unwrap_or_else(|| "No title found".to_string()), + metadata.image + )) } \ No newline at end of file