From 93b1f7e21d252cf7a1267fe5e1e25d2060649412 Mon Sep 17 00:00:00 2001 From: wcjord <32568597+wcjord@users.noreply.github.com> Date: Mon, 30 Dec 2024 09:37:25 -0500 Subject: [PATCH] Wait-for-igc (#1311) * feat: wait longer before calling igc * fix: don't call showFirstMatch if running IT --------- Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> Co-authored-by: ggurdin --- .../controllers/choreographer.dart | 21 +++++++++++++------ .../repo/full_text_translation_repo.dart | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index daa687fc9..b17a413c6 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -48,6 +48,8 @@ class Choreographer { bool isFetching = false; int _timesClicked = 0; + final int msBeforeIGCStart = 10000; + Timer? debounceTimer; ChoreoRecord choreoRecord = ChoreoRecord.newRecord; // last checked by IGC or translation @@ -77,10 +79,13 @@ class Choreographer { void send(BuildContext context) { debugPrint("can send message: $canSendMessage"); - if (!canSendMessage) { - if (igc.igcTextData != null && igc.igcTextData!.matches.isNotEmpty) { - igc.showFirstMatch(context); - } + if (igc.igcTextData != null && igc.igcTextData!.matches.isNotEmpty) { + igc.showFirstMatch(context); + return; + } else if (isRunningIT) { + // If the user is in the middle of IT, don't send the message. + // If they've already clicked the send button once, this will + // not be true, so they can still send it if they want. return; } @@ -107,7 +112,11 @@ class Choreographer { Future _sendWithIGC(BuildContext context) async { if (!canSendMessage) { - igc.showFirstMatch(context); + // It's possible that the reason user can't send message is because they're in the middle of IT. If this is the case, + // do nothing (there's no matches to show). The user can click the send button again to override this. + if (!isRunningIT) { + igc.showFirstMatch(context); + } return; } @@ -237,7 +246,7 @@ class Choreographer { if (editTypeIsKeyboard) { debounceTimer ??= Timer( - const Duration(milliseconds: 1500), + Duration(milliseconds: msBeforeIGCStart), () => getLanguageHelp(), ); } else { diff --git a/lib/pangea/repo/full_text_translation_repo.dart b/lib/pangea/repo/full_text_translation_repo.dart index be15e7855..ded554839 100644 --- a/lib/pangea/repo/full_text_translation_repo.dart +++ b/lib/pangea/repo/full_text_translation_repo.dart @@ -16,7 +16,7 @@ class FullTextTranslationRepo { // start a timer to clear the cache static void startCacheTimer() { - _cacheTimer = Timer.periodic(const Duration(minutes: 3), (timer) { + _cacheTimer = Timer.periodic(const Duration(minutes: 10), (timer) { clearCache(); }); }