mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 01:20:27 +00:00
feat: move native communication to FFI (#1457)
This commit is contained in:
86 files changed
+4558
-886
No files matched your search
@@ -4,6 +4,7 @@ package libgopeed
|
||||
import "C"
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/GopeedLab/gopeed/internal/webview/rpcprovider"
|
||||
"github.com/GopeedLab/gopeed/pkg/rest"
|
||||
"github.com/GopeedLab/gopeed/pkg/rest/model"
|
||||
@@ -15,6 +16,7 @@ func Start(cfg string) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
config.ProductionMode = true
|
||||
config.NativeMode = true
|
||||
applyWebViewProvider(&config)
|
||||
return rest.Start(&config)
|
||||
}
|
||||
@@ -23,6 +25,47 @@ func Stop() {
|
||||
rest.Stop()
|
||||
}
|
||||
|
||||
func GetAPIServerState() string {
|
||||
return apiServerResult(rest.GetAPIServerState())
|
||||
}
|
||||
|
||||
func StartAPIServer() string {
|
||||
return apiServerResult(rest.StartAPIServer())
|
||||
}
|
||||
|
||||
func StopAPIServer() string {
|
||||
return apiServerResult(rest.StopAPIServer())
|
||||
}
|
||||
|
||||
func RestartAPIServer() string {
|
||||
return apiServerResult(rest.RestartAPIServer())
|
||||
}
|
||||
|
||||
func apiServerResult(state *model.APIServerState, err error) string {
|
||||
result := &model.APIServerOperationResult{State: state}
|
||||
if err != nil {
|
||||
result.Error = err.Error()
|
||||
}
|
||||
data, _ := json.Marshal(result)
|
||||
return string(data)
|
||||
}
|
||||
|
||||
func Invoke(method, path, query, body string) string {
|
||||
return rest.Invoke(method, path, query, body)
|
||||
}
|
||||
|
||||
type TaskEventListener interface {
|
||||
OnTaskEvent(payload string)
|
||||
}
|
||||
|
||||
func SubscribeTaskEvents(mask int64, listener TaskEventListener) {
|
||||
if mask == 0 || listener == nil {
|
||||
rest.SubscribeTaskEvents(0, nil)
|
||||
return
|
||||
}
|
||||
rest.SubscribeTaskEvents(uint64(mask), listener.OnTaskEvent)
|
||||
}
|
||||
|
||||
func applyWebViewProvider(config *model.StartConfig) {
|
||||
if config == nil || config.WebViewRPCConfig == nil || !config.WebViewRPCConfig.Enabled() {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user