Skip to content

Commit e34584c

Browse files
committed
refactor: remove user config accesses when select schema or set option
librime does those works itself now.
1 parent 718d09d commit e34584c

File tree

1 file changed

+2
-45
lines changed

1 file changed

+2
-45
lines changed

app/src/main/jni/librime_jni/rime_jni.cc

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -293,44 +293,10 @@ Java_com_osfans_trime_core_Rime_getRimeStatus(JNIEnv *env, jclass /* thiz */) {
293293
return obj;
294294
}
295295

296-
static bool is_save_option(const char *p) {
297-
auto rime = rime_get_api();
298-
bool is_save = false;
299-
std::string option_name(p);
300-
if (option_name.empty()) return is_save;
301-
RimeConfig config = {nullptr};
302-
bool b = rime->config_open("default", &config);
303-
if (!b) return is_save;
304-
const char *key = "switcher/save_options";
305-
RimeConfigIterator iter = {nullptr};
306-
rime->config_begin_list(&iter, &config, key);
307-
while (rime->config_next(&iter)) {
308-
std::string item(rime->config_get_cstring(&config, iter.path));
309-
if (option_name == item) {
310-
is_save = true;
311-
break;
312-
}
313-
}
314-
rime->config_end(&iter);
315-
rime->config_close(&config);
316-
return is_save;
317-
}
318-
319296
// runtime options
320297
extern "C" JNIEXPORT void JNICALL Java_com_osfans_trime_core_Rime_setRimeOption(
321298
JNIEnv *env, jclass /* thiz */, jstring option, jboolean value) {
322-
auto rime = rime_get_api();
323-
RimeConfig user = {nullptr};
324-
auto opt = CString(env, option);
325-
bool b;
326-
if (is_save_option(opt)) {
327-
if (rime->user_config_open("user", &user)) {
328-
std::string key = "var/option/" + std::string(opt);
329-
rime->config_set_bool(&user, key.c_str(), value);
330-
rime->config_close(&user);
331-
}
332-
}
333-
Rime::Instance().setOption(opt, value);
299+
Rime::Instance().setOption(CString(env, option), value);
334300
}
335301

336302
extern "C" JNIEXPORT jboolean JNICALL
@@ -354,16 +320,7 @@ Java_com_osfans_trime_core_Rime_getCurrentRimeSchema(JNIEnv *env,
354320
extern "C" JNIEXPORT jboolean JNICALL
355321
Java_com_osfans_trime_core_Rime_selectRimeSchema(JNIEnv *env, jclass /* thiz */,
356322
jstring schema_id) {
357-
auto rime = rime_get_api();
358-
RimeConfig user = {nullptr};
359-
auto schema = CString(env, schema_id);
360-
if (rime->user_config_open("user", &user)) {
361-
rime->config_set_string(&user, "var/previously_selected_schema", schema);
362-
std::string key = "var/schema_access_time/" + std::string(schema);
363-
rime->config_set_int(&user, key.c_str(), time(nullptr));
364-
rime->config_close(&user);
365-
}
366-
return Rime::Instance().selectSchema(schema);
323+
return Rime::Instance().selectSchema(CString(env, schema_id));
367324
}
368325

369326
// testing

0 commit comments

Comments
 (0)