Skip to content

Commit 6e7ca81

Browse files
committed
feat: notify missing input methods on startup (#516)
1 parent 13cc836 commit 6e7ca81

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/lib/fcitx/inputmethodmanager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class InputMethodManagerPrivate : QPtrHolder<InputMethodManager> {
6969
Instance *instance_ = nullptr;
7070
std::unique_ptr<HandlerTableEntry<EventHandler>> eventWatcher_;
7171
int64_t timestamp_ = 0;
72+
std::vector<std::string> missingInputMethods_;
7273
};
7374

7475
bool checkEntry(const InputMethodEntry &entry,
@@ -111,6 +112,7 @@ void InputMethodManagerPrivate::loadConfig(
111112
FCITX_WARN() << "Group Item " << item.name.value()
112113
<< " in group " << groupConfig.name.value()
113114
<< " is not valid. Removed.";
115+
missingInputMethods_.push_back(item.name.value());
114116
continue;
115117
}
116118
group.inputMethodList().emplace_back(
@@ -236,6 +238,7 @@ void InputMethodManager::load(const std::function<void(InputMethodManager &)>
236238
d->loadStaticEntries(addonNames);
237239
d->loadDynamicEntries(addonNames);
238240

241+
d->missingInputMethods_.clear();
239242
d->loadConfig(buildDefaultGroupCallback);
240243
// groupOrder guarantee to be non-empty at this point.
241244
emit<InputMethodManager::CurrentGroupChanged>(d->groupOrder_.front());
@@ -455,6 +458,12 @@ InputMethodManager::entry(const std::string &name) const {
455458
FCITX_D();
456459
return findValue(d->entries_, name);
457460
}
461+
462+
const std::vector<std::string> &InputMethodManager::missingInputMethods() const {
463+
FCITX_D();
464+
return d->missingInputMethods_;
465+
}
466+
458467
bool InputMethodManager::foreachEntries(
459468
const std::function<bool(const InputMethodEntry &entry)> &callback) {
460469
FCITX_D();

src/lib/fcitx/inputmethodmanager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ class FCITXCORE_EXPORT InputMethodManager : public ConnectableObject {
134134
/// Return a given input method entry by name.
135135
const InputMethodEntry *entry(const std::string &name) const;
136136

137+
/**
138+
* Return the names of input methods that are configured but not available.
139+
*
140+
* @since 5.1.13
141+
*/
142+
const std::vector<std::string> &missingInputMethods() const;
143+
137144
/**
138145
* Enumerate all the input method entries.
139146
*

src/lib/fcitx/instance.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,19 @@ void Instance::initialize() {
14711471
return false;
14721472
});
14731473
d->notifications_ = d->addonManager_.addon("notifications", true);
1474+
if (d->notifications_ && !d->imManager_.missingInputMethods().empty()) {
1475+
std::string body;
1476+
for (const auto &im : d->imManager_.missingInputMethods()) {
1477+
if (!body.empty()) {
1478+
body += ", ";
1479+
}
1480+
body += im;
1481+
}
1482+
d->notifications_->call<INotifications::sendNotification>(
1483+
"fcitx", 0, "fcitx", _("Missing input methods"),
1484+
_("The following input methods are not available: {0}"),
1485+
std::vector<std::string>{body}, 0, nullptr, nullptr);
1486+
}
14741487
}
14751488

14761489
int Instance::exec() {

0 commit comments

Comments
 (0)