summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-07-26 20:11:59 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-07-26 20:11:59 +0800
commitdf74bc4c98036f6b0bddf1c9baf772274e33606a (patch)
treea30a39be761212203cd2b9c2cc625f55767cd2ca
parentc119b2cf8eb2fe2cb2b204e870deb7c6dfb189ee (diff)
perf(SmartCalc): cahce query in event of multiple component calling
query at once with the same query cleanup: no longer needed qml and unused import
-rw-r--r--popups/launcher/components/Date.qml1
-rw-r--r--qml_plugin/src/launcher/calc.rs21
-rw-r--r--services/_SmartCalc.qml37
3 files changed, 18 insertions, 41 deletions
diff --git a/popups/launcher/components/Date.qml b/popups/launcher/components/Date.qml
index 43cb99e..a23c0b0 100644
--- a/popups/launcher/components/Date.qml
+++ b/popups/launcher/components/Date.qml
@@ -9,6 +9,7 @@ import qs.config
import core
IComponent {
+ property int cursorPosition: SelectionState.cursorPosition
property string answer: active && valid ? SmartCalc.result : ""
name: "Date"
diff --git a/qml_plugin/src/launcher/calc.rs b/qml_plugin/src/launcher/calc.rs
index 196484e..7b1b066 100644
--- a/qml_plugin/src/launcher/calc.rs
+++ b/qml_plugin/src/launcher/calc.rs
@@ -1,6 +1,6 @@
-use cxx_qt::{QObject, Threading};
-use cxx_qt_lib::{QDateTime, QString, QVariant};
-use std::{pin::Pin, sync::mpsc, time::Duration};
+use cxx_qt::Threading;
+use cxx_qt_lib::{QString, QVariant};
+use std::pin::Pin;
use crate::RUNTIME;
@@ -24,6 +24,10 @@ mod qobject {
ResultType,
result_type
)]
+ #[qproperty(
+ QVariant,
+ cached_query
+ )]
type SmartCalc = super::SmartCalcRs;
#[qinvokable]
@@ -70,10 +74,17 @@ impl From<&smart_calculator::types::ResultType> for qobject::ResultType {
pub struct SmartCalcRs {
result: QVariant,
result_type: qobject::ResultType,
+
+ cached_query: QVariant,
}
impl qobject::SmartCalc {
- fn query(self: Pin<&mut Self>, input: QString) {
+ fn query(mut self: Pin<&mut Self>, input: QString) {
+ if self.cached_query == (&input).into() {
+ return;
+ }
+ self.as_mut()
+ .set_cached_query((&input.clone()).into());
let qt_thread = self.qt_thread();
RUNTIME.spawn(
async move {
@@ -118,5 +129,7 @@ impl qobject::SmartCalc {
.set_result(QVariant::default());
self.as_mut()
.set_result_type(qobject::ResultType::Unset);
+ self.as_mut()
+ .set_cached_query(QVariant::default());
}
}
diff --git a/services/_SmartCalc.qml b/services/_SmartCalc.qml
deleted file mode 100644
index fd9f134..0000000
--- a/services/_SmartCalc.qml
+++ /dev/null
@@ -1,37 +0,0 @@
-pragma Singleton
-// pragma ComponentBehavior: Bound
-
-import QtQuick
-import Quickshell
-import Quickshell.Io
-
-import qs.config
-
-import core
-
-Singleton {
- id: root
-
- property var result: Calc.result
- property int result_type: Calc.result_type
- readonly property var resultType: ({
- "Math": Calc.Math,
- "Unit": Calc.Unit,
- "Currency": Calc.Currency,
- "Crypto": Calc.Crypto,
- "Time": Calc.Time,
- "Date": Calc.Date,
- "Unset": Calc.Unset
- })
-
- function query(input: string) {
- console.log(input)
- Calc.query(input);
- }
-
-
- // FIXME: we'll prolly need to reset() everytime here after it finish just so the next time another component using it won't be affected by the previous query
- function reset() {
- Calc.reset();
- }
-}