diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml index c6412284..c7255f74 100644 --- a/src/android/AndroidManifest.xml +++ b/src/android/AndroidManifest.xml @@ -5,7 +5,7 @@ versionName="0.0.4"> - + diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/MainActivity.java index 3a59cabb..abebe38e 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/MainActivity.java @@ -53,7 +53,11 @@ public class MainActivity extends Activity { Log.w("tildefriends", e.toString()); } - ProcessBuilder builder = new ProcessBuilder(getFilesDir().toString() + "/tildefriends", "run", "-z", getPackageResourcePath().toString()); + ProcessBuilder builder = new ProcessBuilder( + getFilesDir().toString() + "/tildefriends", + "run", + "-z", + getPackageResourcePath().toString()); Log.w("tildefriends", "files = " + getFilesDir().toString()); builder.directory(getFilesDir()); builder.inheritIO(); @@ -83,8 +87,4 @@ public class MainActivity extends Activity { web.loadUrl("http://127.0.0.1:12345/~core/apps/"); } - - static { - System.loadLibrary("tildefriends"); - } } diff --git a/src/database.js.c b/src/database.js.c index 4feafe69..eaa69900 100644 --- a/src/database.js.c +++ b/src/database.js.c @@ -2,6 +2,8 @@ #include "log.h" #include "mem.h" +#include "ssb.h" +#include "task.h" #include #include @@ -31,7 +33,7 @@ static JSValue _database_get_all(JSContext* context, JSValueConst this_val, int static JSValue _database_get_like(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); static JSValue _databases_list(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv, int magic, JSValue* data); -void tf_database_register(JSContext* context, sqlite3* sqlite) +void tf_database_register(JSContext* context) { JS_NewClassID(&_database_class_id); JSClassDef def = @@ -45,13 +47,12 @@ void tf_database_register(JSContext* context, sqlite3* sqlite) } JSValue global = JS_GetGlobalObject(context); - JSValue data[] = { JS_NewInt64(context, (int64_t)(intptr_t)sqlite) }; - JSValue constructor = JS_NewCFunctionData(context, _database_create, 0, 0, 1, data); + JSValue constructor = JS_NewCFunctionData(context, _database_create, 0, 0, 0, NULL); JS_SetConstructorBit(context, constructor, true); JS_SetPropertyStr(context, global, "Database", constructor); JSValue databases = JS_NewObject(context); JS_SetPropertyStr(context, global, "databases", databases); - JS_SetPropertyStr(context, databases, "list", JS_NewCFunctionData(context, _databases_list, 0, 0, 1, data)); + JS_SetPropertyStr(context, databases, "list", JS_NewCFunctionData(context, _databases_list, 0, 0, 0, NULL)); JS_FreeValue(context, global); } @@ -60,9 +61,8 @@ static JSValue _database_create(JSContext* context, JSValueConst this_val, int a ++_database_count; JSValue object = JS_NewObjectClass(context, _database_class_id); - int64_t value = 0; - JS_ToInt64(context, &value, data[0]); - sqlite3* db = (sqlite3*)(intptr_t)value; + tf_task_t* task = tf_task_get(context); + sqlite3* db = tf_ssb_get_db(tf_task_get_ssb(task)); database_t* database = tf_malloc(sizeof(database_t)); *database = (database_t) @@ -105,7 +105,7 @@ static JSValue _database_get(JSContext* context, JSValueConst this_val, int argc if (database) { sqlite3_stmt* statement; - if (sqlite3_prepare(database->db, "SELECT value FROM properties WHERE id = $1 AND key = $2", -1, &statement, NULL) == SQLITE_OK) + if (sqlite3_prepare(database->db, "SELECT value FROM properties WHERE id = ? AND key = ?", -1, &statement, NULL) == SQLITE_OK) { size_t length; const char* keyString = JS_ToCStringLen(context, &length, argv[0]); @@ -278,9 +278,8 @@ JSValue _database_get_like(JSContext* context, JSValueConst this_val, int argc, static JSValue _databases_list(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv, int magic, JSValue* data) { - int64_t value = 0; - JS_ToInt64(context, &value, data[0]); - sqlite3* db = (sqlite3*)(intptr_t)value; + tf_task_t* task = tf_task_get(context); + sqlite3* db = tf_ssb_get_db(tf_task_get_ssb(task)); JSValue array = JS_UNDEFINED; sqlite3_stmt* statement; diff --git a/src/database.js.h b/src/database.js.h index 20f17c3e..800c3c2f 100644 --- a/src/database.js.h +++ b/src/database.js.h @@ -2,6 +2,4 @@ #include "quickjs.h" -typedef struct sqlite3 sqlite3; - -void tf_database_register(JSContext* context, sqlite3* sqlite); +void tf_database_register(JSContext* context); diff --git a/src/jnitest.c b/src/jnitest.c deleted file mode 100644 index 80d5b813..00000000 --- a/src/jnitest.c +++ /dev/null @@ -1,23 +0,0 @@ -#if defined(__ANDROID__) -#include "log.h" - -#include -#include - -void tf_android(const char* apk_path); - -JNIEXPORT void JNICALL Java_com_unprompted_tildefriends_MainActivity_setFilesPath(JNIEnv* env, jobject obj, jstring files_path, jstring apk_path) -{ - tf_printf("setFilesPath called.\n"); - const char* path_string = (*env)->GetStringUTFChars(env, files_path, NULL); - tf_printf("files_path = %s\n", path_string); - int result = chdir(path_string); - tf_printf("chdir %s => %d\n", path_string, result); - (*env)->ReleaseStringUTFChars(env, files_path, path_string); - - const char* apk_path_string = (*env)->GetStringUTFChars(env, apk_path, NULL); - tf_printf("apk = %s\n", apk_path_string); - tf_android(apk_path_string); - (*env)->ReleaseStringUTFChars(env, apk_path, apk_path_string); -} -#endif diff --git a/src/main.c b/src/main.c index b2112118..5b6df570 100644 --- a/src/main.c +++ b/src/main.c @@ -745,19 +745,3 @@ done: tf_mem_shutdown(); return result; } - -static void _tf_android_thread(void* user_data) -{ - char* apk_path = user_data; - char* args[] = { "tildefriends", "run", "-z", apk_path }; - main(_countof(args), args); - tf_free(apk_path); -} - -void tf_android(const char* apk_path) -{ - uv_thread_t thread_id = 0; - tf_printf("Starting a thread.\n"); - uv_thread_create(&thread_id, _tf_android_thread, tf_strdup(apk_path)); - tf_printf("Post-thread start.\n"); -} diff --git a/src/ssb.import.c b/src/ssb.import.c index b6e87889..b26d8648 100644 --- a/src/ssb.import.c +++ b/src/ssb.import.c @@ -352,7 +352,7 @@ void tf_ssb_import_from_zip(tf_ssb_t* ssb, const char* zip_path, const char* use unzFile zip = unzOpen(zip_path); if (zip) { - tf_printf("Importing from %s.", zip_path); + tf_printf("Importing from %s.\n", zip_path); if (unzGoToFirstFile(zip) == UNZ_OK) { while (unzGoToNextFile(zip) == UNZ_OK) diff --git a/src/task.c b/src/task.c index fdd16747..9a07457b 100644 --- a/src/task.c +++ b/src/task.c @@ -1584,44 +1584,11 @@ static void _tf_task_trace_to_parent(tf_trace_t* trace, const char* buffer, size tf_packetstream_send(tf_taskstub_get_stream(task->_parent), kTaskTrace, buffer, size); } -#if defined(__ANDROID__) -static void _tf_task_extract_file(tf_task_t* task, const char* name, int mode) -{ - size_t size = 0; - char path_in_zip[256]; - snprintf(path_in_zip, sizeof(path_in_zip), "lib/arm64-v8a/%s", name); - const char* exe_source = _task_loadFile(task, path_in_zip, &size); - if (exe_source) - { - FILE* exe_target = fopen(name, "wb"); - if (exe_target) - { - fwrite(exe_source, size, 1, exe_target); - fchmod(fileno(exe_target), mode); - fclose(exe_target); - } - else - { - tf_printf("failed to open %s for write", name); - } - tf_free((void*)exe_source); - } - else - { - tf_printf("failed to read %s source", path_in_zip); - } -} -#endif - void tf_task_activate(tf_task_t* task) { assert(!task->_activated); task->_activated = true; -#if defined(__ANDROID__) - _tf_task_extract_file(task, "tildefriends", 0755); -#endif - JSContext* context = task->_context; JSValue global = JS_GetGlobalObject(context); JSValue e = JS_NewObject(context); @@ -1679,7 +1646,7 @@ void tf_task_activate(tf_task_t* task) JS_SetPropertyStr(context, global, "Socket", tf_socket_register(context)); JS_SetPropertyStr(context, global, "TlsContext", tf_tls_context_register(context)); tf_file_register(context); - tf_database_register(context, task->_db); + tf_database_register(context); task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db_path); tf_ssb_set_trace(task->_ssb, task->_trace); diff --git a/src/taskstub.js.c b/src/taskstub.js.c index ec1c18a3..f44c6e50 100644 --- a/src/taskstub.js.c +++ b/src/taskstub.js.c @@ -45,10 +45,6 @@ void tf_taskstub_startup() JS_NewClassID(&_classId); size_t size = sizeof(_executable); uv_exepath(_executable, &size); -#if defined(__ANDROID__) - /* We have already changed into our files directory. */ - snprintf(_executable, sizeof(_executable), "./tildefriends"); -#endif tf_printf("exepath is %s\n", _executable); initialized = true; }