diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-08-01 18:26:09 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-08-01 18:26:09 +0800 |
| commit | ba3e36e562f5028f54840258312caed99577acb0 (patch) | |
| tree | 9a982ec1598f5ec0d8c487048230a016c3453e27 /qml_plugin/src/web/duckduckgo.rs | |
| parent | 1d6da847b7075b4babf3409b9445db0b54677893 (diff) | |
launcher(duckduckgo.rs): qml usable interface
Diffstat (limited to 'qml_plugin/src/web/duckduckgo.rs')
| -rw-r--r-- | qml_plugin/src/web/duckduckgo.rs | 26 |
1 files changed, 25 insertions, 1 deletions
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<Url>, } +impl From<DuckDuckGoContent> 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<InfoboxContent>, @@ -121,7 +145,7 @@ pub async fn query(input: &str) -> anyhow::Result<DuckDuckGoContent> { // 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()), }, ) } |
