summaryrefslogtreecommitdiff
path: root/qml_plugin/src/launcher/duckduckgo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'qml_plugin/src/launcher/duckduckgo.rs')
-rw-r--r--qml_plugin/src/launcher/duckduckgo.rs98
1 files changed, 33 insertions, 65 deletions
diff --git a/qml_plugin/src/launcher/duckduckgo.rs b/qml_plugin/src/launcher/duckduckgo.rs
index 16c9102..0375cdf 100644
--- a/qml_plugin/src/launcher/duckduckgo.rs
+++ b/qml_plugin/src/launcher/duckduckgo.rs
@@ -16,19 +16,10 @@ mod qobject {
#[qobject]
#[qml_element]
#[qml_singleton]
- #[qproperty(
- bool, ok
- )]
- #[qproperty(
- QString, title
- )]
- #[qproperty(
- QString,
- description_html
- )]
- #[qproperty(
- QString, image
- )]
+ #[qproperty(bool, ok)]
+ #[qproperty(QString, title)]
+ #[qproperty(QString, description_html)]
+ #[qproperty(QString, image)]
type DuckDuckGo = super::DuckDuckGoRs;
#[qinvokable]
@@ -61,60 +52,37 @@ pub struct DuckDuckGoRs {
impl qobject::DuckDuckGo {
fn query(self: Pin<&mut Self>, input: QString) {
let qt_thread = self.qt_thread();
- self.rust_mut()
- .executor
- .spawn(
- async move {
- let qinput = input.to_string();
- let result: Result<QmlDuckDuckGo, _> = duckduckgo::query(&qinput)
- .await
- .map(|r| r.into());
- // consider just unwrapping since this is in a separate thread and is already
- // end of life anw
- _ = qt_thread
- .queue(
- move |mut qo| match result {
- Ok(r) => {
- if (r
- .title
- .to_lower()
- == input.to_lower()
- || r.title
- .is_empty())
- && r.description_html
- .is_empty()
- && r.image
- .is_empty()
- {
- qo.as_mut()
- .set_ok(false);
- } else {
- qo.as_mut()
- .set_ok(true);
- qo.as_mut()
- .set_title(r.title);
- qo.as_mut()
- .set_description_html(r.description_html);
- qo.as_mut()
- .set_image(r.image);
- }
- }
- Err(_) => qo.set_ok(false),
- },
- )
- .unwrap_print();
- },
- );
+ self.rust_mut().executor.spawn(async move {
+ let qinput = input.to_string();
+ let result: Result<QmlDuckDuckGo, _> =
+ duckduckgo::query(&qinput).await.map(|r| r.into());
+ // consider just unwrapping since this is in a separate thread and
+ // is already end of life anw
+ _ = qt_thread
+ .queue(move |mut qo| match result {
+ Ok(r) => {
+ if (r.title.to_lower() == input.to_lower() || r.title.is_empty())
+ && r.description_html.is_empty()
+ && r.image.is_empty()
+ {
+ qo.as_mut().set_ok(false);
+ } else {
+ qo.as_mut().set_ok(true);
+ qo.as_mut().set_title(r.title);
+ qo.as_mut().set_description_html(r.description_html);
+ qo.as_mut().set_image(r.image);
+ }
+ }
+ Err(_) => qo.set_ok(false),
+ })
+ .unwrap_print();
+ });
}
fn reset(mut self: Pin<&mut Self>) {
- self.as_mut()
- .set_ok(false);
- self.as_mut()
- .set_title("".into());
- self.as_mut()
- .set_description_html("".into());
- self.as_mut()
- .set_image("".into());
+ self.as_mut().set_ok(false);
+ self.as_mut().set_title("".into());
+ self.as_mut().set_description_html("".into());
+ self.as_mut().set_image("".into());
}
}