From a55340f79cebf5fb360d721cc1f1f7276ba36eca Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Thu, 23 Jan 2025 05:54:48 -0800 Subject: [PATCH] block initial message after start up --- src/rimeengine.cpp | 14 +++++++++++--- src/rimeengine.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rimeengine.cpp b/src/rimeengine.cpp index b335069..dde8388 100644 --- a/src/rimeengine.cpp +++ b/src/rimeengine.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,8 @@ namespace fcitx::rime { namespace { +constexpr uint64_t startUpMessageTimeout = 5000000; + std::unordered_map> parseAppOptions(rime_api_t *api, RimeConfig *config) { std::unordered_map> @@ -224,6 +227,8 @@ RimeEngine::RimeEngine(Instance *instance) globalConfigReloadHandle_ = instance_->watchEvent( EventType::GlobalConfigReloaded, EventWatcherPhase::Default, [this](Event &) { refreshSessionPoolPolicy(); }); + + startUpTime_ = now(CLOCK_MONOTONIC); reloadConfig(); constructed_ = true; } @@ -504,7 +509,6 @@ void RimeEngine::deactivate(const InputMethodEntry &entry, void RimeEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &event) { FCITX_UNUSED(entry); - lastKeyEventTime_ = now(CLOCK_MONOTONIC); RIME_DEBUG() << "Rime receive key: " << event.rawKey() << " " << event.isRelease(); auto *inputContext = event.inputContext(); @@ -580,6 +584,7 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType, const char *tipId = ""; int timeout = 3000; bool blockMessage = false; + bool startUpTimeCheck = true; if (messageType == "deploy") { tipId = "fcitx-rime-deploy"; icon = "fcitx_rime_deploy"; @@ -603,6 +608,8 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType, message = _("Rime has encountered an error. " "See log for details."); blockMessage = true; + // Exclude error message from start up check. + startUpTimeCheck = false; } } else if (messageType == "option") { updateStatusArea(session); @@ -612,8 +619,9 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType, } auto *notifications = this->notifications(); - if (message && notifications && - now(CLOCK_MONOTONIC) > blockNotificationBefore_) { + const auto current = now(CLOCK_MONOTONIC); + if (message && notifications && current > blockNotificationBefore_ && + (!startUpTimeCheck || current > startUpTime_ + startUpMessageTimeout)) { notifications->call( tipId, _("Rime"), icon, _("Rime"), message, timeout); } diff --git a/src/rimeengine.h b/src/rimeengine.h index 8a25c7a..e3f2f10 100644 --- a/src/rimeengine.h +++ b/src/rimeengine.h @@ -200,7 +200,7 @@ class RimeEngine final : public InputMethodEngineV2 { rime_api_t *api_; static bool firstRun_; uint64_t blockNotificationBefore_ = 0; - uint64_t lastKeyEventTime_ = 0; + uint64_t startUpTime_ = 0; FactoryFor factory_; bool needRefreshAppOption_ = false;