16
16
#include < fcitx-config/iniparser.h>
17
17
#include < fcitx-config/rawconfig.h>
18
18
#include < fcitx-utils/event.h>
19
+ #include < fcitx-utils/eventloopinterface.h>
19
20
#include < fcitx-utils/fs.h>
20
21
#include < fcitx-utils/i18n.h>
21
22
#include < fcitx-utils/log.h>
@@ -53,6 +54,9 @@ namespace fcitx::rime {
53
54
54
55
namespace {
55
56
57
+ // Allow notification for 60secs.
58
+ constexpr uint64_t NotificationTimeout = 60000000 ;
59
+
56
60
std::unordered_map<std::string, std::unordered_map<std::string, bool >>
57
61
parseAppOptions (rime_api_t *api, RimeConfig *config) {
58
62
std::unordered_map<std::string, std::unordered_map<std::string, bool >>
@@ -210,7 +214,7 @@ RimeEngine::RimeEngine(Instance *instance)
210
214
syncAction_.setShortText (_ (" Synchronize" ));
211
215
212
216
syncAction_.connect <SimpleAction::Activated>([this ](InputContext *ic) {
213
- sync ();
217
+ sync (/* userTriggered= */ true );
214
218
auto *state = this ->state (ic);
215
219
if (state && ic->hasFocus ()) {
216
220
state->updateUI (ic, false );
@@ -224,6 +228,8 @@ RimeEngine::RimeEngine(Instance *instance)
224
228
globalConfigReloadHandle_ = instance_->watchEvent (
225
229
EventType::GlobalConfigReloaded, EventWatcherPhase::Default,
226
230
[this ](Event &) { refreshSessionPoolPolicy (); });
231
+
232
+ allowNotification (" failure" );
227
233
reloadConfig ();
228
234
constructed_ = true ;
229
235
}
@@ -335,7 +341,7 @@ void RimeEngine::setSubConfig(const std::string &path,
335
341
if (path == " deploy" ) {
336
342
deploy ();
337
343
} else if (path == " sync" ) {
338
- sync ();
344
+ sync (/* userTriggered= */ true );
339
345
}
340
346
}
341
347
@@ -504,7 +510,6 @@ void RimeEngine::deactivate(const InputMethodEntry &entry,
504
510
505
511
void RimeEngine::keyEvent (const InputMethodEntry &entry, KeyEvent &event) {
506
512
FCITX_UNUSED (entry);
507
- lastKeyEventTime_ = now (CLOCK_MONOTONIC);
508
513
RIME_DEBUG () << " Rime receive key: " << event.rawKey () << " "
509
514
<< event.isRelease ();
510
515
auto *inputContext = event.inputContext ();
@@ -513,7 +518,7 @@ void RimeEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &event) {
513
518
deploy ();
514
519
return event.filterAndAccept ();
515
520
} else if (event.key ().checkKeyList (*config_.synchronize )) {
516
- sync ();
521
+ sync (/* userTriggered= */ true );
517
522
return event.filterAndAccept ();
518
523
}
519
524
}
@@ -534,15 +539,12 @@ void RimeEngine::reset(const InputMethodEntry & /*entry*/,
534
539
inputContext->updateUserInterface (UserInterfaceComponent::InputPanel);
535
540
}
536
541
537
- void RimeEngine::blockNotificationFor (uint64_t usec) {
538
- blockNotificationBefore_ = now (CLOCK_MONOTONIC) + usec;
542
+ void RimeEngine::allowNotification (std::string type) {
543
+ allowNotificationUntil_ = now (CLOCK_MONOTONIC) + NotificationTimeout;
544
+ allowNotificationType_ = std::move (type);
539
545
}
540
546
541
- void RimeEngine::save () {
542
- // Block notification for 5 sec.
543
- blockNotificationFor (5000000 );
544
- sync ();
545
- }
547
+ void RimeEngine::save () { sync (/* userTriggered=*/ false ); }
546
548
547
549
void RimeEngine::rimeNotificationHandler (void *context, RimeSessionId session,
548
550
const char *messageType,
@@ -578,7 +580,7 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType,
578
580
const char *message = nullptr ;
579
581
const char *icon = " " ;
580
582
const char *tipId = " " ;
581
- int timeout = 3000 ;
583
+ const int timeout = 3000 ;
582
584
bool blockMessage = false ;
583
585
if (messageType == " deploy" ) {
584
586
tipId = " fcitx-rime-deploy" ;
@@ -612,14 +614,17 @@ void RimeEngine::notify(RimeSessionId session, const std::string &messageType,
612
614
}
613
615
614
616
auto *notifications = this ->notifications ();
615
- if (message && notifications &&
616
- now (CLOCK_MONOTONIC) > blockNotificationBefore_) {
617
+ const auto current = now (CLOCK_MONOTONIC);
618
+ if (message && notifications && current > silenceNotificationUntil_ &&
619
+ (current < allowNotificationUntil_ &&
620
+ (allowNotificationType_.empty () ||
621
+ messageType == allowNotificationType_))) {
617
622
notifications->call <INotifications::showTip>(
618
623
tipId, _ (" Rime" ), icon, _ (" Rime" ), message, timeout);
619
624
}
620
625
// Block message after error / success.
621
626
if (blockMessage) {
622
- blockNotificationFor ( 30000 ) ;
627
+ silenceNotificationUntil_ = current + 30000 ;
623
628
}
624
629
}
625
630
@@ -683,12 +688,16 @@ void RimeEngine::deploy() {
683
688
RIME_DEBUG () << " Rime Deploy" ;
684
689
releaseAllSession (true );
685
690
api_->finalize ();
691
+ allowNotification ();
686
692
rimeStart (true );
687
693
}
688
694
689
- void RimeEngine::sync () {
695
+ void RimeEngine::sync (bool userTriggered ) {
690
696
RIME_DEBUG () << " Rime Sync user data" ;
691
697
releaseAllSession (true );
698
+ if (userTriggered) {
699
+ allowNotification ();
700
+ }
692
701
api_->sync_user_data ();
693
702
}
694
703
@@ -757,7 +766,6 @@ void RimeEngine::updateSchemaMenu() {
757
766
schemaAction.connect <SimpleAction::Activated>(
758
767
[this , schemaId](InputContext *ic) {
759
768
auto *state = this ->state (ic);
760
- blockNotificationFor (30000 );
761
769
state->selectSchema (schemaId);
762
770
imAction_->update (ic);
763
771
});
0 commit comments