feat: move native communication to FFI (#1457)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 20:18:42 +08:00
1 parent 177c225f16
commit 39cd9034cd
86 files changed
+4558 -886

No files matched your search

@@ -1,6 +1,7 @@
package com.gopeed.gopeed
import com.gopeed.libgopeed.Libgopeed
import com.gopeed.libgopeed.TaskEventListener
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
@@ -12,12 +13,13 @@ class MainActivity : FlutterActivity() {
val taskQueue =
flutterEngine.dartExecutor.binaryMessenger.makeBackgroundTaskQueue()
MethodChannel(
val libgopeedChannel = MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
LIBGOPEED_CHANNEL,
StandardMethodCodec.INSTANCE,
taskQueue,
).setMethodCallHandler { call, result ->
)
libgopeedChannel.setMethodCallHandler { call, result ->
when (call.method) {
"start" -> {
try {
@@ -30,6 +32,42 @@ class MainActivity : FlutterActivity() {
Libgopeed.stop()
result.success(null)
}
"getApiServerState" -> result.success(Libgopeed.getAPIServerState())
"startApiServer" -> result.success(Libgopeed.startAPIServer())
"stopApiServer" -> result.success(Libgopeed.stopAPIServer())
"restartApiServer" -> result.success(Libgopeed.restartAPIServer())
"invoke" -> {
try {
result.success(
Libgopeed.invoke(
call.argument<String>("method") ?: "",
call.argument<String>("path") ?: "",
call.argument<String>("query") ?: "",
call.argument<String>("body") ?: "",
),
)
} catch (error: Exception) {
result.error("ERROR", error.message, null)
}
}
"subscribeTaskEvents" -> {
val mask = call.argument<Number>("mask")?.toLong() ?: 0L
if (mask == 0L) {
Libgopeed.subscribeTaskEvents(0L, null)
} else {
Libgopeed.subscribeTaskEvents(
mask,
object : TaskEventListener {
override fun onTaskEvent(payload: String?) {
runOnUiThread {
libgopeedChannel.invokeMethod("taskEvent", payload ?: "")
}
}
},
)
}
result.success(null)
}
else -> result.notImplemented()
}
}