From ba3e36e562f5028f54840258312caed99577acb0 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 1 Aug 2026 18:26:09 +0800 Subject: launcher(duckduckgo.rs): qml usable interface --- qml_plugin/src/web/duckduckgo.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'qml_plugin/src/web') diff --git a/qml_plugin/src/web/duckduckgo.rs b/qml_plugin/src/web/duckduckgo.rs index f80e4c8..3793485 100644 --- a/qml_plugin/src/web/duckduckgo.rs +++ b/qml_plugin/src/web/duckduckgo.rs @@ -1,5 +1,6 @@ use std::ops::{Deref, DerefMut}; +use crate::launcher::duckduckgo::QmlDuckDuckGo; use duckduckgo::{ browser::Browser, params::{SafeSearch, SearchParams, Toggle}, @@ -9,12 +10,35 @@ use serde::Deserialize; const DUCKDUCKGO: &str = "https://duckduckgo.com"; +#[derive(Default, PartialEq)] pub struct DuckDuckGoContent { title: String, description_html: String, preview_image: Option, } +impl From for QmlDuckDuckGo { + fn from(value: DuckDuckGoContent) -> Self { + Self { + title: value + .title + .into(), + description_html: value + .description_html + .into(), + preview_image: value + .preview_image + .map( + |u| { + u.to_string() + .into() + }, + ) + .unwrap_or_default(), + } + } +} + #[derive(Debug, Deserialize)] pub struct Infobox { pub content: Vec, @@ -121,7 +145,7 @@ pub async fn query(input: &str) -> anyhow::Result { // TODO: try also Results[*].Icon.URL and RelatedTopics[*].Icon.URL preview_image: resp .image - .and_then(|i| Url::parse(&(DUCKDUCKGO.to_owned() + &i)).ok()), + .and_then(|i| Url::parse(&format!("{DUCKDUCKGO}{i}",)).ok()), }, ) } -- cgit v1.2.3