Skip to content

Commit

Permalink
fix: avoid potential deployment failure
Browse files Browse the repository at this point in the history
The original native deploy method doesn't pass the shared data dir and user data dir again to Rime engine, which may make the engine cannot "see" the configurations.
  • Loading branch information
WhiredPlanck authored and Bambooin committed Mar 14, 2023
1 parent f3299ef commit bb81f3e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
13 changes: 8 additions & 5 deletions app/src/main/java/com/osfans/trime/core/Rime.java
Expand Up @@ -196,7 +196,7 @@ public static String getComposingText() {
}

public Rime(boolean full_check) {
init(full_check);
startup(full_check);
self = this;
}

Expand All @@ -213,7 +213,7 @@ private static boolean getStatus() {
return getRimeStatus(mStatus);
}

private static void init(boolean full_check) {
private static void startup(boolean full_check) {
isHandlingRimeNotification = false;

DataManager.sync();
Expand All @@ -223,10 +223,13 @@ private static void init(boolean full_check) {
Timber.i("Starting up Rime APIs ...");
startupRime(sharedDataDir, userDataDir, full_check);

Timber.i("Initializing schema stuffs ...");
Timber.i("Updating schema switchers ...");
initSchema();
}

Timber.i("Finishing startup");
public static void deploy() {
exitRime();
startup(true);
}

public static String getCommitText() {
Expand Down Expand Up @@ -385,7 +388,7 @@ public static void handleRimeNotification(
public static native void startupRime(
@NonNull String sharedDir, @NonNull String userDir, boolean fullCheck);

public static native void deployRime();
public static native void exitRime();

public static native boolean deployRimeSchemaFile(@NonNull String schemaFile);

Expand Down
Expand Up @@ -40,13 +40,13 @@ class IntentReceiver : BroadcastReceiver(), CoroutineScope by MainScope() {
when (command) {
COMMAND_DEPLOY -> launch {
withContext(Dispatchers.Default) {
Rime.deployRime()
Rime.deploy()
}
ToastUtils.showLong(R.string.deploy_finish)
}
COMMAND_SYNC -> async {
Rime.syncRimeUserData()
Rime.deployRime()
Rime.deploy()
}
else -> return
}
Expand Down
Expand Up @@ -56,7 +56,7 @@ class ProfileFragment : PaddingPreferenceFragment() {
lifecycleScope.withLoadingDialog(context, 200L, R.string.sync_progress) {
withContext(Dispatchers.IO) {
Rime.syncRimeUserData()
Rime.deployRime()
Rime.deploy()
}
}
true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ui/main/Pickers.kt
Expand Up @@ -101,7 +101,7 @@ fun Context.schemaPicker(
loading.show()
}
withContext(Dispatchers.Default) {
Rime.deployRime()
Rime.deploy()
job.cancelAndJoin()
if (loading.isShowing) {
loading.dismiss()
Expand Down
Expand Up @@ -122,7 +122,7 @@ class PrefMainActivity : AppCompatActivity() {
Runtime.getRuntime().exec(arrayOf("logcat", "-c"))
}
withContext(Dispatchers.Default) {
Rime.deployRime()
Rime.deploy()
}
briefResultLogDialog("rime.trime", "W", 1)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt
Expand Up @@ -124,7 +124,7 @@ object ShortcutUtils {
fun syncInBackground() {
val prefs = AppPrefs.defaultInstance()
prefs.profile.lastBackgroundSync = Date().time.toString()
prefs.profile.lastSyncStatus = Rime.syncRimeUserData().also { Rime.deployRime() }
prefs.profile.lastSyncStatus = Rime.syncRimeUserData().also { Rime.deploy() }
}

fun openCategory(keyCode: Int): Boolean {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/jni/librime_jni/rime_jni.cc
Expand Up @@ -118,11 +118,10 @@ class Rime {
return rime->delete_candidate_on_current_page(session, index);
}

void deploy() {
void exit() {
rime->destroy_session(session);
session = 0;
rime->finalize();
startup(true);
}

bool sync() {
Expand Down Expand Up @@ -173,13 +172,14 @@ Java_com_osfans_trime_core_Rime_startupRime(JNIEnv *env, jclass clazz, jstring s
Rime::Instance().startup(full_check);
}

// deployment
extern "C"
JNIEXPORT void JNICALL
Java_com_osfans_trime_core_Rime_deployRime(JNIEnv *env, jclass /* thiz */) {
Rime::Instance().deploy();
Java_com_osfans_trime_core_Rime_exitRime(JNIEnv *env, jclass /* thiz */) {
RETURN_IF_NOT_RUNNING
Rime::Instance().exit();
}

// deployment
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_osfans_trime_core_Rime_deployRimeSchemaFile(JNIEnv *env, jclass /* thiz */, jstring schema_file) {
Expand Down

0 comments on commit bb81f3e

Please sign in to comment.