Skip to content

Commit f86b185

Browse files
committed
Update config functions.
- Implement set sub config to enable deploy/sync command via dbus. - Split reloadConfig to updateconfig to make write config file failure not affect runtime config.
1 parent e4fc600 commit f86b185

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/rimeengine.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,7 @@ RimeEngine::RimeEngine(Instance *instance)
9797
deployAction_.setIcon("rime-deploy");
9898
deployAction_.setShortText(_("Deploy"));
9999
deployAction_.connect<SimpleAction::Activated>([this](InputContext *ic) {
100-
instance_->inputContextManager().foreach([this](InputContext *ic) {
101-
auto state = this->state(ic);
102-
state->release();
103-
return true;
104-
});
105-
api_->sync_user_data();
106-
api_->finalize();
107-
rimeStart(true);
100+
deploy();
108101
auto state = this->state(ic);
109102
if (ic->hasFocus()) {
110103
state->updateUI(ic, false);
@@ -117,7 +110,7 @@ RimeEngine::RimeEngine(Instance *instance)
117110
syncAction_.setShortText(_("Synchronize"));
118111

119112
syncAction_.connect<SimpleAction::Activated>([this](InputContext *ic) {
120-
api_->sync_user_data();
113+
sync();
121114
auto state = this->state(ic);
122115
if (ic->hasFocus()) {
123116
state->updateUI(ic, false);
@@ -186,6 +179,18 @@ void RimeEngine::rimeStart(bool fullcheck) {
186179

187180
void RimeEngine::reloadConfig() {
188181
readAsIni(config_, "conf/rime.conf");
182+
updateConfig();
183+
}
184+
185+
void RimeEngine::setSubConfig(const std::string &path, const RawConfig &) {
186+
if (path == "deploy") {
187+
deploy();
188+
} else if (path == "sync") {
189+
sync();
190+
}
191+
}
192+
193+
void RimeEngine::updateConfig() {
189194
factory_.unregister();
190195
if (api_) {
191196
try {
@@ -329,6 +334,20 @@ std::string RimeEngine::subMode(const InputMethodEntry &, InputContext &ic) {
329334
}
330335
return result;
331336
}
337+
338+
void RimeEngine::deploy() {
339+
instance_->inputContextManager().foreach([this](InputContext *ic) {
340+
auto state = this->state(ic);
341+
state->release();
342+
return true;
343+
});
344+
api_->sync_user_data();
345+
api_->finalize();
346+
rimeStart(true);
347+
}
348+
349+
void RimeEngine::sync() { api_->sync_user_data(); }
350+
332351
} // namespace fcitx
333352

334353
FCITX_ADDON_FACTORY(fcitx::RimeEngineFactory)

src/rimeengine.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ class RimeEngine final : public InputMethodEngine {
6363
void setConfig(const RawConfig &config) override {
6464
config_.load(config, true);
6565
safeSaveAsIni(config_, "conf/rime.conf");
66-
reloadConfig();
66+
updateConfig();
6767
}
68+
void setSubConfig(const std::string &path, const RawConfig &);
69+
void updateConfig();
6870

6971
std::string subMode(const InputMethodEntry &, InputContext &) override;
7072
const RimeEngineConfig &config() const { return config_; }
@@ -81,6 +83,9 @@ class RimeEngine final : public InputMethodEngine {
8183
const char *message_type,
8284
const char *message_value);
8385

86+
void deploy();
87+
void sync();
88+
8489
Instance *instance_;
8590
EventDispatcher eventDispatcher_;
8691
rime_api_t *api_;

src/rimestate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void RimeState::keyEvent(KeyEvent &event) {
6060
KeyStates{KeyState::Mod1, KeyState::CapsLock, KeyState::Shift,
6161
KeyState::Ctrl, KeyState::Super};
6262
if (states.test(KeyState::Super)) {
63-
states.unset(KeyState::Super);
6463
// IBus uses virtual super mask.
6564
states |= KeyState::Super2;
6665
}

0 commit comments

Comments
 (0)