Skip to content

Commit

Permalink
chore: migrate to rime_get_api
Browse files Browse the repository at this point in the history
The deprecated librime 0.9 API function declarations will be move to a
separeate header file rime_api_deprecated.h in rime/librime#877
  • Loading branch information
Bambooin committed Jun 14, 2024
1 parent 9e7ae97 commit 9548743
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/src/main/jni/librime_jni/objconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inline jobject rimeConfigListToJObject(JNIEnv *env, RimeConfig *config,
auto obj =
env->NewObject(GlobalRef->ArrayList, GlobalRef->ArrayListInit, size);
int i = 0;
while (RimeConfigNext(&iter)) {
while (rime->config_next(&iter)) {
auto e = JRef<>(env, rimeConfigValueToJObject(env, config, iter.path));
env->CallVoidMethod(obj, GlobalRef->ArrayListAdd, i++, *e);
}
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/jni/librime_jni/rime_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,25 @@ Java_com_osfans_trime_core_Rime_getRimeStatus(JNIEnv *env, jclass /* thiz */) {
}

static bool is_save_option(const char *p) {
auto rime = rime_get_api();
bool is_save = false;
std::string option_name(p);
if (option_name.empty()) return is_save;
RimeConfig config = {nullptr};
bool b = RimeConfigOpen("default", &config);
bool b = rime->config_open("default", &config);
if (!b) return is_save;
const char *key = "switcher/save_options";
RimeConfigIterator iter = {nullptr};
RimeConfigBeginList(&iter, &config, key);
while (RimeConfigNext(&iter)) {
std::string item(RimeConfigGetCString(&config, iter.path));
rime->config_begin_list(&iter, &config, key);
while (rime->config_next(&iter)) {
std::string item(rime->config_get_cstring(&config, iter.path));
if (option_name == item) {
is_save = true;
break;
}
}
RimeConfigEnd(&iter);
RimeConfigClose(&config);
rime->config_end(&iter);
rime->config_close(&config);
return is_save;
}

Expand Down Expand Up @@ -439,16 +440,17 @@ Java_com_osfans_trime_core_Rime_getRimeConfigMap(JNIEnv *env, jclass clazz,
extern "C" JNIEXPORT jboolean JNICALL
Java_com_osfans_trime_core_Rime_runRimeTask(JNIEnv *env, jclass /* thiz */,
jstring task_name) {
auto rime = rime_get_api();
const char *s = env->GetStringUTFChars(task_name, nullptr);
RimeConfig config = {nullptr};
Bool b = RimeRunTask(s);
Bool b = rime->run_task(s);
env->ReleaseStringUTFChars(task_name, s);
return b;
}
extern "C" JNIEXPORT jstring JNICALL
Java_com_osfans_trime_core_Rime_getRimeSharedDataDir(JNIEnv *env,
jclass /* thiz */) {
return env->NewStringUTF(RimeGetSharedDataDir());
return env->NewStringUTF(rime_get_api()->get_shared_data_dir());
}

extern "C" JNIEXPORT jstring JNICALL
Expand All @@ -459,12 +461,12 @@ Java_com_osfans_trime_core_Rime_getRimeUserDataDir(JNIEnv *env,

extern "C" JNIEXPORT jstring JNICALL
Java_com_osfans_trime_core_Rime_getRimeSyncDir(JNIEnv *env, jclass /* thiz */) {
return env->NewStringUTF(RimeGetSyncDir());
return env->NewStringUTF(rime_get_api()->get_sync_dir());
}

extern "C" JNIEXPORT jstring JNICALL
Java_com_osfans_trime_core_Rime_getRimeUserId(JNIEnv *env, jclass /* thiz */) {
return env->NewStringUTF(RimeGetUserId());
return env->NewStringUTF(rime_get_api()->get_user_id());
}

extern "C" JNIEXPORT jstring JNICALL
Expand Down

0 comments on commit 9548743

Please sign in to comment.