refactor: share async invoke bridge across native platforms

This commit is contained in:
Levi committed 2026-09-06 11:59:11 +08:00
1 parent d12122ea86
commit 607d1729e6
17 files changed
+464 -222

No files matched your search

+22 -3
View File
@@ -5,6 +5,7 @@ import "C"
import (
"encoding/json"
nativebridge "github.com/GopeedLab/gopeed/bind/native"
"github.com/GopeedLab/gopeed/internal/webview/rpcprovider"
"github.com/GopeedLab/gopeed/pkg/rest"
"github.com/GopeedLab/gopeed/pkg/rest/model"
@@ -18,10 +19,15 @@ func Start(cfg string) (int, error) {
config.ProductionMode = true
config.NativeMode = true
applyWebViewProvider(&config)
return rest.Start(&config)
port, err := rest.Start(&config)
if err == nil {
nativebridge.ResumeInvokes()
}
return port, err
}
func Stop() {
nativebridge.PauseInvokesAndWait()
rest.Stop()
}
@@ -50,8 +56,21 @@ func apiServerResult(state *model.APIServerState, err error) string {
return string(data)
}
func Invoke(method, path, query, body string) string {
return rest.Invoke(method, path, query, body)
type InvokeResultListener interface {
OnResult(requestID int64, success bool, payload string)
}
func InvokeAsync(method, path, query, body string, requestID int64, listener InvokeResultListener) {
if listener == nil {
return
}
nativebridge.InvokeAsync(method, path, query, body, func(result string, err error) {
if err != nil {
listener.OnResult(requestID, false, err.Error())
return
}
listener.OnResult(requestID, true, result)
})
}
type TaskEventListener interface {