summaryrefslogtreecommitdiff
path: root/qml_plugin/src/web
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-09-18 15:13:01 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-10-01 15:10:27 +0800
commit3cea94b72dbfdd2077a59fc52a7460e200b6061e (patch)
tree294a8cb1ef3aadc189073492bb041f6af2b17f70 /qml_plugin/src/web
parent8a71bd72f53e3629fb1d23d7c1b153207ba44789 (diff)
refactor: qml_pluginmain
Diffstat (limited to 'qml_plugin/src/web')
-rw-r--r--qml_plugin/src/web/duckduckgo.rs78
1 files changed, 46 insertions, 32 deletions
diff --git a/qml_plugin/src/web/duckduckgo.rs b/qml_plugin/src/web/duckduckgo.rs
index 6b4edae..e5f1b64 100644
--- a/qml_plugin/src/web/duckduckgo.rs
+++ b/qml_plugin/src/web/duckduckgo.rs
@@ -1,6 +1,5 @@
use std::ops::{Deref, DerefMut};
-use crate::launcher::duckduckgo::QmlDuckDuckGo;
use duckduckgo::{
browser::Browser,
params::{SafeSearch, SearchParams, Toggle},
@@ -8,6 +7,8 @@ use duckduckgo::{
use reqwest::Url;
use serde::Deserialize;
+use crate::qml_interface::duckduckgo::QmlDuckDuckGo;
+
const DUCKDUCKGO: &str = "https://duckduckgo.com";
#[derive(Default, PartialEq)]
@@ -83,36 +84,49 @@ pub async fn query(input: &str) -> anyhow::Result<DuckDuckGoContent> {
_ => None,
};
- let alt_desc = resp.entity.unwrap_or(match infobox {
- Some(i) => i
- .iter()
- .find(|i| i.data_type == "wd_description" || i.data_type == "official_website")
- .map_or(String::new(), |i| {
- if i.data_type == "official_website" {
- i.label.clone()
- } else {
- match i.value {
- InfoboxValue::Entity(_) => unreachable!(),
- InfoboxValue::String(ref s) => s.to_string(),
+ let alt_desc = resp.entity.unwrap_or(
+ match infobox {
+ Some(i) => i
+ .iter()
+ .find(|i| i.data_type == "wd_description" || i.data_type == "official_website")
+ .map_or(
+ String::new(),
+ |i| {
+ if i.data_type == "official_website" {
+ i.label.clone()
+ } else {
+ match i.value {
+ InfoboxValue::Entity(_) => unreachable!(),
+ InfoboxValue::String(ref s) => s.to_string(),
+ }
+ }
+ },
+ ),
+ // TODO: find better way to get title from infobox
+ None => String::new(),
+ },
+ );
+
+ Ok(
+ DuckDuckGoContent {
+ title: resp
+ .heading
+ .filter(|h| !h.is_empty())
+ .unwrap_or(resp.definition.filter(|d| !d.is_empty()).unwrap_or(alt_desc.clone())),
+ description_html: resp
+ .answer
+ .filter(|a| !a.is_empty())
+ .unwrap_or(resp.r#abstract.filter(|a| !a.is_empty()).unwrap_or(alt_desc)),
+ // TODO: try also Results[*].Icon.URL and RelatedTopics[*].Icon.URL
+ image: resp.image.filter(|i| !i.is_empty()).and_then(
+ |i| {
+ if !i.is_empty() {
+ Url::parse(&format!("{DUCKDUCKGO}{i}",)).ok()
+ } else {
+ None
}
- }
- }),
- // TODO: find better way to get title from infobox
- None => String::new(),
- });
-
- Ok(DuckDuckGoContent {
- title: resp
- .heading
- .filter(|h| !h.is_empty())
- .unwrap_or(resp.definition.filter(|d| !d.is_empty()).unwrap_or(alt_desc.clone())),
- description_html: resp
- .answer
- .filter(|a| !a.is_empty())
- .unwrap_or(resp.r#abstract.filter(|a| !a.is_empty()).unwrap_or(alt_desc)),
- // TODO: try also Results[*].Icon.URL and RelatedTopics[*].Icon.URL
- image: resp.image.filter(|i| !i.is_empty()).and_then(|i| {
- if !i.is_empty() { Url::parse(&format!("{DUCKDUCKGO}{i}",)).ok() } else { None }
- }),
- })
+ },
+ ),
+ },
+ )
}