mirror of
https://github.com/RoboSats/robosats.git
synced 2025-08-02 01:51:53 +00:00
Test robonames
This commit is contained in:
@ -11,17 +11,41 @@ interface AndroidAppRobosats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AndroidRobosats {
|
class AndroidRobosats {
|
||||||
private promises: Record<string, (value: string | PromiseLike<string>) => void> = {};
|
private promises: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
resolve: (value: string | PromiseLike<string>) => void;
|
||||||
|
reject: (reason?: string) => void;
|
||||||
|
}
|
||||||
|
> = {};
|
||||||
|
|
||||||
public storePromise: (
|
public storePromise: (
|
||||||
uuid: string,
|
uuid: string,
|
||||||
promise: (value: string | PromiseLike<string>) => void,
|
resolve: (value: string | PromiseLike<string>) => void,
|
||||||
) => void = (uuid, promise) => {
|
reject?: (reason?: string) => void,
|
||||||
this.promises[uuid] = promise;
|
) => void = (uuid, resolve, reject) => {
|
||||||
|
this.promises[uuid] = {
|
||||||
|
resolve,
|
||||||
|
reject: reject || ((error) => console.error('Promise rejected:', error)),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
public onResolvePromise: (uuid: string, response: string) => void = (uuid, respone) => {
|
public onResolvePromise: (uuid: string, response: string) => void = (uuid, response) => {
|
||||||
this.promises[uuid](respone);
|
if (this.promises[uuid]) {
|
||||||
|
this.promises[uuid].resolve(response);
|
||||||
|
delete this.promises[uuid]; // Clean up after resolving
|
||||||
|
} else {
|
||||||
|
console.warn(`No promise found for UUID: ${uuid}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public onRejectPromise: (uuid: string, error: string) => void = (uuid, error) => {
|
||||||
|
if (this.promises[uuid]) {
|
||||||
|
this.promises[uuid].reject(error);
|
||||||
|
delete this.promises[uuid]; // Clean up after rejecting
|
||||||
|
} else {
|
||||||
|
console.warn(`No promise found for UUID: ${uuid}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,15 +9,19 @@ class RoboidentitiesAndroidClient implements RoboidentitiesClient {
|
|||||||
if (this.robonames[initialString]) {
|
if (this.robonames[initialString]) {
|
||||||
return this.robonames[initialString];
|
return this.robonames[initialString];
|
||||||
} else {
|
} else {
|
||||||
const result = await new Promise<string>((resolve) => {
|
try {
|
||||||
const uuid: string = uuidv4();
|
const result = await new Promise<string>((resolve, reject) => {
|
||||||
window.AndroidAppRobosats?.generateRoboname(uuid, initialString);
|
const uuid: string = uuidv4();
|
||||||
window.AndroidRobosats?.storePromise(uuid, resolve);
|
window.AndroidAppRobosats?.generateRoboname(uuid, initialString);
|
||||||
});
|
window.AndroidRobosats?.storePromise(uuid, resolve, reject);
|
||||||
|
});
|
||||||
|
|
||||||
this.robonames[initialString] = result;
|
this.robonames[initialString] = result;
|
||||||
|
return result;
|
||||||
return result;
|
} catch (error) {
|
||||||
|
console.error('Error generating roboname:', error);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Packaging.() {
|
packaging {
|
||||||
jniLibs.useLegacyPackaging = true
|
jniLibs.useLegacyPackaging = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import android.os.Bundle
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.webkit.*
|
import android.webkit.*
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.koalasat.robosats.tor.WebAppInterface
|
import com.koalasat.robosats.WebAppInterface
|
||||||
import com.robosats.tor.TorKmp
|
import com.robosats.tor.TorKmp
|
||||||
import com.robosats.tor.TorKmpManager
|
import com.robosats.tor.TorKmpManager
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.koalasat.robosats
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
|
class RoboIdentities {
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "RoboIdentities"
|
||||||
|
private var librariesLoaded = false
|
||||||
|
|
||||||
|
init {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("robonames")
|
||||||
|
System.loadLibrary("robohash")
|
||||||
|
librariesLoaded = true
|
||||||
|
Log.d(TAG, "Native libraries loaded successfully")
|
||||||
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
|
Log.e(TAG, "Failed to load native libraries: ${e.message}", e)
|
||||||
|
librariesLoaded = false
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Unexpected error loading native libraries: ${e.message}", e)
|
||||||
|
librariesLoaded = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun areLibrariesLoaded(): Boolean {
|
||||||
|
return librariesLoaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateRoboname(initial_string: String?): String? {
|
||||||
|
return try {
|
||||||
|
if (!areLibrariesLoaded()) {
|
||||||
|
Log.e(TAG, "Cannot generate roboname: Native libraries not loaded")
|
||||||
|
"" }
|
||||||
|
nativeGenerateRoboname(initial_string)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error generating roboname: ${e.message}", e)
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateRobohash(initial_string: String?): String? {
|
||||||
|
return try {
|
||||||
|
if (!areLibrariesLoaded()) {
|
||||||
|
Log.e(TAG, "Cannot generate robohash: Native libraries not loaded")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
nativeGenerateRobohash(initial_string)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error generating robohash: ${e.message}", e)
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Native functions implemented in Rust.
|
||||||
|
private external fun nativeGenerateRoboname(initial_string: String?): String?
|
||||||
|
private external fun nativeGenerateRobohash(initial_string: String?): String?
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.koalasat.robosats
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import android.webkit.JavascriptInterface
|
||||||
|
import android.webkit.WebView
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
|
class WebAppInterface(private val context: Context, private val webView: WebView) {
|
||||||
|
private val TAG = "WebAppInterface"
|
||||||
|
private val roboIdentities = RoboIdentities()
|
||||||
|
|
||||||
|
init {
|
||||||
|
// Check if libraries are loaded and show a toast notification if there's an issue
|
||||||
|
if (!RoboIdentities.areLibrariesLoaded()) {
|
||||||
|
Log.w(TAG, "Native libraries for RoboIdentities are not loaded - fallback names will be used")
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"Warning: Robot name generator is using fallback mode",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun generateRoboname(uuid: String, message: String) {
|
||||||
|
try {
|
||||||
|
val roboname = roboIdentities.generateRoboname(message)
|
||||||
|
Log.d(TAG, "Generated roboname: $roboname for message: $message")
|
||||||
|
|
||||||
|
webView.post {
|
||||||
|
webView.evaluateJavascript("javascript:window.AndroidRobosats.onResolvePromise('${uuid}', '${roboname}')", null)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error in generateRoboname: ${e.message}", e)
|
||||||
|
|
||||||
|
// Handle error gracefully by returning a fallback value
|
||||||
|
webView.post {
|
||||||
|
webView.evaluateJavascript(
|
||||||
|
"javascript:window.AndroidRobosats.onRejectPromise('${uuid}', 'Error generating robot name')",
|
||||||
|
null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package com.koalasat.robosats.tor
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.webkit.JavascriptInterface
|
|
||||||
import android.webkit.WebView
|
|
||||||
import android.widget.Toast
|
|
||||||
|
|
||||||
class WebAppInterface(private val context: Context, private val webView: WebView) {
|
|
||||||
@JavascriptInterface
|
|
||||||
fun generateRoboname(uuid: String, message: String) {
|
|
||||||
// Handle the message received from JavaScript
|
|
||||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
|
||||||
|
|
||||||
webView.post {
|
|
||||||
webView.evaluateJavascript("javascript:window.AndroidRobosats.onResolvePromise('${uuid}', '${message}')", null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
BIN
mobile_new/app/src/main/jniLibs/arm64-v8a/librobohash.so
Executable file
BIN
mobile_new/app/src/main/jniLibs/arm64-v8a/librobohash.so
Executable file
Binary file not shown.
BIN
mobile_new/app/src/main/jniLibs/arm64-v8a/librobonames.so
Executable file
BIN
mobile_new/app/src/main/jniLibs/arm64-v8a/librobonames.so
Executable file
Binary file not shown.
BIN
mobile_new/app/src/main/jniLibs/armeabi-v7a/librobohash.so
Executable file
BIN
mobile_new/app/src/main/jniLibs/armeabi-v7a/librobohash.so
Executable file
Binary file not shown.
BIN
mobile_new/app/src/main/jniLibs/armeabi-v7a/librobonames.so
Executable file
BIN
mobile_new/app/src/main/jniLibs/armeabi-v7a/librobonames.so
Executable file
Binary file not shown.
BIN
mobile_new/app/src/main/jniLibs/x86_64/librobohash.so
Executable file
BIN
mobile_new/app/src/main/jniLibs/x86_64/librobohash.so
Executable file
Binary file not shown.
BIN
mobile_new/app/src/main/jniLibs/x86_64/librobonames.so
Executable file
BIN
mobile_new/app/src/main/jniLibs/x86_64/librobonames.so
Executable file
Binary file not shown.
Reference in New Issue
Block a user