From 95487431e1034dcf33e018cac7d0fea69367ae2e Mon Sep 17 00:00:00 2001 From: Bambooin Date: Fri, 14 Jun 2024 15:37:28 +0800 Subject: [PATCH] chore: migrate to rime_get_api The deprecated librime 0.9 API function declarations will be move to a separeate header file rime_api_deprecated.h in rime/librime#877 --- app/src/main/jni/librime_jni/objconv.h | 2 +- app/src/main/jni/librime_jni/rime_jni.cc | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/jni/librime_jni/objconv.h b/app/src/main/jni/librime_jni/objconv.h index 22e147d294..9d98696f4d 100644 --- a/app/src/main/jni/librime_jni/objconv.h +++ b/app/src/main/jni/librime_jni/objconv.h @@ -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); } diff --git a/app/src/main/jni/librime_jni/rime_jni.cc b/app/src/main/jni/librime_jni/rime_jni.cc index ae2435f06f..da159b79ec 100644 --- a/app/src/main/jni/librime_jni/rime_jni.cc +++ b/app/src/main/jni/librime_jni/rime_jni.cc @@ -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; } @@ -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 @@ -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