mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-15 12:53:41 +00:00
feat: move native communication to FFI (#1457)
This commit is contained in:
86 files changed
+4558
-886
No files matched your search
@@ -19,6 +19,7 @@ import UIKit
|
||||
name: "gopeed.com/libgopeed",
|
||||
binaryMessenger: messenger
|
||||
)
|
||||
let taskEventForwarder = GopeedTaskEventForwarder(channel: libgopeedChannel)
|
||||
libgopeedChannel.setMethodCallHandler { call, result in
|
||||
switch call.method {
|
||||
case "start":
|
||||
@@ -41,6 +42,26 @@ import UIKit
|
||||
case "stop":
|
||||
LibgopeedStop()
|
||||
result(nil)
|
||||
case "getApiServerState":
|
||||
result(LibgopeedGetAPIServerState())
|
||||
case "startApiServer":
|
||||
result(LibgopeedStartAPIServer())
|
||||
case "stopApiServer":
|
||||
result(LibgopeedStopAPIServer())
|
||||
case "restartApiServer":
|
||||
result(LibgopeedRestartAPIServer())
|
||||
case "invoke":
|
||||
let arguments = call.arguments as? [String: Any]
|
||||
let method = arguments?["method"] as? String ?? ""
|
||||
let path = arguments?["path"] as? String ?? ""
|
||||
let query = arguments?["query"] as? String ?? ""
|
||||
let body = arguments?["body"] as? String ?? ""
|
||||
result(LibgopeedInvoke(method, path, query, body))
|
||||
case "subscribeTaskEvents":
|
||||
let arguments = call.arguments as? [String: Any]
|
||||
let mask = (arguments?["mask"] as? NSNumber)?.int64Value ?? 0
|
||||
GopeedSubscribeTaskEventsWithForwarder(mask, mask == 0 ? nil : taskEventForwarder)
|
||||
result(nil)
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface GopeedTaskEventForwarder : NSObject
|
||||
|
||||
- (instancetype)initWithChannel:(FlutterMethodChannel *)channel NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
@end
|
||||
|
||||
FOUNDATION_EXPORT void GopeedSubscribeTaskEventsWithForwarder(
|
||||
int64_t mask,
|
||||
GopeedTaskEventForwarder * _Nullable listener);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,35 @@
|
||||
#import "GopeedTaskEventForwarder.h"
|
||||
|
||||
#import <Libgopeed/Libgopeed.h>
|
||||
|
||||
@interface GopeedTaskEventForwarder () <LibgopeedTaskEventListener>
|
||||
|
||||
@property(nonatomic, strong) FlutterMethodChannel *channel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GopeedTaskEventForwarder
|
||||
|
||||
- (instancetype)initWithChannel:(FlutterMethodChannel *)channel {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_channel = channel;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)onTaskEvent:(NSString * _Nullable)payload {
|
||||
NSString *arguments = payload ?: @"";
|
||||
FlutterMethodChannel *channel = self.channel;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[channel invokeMethod:@"taskEvent" arguments:arguments];
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void GopeedSubscribeTaskEventsWithForwarder(
|
||||
int64_t mask,
|
||||
GopeedTaskEventForwarder * _Nullable listener) {
|
||||
LibgopeedSubscribeTaskEvents(mask, listener);
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
#import "GopeedTaskEventForwarder.h"
|
||||
Reference in new issue
Block a user