Use user provided xdg runtime directory

This commit is contained in:
Wisest_wizard 2021-08-16 08:51:31 +05:30 committed by Wisest_wizard
parent 7446d74d28
commit c131fec2da
2 changed files with 34 additions and 5 deletions

View File

@ -179,9 +179,31 @@ static LorieBackendAndroid* fromLong(jlong v) {
return u.b; return u.b;
} }
jstring spname(JNIEnv *env) {
return env->NewStringUTF("sharedstore");
}
extern "C" JNIEXPORT jlong JNICALL extern "C" JNIEXPORT jlong JNICALL
JNI_DECLARE(LorieService, createLorieThread)(JNIEnv __unused *env, jobject __unused instance) { JNI_DECLARE(LorieService, createLorieThread)(JNIEnv *env, jobject __unused instance) {
setenv("XDG_RUNTIME_DIR", "/data/data/com.termux/files/usr/tmp", 1);
jclass spcls = env->FindClass("android/content/SharedPreferences");
jclass contextcls = env->FindClass("android/content/Context");
mainClass = env->NewGlobalRef(activity);
jmethodID mid = env->GetMethodID(contextcls, "getSharedPreferences",
"(Ljava/lang/String;I)Landroid/content/SharedPreferences;");
jmethodID midstring = env->GetMethodID(spcls, "getSring",
"(Ljava/lang/String;Z)Z");
jobject jobjectshared = env->CallObjectMethod(mainClass, mid, spname(env), 0);
jstring xdgcustpath = env->CallStringMethod(jobjectshared, mistring, objectname(env), "/data/data/com.termux/files/usr/tmp");
const char *pathxdg = env->GetStringUTFChars(xdgcustpath, 0);
env->ReleaseStringUTFChars(xdgcustpath, pathxdg);
setenv("XDG_RUNTIME_DIR", pathxdg, 1);
return (jlong) new LorieBackendAndroid; return (jlong) new LorieBackendAndroid;
} }

View File

@ -36,4 +36,11 @@
android:key="PIP" android:key="PIP"
android:summary="Show app in picture-in-picture mode when home button or recents button is pressed" /> android:summary="Show app in picture-in-picture mode when home button or recents button is pressed" />
<EditTextPreference
android:title="Custom XDG_RUNTIME_DIR"
android:defaultValue="/data/data/com.termux/files/usr/tmp"
android:key="CustXDG"
android:summary="Set the XDG runtime directory for wayland sockets"
android:dialogMessage="Please be careful here as setting the wrong directory may make the app not run as expected" />
</PreferenceScreen> </PreferenceScreen>