Skip to content

Commit

Permalink
block initial message after start up
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Jan 23, 2025
1 parent 9155bf3 commit a55340f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/rimeengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fcitx-config/iniparser.h>
#include <fcitx-config/rawconfig.h>
#include <fcitx-utils/event.h>
#include <fcitx-utils/eventloopinterface.h>
#include <fcitx-utils/fs.h>
#include <fcitx-utils/i18n.h>
#include <fcitx-utils/log.h>
Expand Down Expand Up @@ -53,6 +54,8 @@ namespace fcitx::rime {

namespace {

constexpr uint64_t startUpMessageTimeout = 5000000;

std::unordered_map<std::string, std::unordered_map<std::string, bool>>
parseAppOptions(rime_api_t *api, RimeConfig *config) {
std::unordered_map<std::string, std::unordered_map<std::string, bool>>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand All @@ -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);
Expand All @@ -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<INotifications::showTip>(
tipId, _("Rime"), icon, _("Rime"), message, timeout);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rimeengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RimeState> factory_;
bool needRefreshAppOption_ = false;

Expand Down

0 comments on commit a55340f

Please sign in to comment.