2020-04-26 14:57:08 +08:00
|
|
|
//
|
|
|
|
// MOPAppletDelegate.m
|
|
|
|
// mop
|
|
|
|
//
|
|
|
|
// Created by 康旭耀 on 2020/4/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MOPAppletDelegate.h"
|
|
|
|
#import "MopPlugin.h"
|
2021-02-26 13:41:45 +08:00
|
|
|
#import "MopCustomMenuModel.h"
|
2020-04-26 14:57:08 +08:00
|
|
|
|
|
|
|
@implementation MOPAppletDelegate
|
|
|
|
|
2020-04-27 18:55:36 +08:00
|
|
|
+ (instancetype)instance
|
|
|
|
{
|
|
|
|
static MOPAppletDelegate *_instance;
|
|
|
|
static dispatch_once_t once;
|
|
|
|
dispatch_once(&once, ^{
|
|
|
|
_instance = [[self alloc] init];
|
|
|
|
});
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
2020-04-26 14:57:08 +08:00
|
|
|
- (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion
|
|
|
|
{
|
2020-12-10 17:53:10 +08:00
|
|
|
NSLog(@"forwardAppletWithInfo1:%@",contentInfo);
|
2020-04-26 14:57:08 +08:00
|
|
|
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
2020-04-27 18:55:36 +08:00
|
|
|
[channel invokeMethod:@"extensionApi:forwardApplet" arguments:@{@"appletInfo":contentInfo} result:^(id _Nullable result) {
|
2020-04-26 14:57:08 +08:00
|
|
|
if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ])
|
|
|
|
{
|
|
|
|
completion(FATExtensionCodeFailure,nil);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
completion(FATExtensionCodeSuccess,result);
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)getUserInfoWithAppletInfo:(FATAppletInfo *)appletInfo
|
|
|
|
{
|
|
|
|
NSLog(@"getUserInfoWithAppletInfo");
|
|
|
|
__block NSDictionary *userInfo;
|
|
|
|
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
2021-03-03 22:59:09 +08:00
|
|
|
[channel invokeMethod:@"extensionApi:getUserInfo" arguments:nil result:^(id _Nullable result) {
|
|
|
|
CFRunLoopStop(CFRunLoopGetMain());
|
|
|
|
userInfo = result;
|
2020-04-26 14:57:08 +08:00
|
|
|
}];
|
2021-03-03 22:59:09 +08:00
|
|
|
CFRunLoopRun();
|
2020-04-26 14:57:08 +08:00
|
|
|
return userInfo;
|
|
|
|
}
|
|
|
|
|
2021-02-26 13:41:45 +08:00
|
|
|
- (NSArray<id<FATAppletMenuProtocol>> *)customMenusInApplet:(FATAppletInfo *)appletInfo atPath:(NSString *)path {
|
2021-03-03 22:59:09 +08:00
|
|
|
NSLog(@"customMenusInApplet");
|
|
|
|
__block NSArray *list;
|
|
|
|
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
|
|
|
[channel invokeMethod:@"extensionApi:getCustomMenus" arguments:@{@"appId": appletInfo.appId} result:^(id _Nullable result) {
|
|
|
|
CFRunLoopStop(CFRunLoopGetMain());
|
|
|
|
list = result;
|
|
|
|
}];
|
|
|
|
CFRunLoopRun();
|
2021-02-26 13:41:45 +08:00
|
|
|
|
2021-03-03 22:59:09 +08:00
|
|
|
NSMutableArray *models = [NSMutableArray array];
|
|
|
|
for (NSDictionary<NSString *, NSString *> *data in list) {
|
|
|
|
MopCustomMenuModel *model = [[MopCustomMenuModel alloc] init];
|
|
|
|
model.menuId = data[@"menuId"];
|
|
|
|
model.menuTitle = data[@"title"];
|
|
|
|
model.menuIconImage = [UIImage imageNamed:data[@"image"]];
|
|
|
|
NSString *typeString = data[@"type"];
|
|
|
|
if (typeString) {
|
|
|
|
FATAppletMenuStyle style = [typeString isEqualToString:@"onMiniProgram"] ? FATAppletMenuStyleOnMiniProgram : FATAppletMenuStyleCommon;
|
|
|
|
model.menuType = style;
|
|
|
|
}
|
|
|
|
[models addObject:model];
|
|
|
|
}
|
2021-02-26 13:41:45 +08:00
|
|
|
|
2021-03-03 22:59:09 +08:00
|
|
|
return models;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)customMenu:(id<FATAppletMenuProtocol>)customMenu inApplet:(FATAppletInfo *)appletInfo didClickAtPath:(NSString *)path {
|
|
|
|
NSDictionary *arguments = @{
|
|
|
|
@"appId": appletInfo.appId,
|
|
|
|
@"path": path,
|
|
|
|
@"menuId": customMenu.menuId,
|
|
|
|
@"appInfo": appletInfo.description
|
|
|
|
};
|
|
|
|
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
|
|
|
[channel invokeMethod:@"extensionApi:onCustomMenuClick" arguments:arguments result:^(id _Nullable result) {
|
|
|
|
|
|
|
|
}];
|
2020-04-26 14:57:08 +08:00
|
|
|
}
|
|
|
|
|
2021-02-26 13:41:45 +08:00
|
|
|
- (void)clickCustomItemMenuWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode code, NSDictionary *result))completion {
|
2021-03-03 22:59:09 +08:00
|
|
|
NSDictionary *arguments = @{
|
|
|
|
@"appId": contentInfo[@"appId"],
|
|
|
|
@"path": contentInfo[@"path"],
|
|
|
|
@"menuId": contentInfo[@"menuId"],
|
|
|
|
@"appInfo": [NSString stringWithFormat:@"{'title': '%@', 'description': '%@', 'imageUrl': '%@'}", contentInfo[@"title"], contentInfo[@"description"], contentInfo[@"imageUrl"]]
|
|
|
|
};
|
|
|
|
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
|
|
|
|
[channel invokeMethod:@"extensionApi:onCustomMenuClick" arguments:arguments result:^(id _Nullable result) {
|
|
|
|
|
|
|
|
}];
|
2020-04-26 14:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|