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

+44
View File
@@ -0,0 +1,44 @@
package rest
import (
"encoding/json"
"net/url"
goapi "github.com/GopeedLab/gopeed/pkg/api"
"github.com/GopeedLab/gopeed/pkg/rest/model"
)
const (
TaskEventDone = uint64(goapi.TaskEventDone)
TaskEventError = uint64(goapi.TaskEventError)
)
// Invoke dispatches a Core API request without using an HTTP listener. It is
// the shared entry point for Desktop FFI and gomobile bindings.
func Invoke(method, path, rawQuery, body string) string {
service := APIService
if service == nil {
return marshalInvokeResult(model.NewErrorResult("service not started"))
}
query, err := url.ParseQuery(rawQuery)
if err != nil {
return marshalInvokeResult(model.NewErrorResult(err.Error()))
}
_, data := service.JSON(method, path, query, []byte(body), nil)
return string(data)
}
func SubscribeTaskEvents(mask uint64, listener func(payload string)) {
if APIService == nil {
return
}
APIService.SubscribeTaskEvents(goapi.TaskEventMask(mask), listener)
}
func marshalInvokeResult(value any) string {
data, err := json.Marshal(value)
if err != nil {
return `{"code":1000,"msg":"marshal response failed"}`
}
return string(data)
}