Skip to content

Commit a55340f

Browse files
committed
block initial message after start up
1 parent 9155bf3 commit a55340f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Diff for: src/rimeengine.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <fcitx-config/iniparser.h>
1717
#include <fcitx-config/rawconfig.h>
1818
#include <fcitx-utils/event.h>
19+
#include <fcitx-utils/eventloopinterface.h>
1920
#include <fcitx-utils/fs.h>
2021
#include <fcitx-utils/i18n.h>
2122
#include <fcitx-utils/log.h>
@@ -53,6 +54,8 @@ namespace fcitx::rime {
5354

5455
namespace {
5556

57+
constexpr uint64_t startUpMessageTimeout = 5000000;
58+
5659
std::unordered_map<std::string, std::unordered_map<std::string, bool>>
5760
parseAppOptions(rime_api_t *api, RimeConfig *config) {
5861
std::unordered_map<std::string, std::unordered_map<std::string, bool>>
@@ -224,6 +227,8 @@ RimeEngine::RimeEngine(Instance *instance)
224227
globalConfigReloadHandle_ = instance_->watchEvent(
225228
EventType::GlobalConfigReloaded, EventWatcherPhase::Default,
226229
[this](Event &) { refreshSessionPoolPolicy(); });
230+
231+
startUpTime_ = now(CLOCK_MONOTONIC);
227232
reloadConfig();
228233
constructed_ = true;
229234
}
@@ -504,7 +509,6 @@ void RimeEngine::deactivate(const InputMethodEntry &entry,
504509

505510
void RimeEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &event) {
506511
FCITX_UNUSED(entry);
507-
lastKeyEventTime_ = now(CLOCK_MONOTONIC);
508512
RIME_DEBUG() << "Rime receive key: " << event.rawKey() << " "
509513
<< event.isRelease();
510514
auto *inputContext = event.inputContext();
@@ -580,6 +584,7 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType,
580584
const char *tipId = "";
581585
int timeout = 3000;
582586
bool blockMessage = false;
587+
bool startUpTimeCheck = true;
583588
if (messageType == "deploy") {
584589
tipId = "fcitx-rime-deploy";
585590
icon = "fcitx_rime_deploy";
@@ -603,6 +608,8 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType,
603608
message = _("Rime has encountered an error. "
604609
"See log for details.");
605610
blockMessage = true;
611+
// Exclude error message from start up check.
612+
startUpTimeCheck = false;
606613
}
607614
} else if (messageType == "option") {
608615
updateStatusArea(session);
@@ -612,8 +619,9 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType,
612619
}
613620

614621
auto *notifications = this->notifications();
615-
if (message && notifications &&
616-
now(CLOCK_MONOTONIC) > blockNotificationBefore_) {
622+
const auto current = now(CLOCK_MONOTONIC);
623+
if (message && notifications && current > blockNotificationBefore_ &&
624+
(!startUpTimeCheck || current > startUpTime_ + startUpMessageTimeout)) {
617625
notifications->call<INotifications::showTip>(
618626
tipId, _("Rime"), icon, _("Rime"), message, timeout);
619627
}

Diff for: src/rimeengine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class RimeEngine final : public InputMethodEngineV2 {
200200
rime_api_t *api_;
201201
static bool firstRun_;
202202
uint64_t blockNotificationBefore_ = 0;
203-
uint64_t lastKeyEventTime_ = 0;
203+
uint64_t startUpTime_ = 0;
204204
FactoryFor<RimeState> factory_;
205205
bool needRefreshAppOption_ = false;
206206

0 commit comments

Comments
 (0)