Skip to content

Commit 9e8b455

Browse files
committed
fix: ensure query results are cleared correctly when app visibility changes
1 parent 92fa6ac commit 9e8b455

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

wox.ui.flutter/wox/lib/controllers/wox_launcher_controller.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,11 @@ class WoxLauncherController extends GetxController {
883883
// and then the query result is received which will expand the windows height. so it will causes window flicker
884884
clearQueryResultsTimer.cancel();
885885

886-
// If app is hidden (e.g. tray query will trigger change query first then showapp), clear immediately so old results won't flash when shown.
886+
final currentQueryId = query.queryId;
887887
final isVisible = await windowManager.isVisible();
888+
// If app is hidden (e.g. tray query will trigger change query first then showapp), clear immediately so old results won't flash when shown.
888889
if (!isVisible) {
889-
clearQueryResults(traceId);
890+
await clearQueryResults(traceId);
890891
Logger.instance.debug(traceId, "clear query results immediately because window is hidden");
891892
} else {
892893
// delay clear results, otherwise windows height will shrink immediately,
@@ -903,6 +904,11 @@ class WoxLauncherController extends GetxController {
903904
}
904905

905906
clearQueryResultsTimer = Timer(Duration(milliseconds: clearQueryResultDelay), () {
907+
if (currentQuery.value.queryId != currentQueryId) return;
908+
909+
final hasResultsNow = activeResultViewController.items.isNotEmpty && activeResultViewController.items.first.value.data.queryId == currentQueryId;
910+
if (isCurrentQueryReturned || hasResultsNow) return;
911+
906912
clearQueryResults(traceId);
907913
});
908914
}
@@ -971,7 +977,7 @@ class WoxLauncherController extends GetxController {
971977
showApp(msg.traceId, ShowAppParams.fromJson(msg.data));
972978
responseWoxWebsocketRequest(msg, true, null);
973979
} else if (msg.method == "ChangeQuery") {
974-
onQueryChanged(msg.traceId, PlainQuery.fromJson(msg.data), "receive change query from wox", moveCursorToEnd: true);
980+
await onQueryChanged(msg.traceId, PlainQuery.fromJson(msg.data), "receive change query from wox", moveCursorToEnd: true);
975981
focusQueryBox();
976982
responseWoxWebsocketRequest(msg, true, null);
977983
} else if (msg.method == "RefreshQuery") {

0 commit comments

Comments
 (0)