Merge branch 'master' into github-master

master
kangxuyao 2020-04-26 14:58:33 +08:00
commit 52cdc4a3df
32 changed files with 842 additions and 93 deletions

View File

@ -1,3 +1,5 @@
## 0.6.0
api
## 0.5.0 ## 0.5.0
## 0.4.0 ## 0.4.0

View File

@ -12,6 +12,13 @@ buildscript {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {
url "https://gradle.finogeeks.club/repository/finogeeks/"
credentials {
username "gradle"
password "ftjk@@123321"
}
}
maven { maven {
url "https://gradle.finogeeks.club/repository/applet/" url "https://gradle.finogeeks.club/repository/applet/"
credentials { credentials {
@ -34,6 +41,13 @@ rootProject.allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {
url "https://gradle.finogeeks.club/repository/finogeeks/"
credentials {
username "gradle"
password "ftjk@@123321"
}
}
maven { maven {
url "https://gradle.finogeeks.club/repository/applet/" url "https://gradle.finogeeks.club/repository/applet/"
credentials { credentials {
@ -77,6 +91,6 @@ kapt {
} }
dependencies { dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.finogeeks.lib:finapplet:+' implementation 'com.finogeeks.lib:finapplet:2.1.17'
} }

View File

@ -19,81 +19,81 @@ import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.PluginRegistry.Registrar;
/** MopPlugin */ /**
* MopPlugin
*/
public class MopPlugin implements MethodCallHandler { public class MopPlugin implements MethodCallHandler {
private static final String LOG_TAG = MopPlugin.class.getSimpleName(); private static final String LOG_TAG = MopPlugin.class.getSimpleName();
private static final String CHANNEL = "mop"; private static final String CHANNEL = "mop";
private PluginRegistry.Registrar registrar; private PluginRegistry.Registrar registrar;
private FlutterInterface flutterInterface; private FlutterInterface flutterInterface;
private MopPluginDelegate delegate; private MopPluginDelegate delegate;
/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
final MopPlugin instance = new MopPlugin(registrar, delegate);
channel.setMethodCallHandler(instance);
final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugins.mop.finogeeks.com/mop_event");
MopEventStream mopEventStream = new MopEventStream();
eventChannel.setStreamHandler(mopEventStream);
MopPluginService.getInstance().initialize(registrar.activity(), mopEventStream, channel);
}
/** MopPlugin(PluginRegistry.Registrar registrar, MopPluginDelegate delegate) {
* Plugin registration. this.registrar = registrar;
*/ this.flutterInterface = new FlutterInterface();
public static void registerWith(Registrar registrar) { this.delegate = delegate;
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL); }
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
final MopPlugin instance = new MopPlugin(registrar,delegate);
channel.setMethodCallHandler(instance);
final EventChannel eventChannel=new EventChannel(registrar.messenger(),"plugins.mop.finogeeks.com/mop_event");
MopEventStream mopEventStream = new MopEventStream();
eventChannel.setStreamHandler(mopEventStream);
MopPluginService.getInstance().initialize(registrar.activity(),mopEventStream);
} @Override
public void onMethodCall(MethodCall call, final Result result) {
registrar.addActivityResultListener(delegate);
ICallback callback = new ICallback<Object>() {
@Override
public void onSuccess(Object data) {
Map<String, Object> obj = new HashMap<String, Object>();
MopPlugin(PluginRegistry.Registrar registrar,MopPluginDelegate delegate) { obj.put("success", true);
this.registrar = registrar; if (data != null)
this.flutterInterface = new FlutterInterface(); obj.put("data", data);
this.delegate = delegate; obj.put("retMsg", "ok");
} result.success(obj);
}
@Override @Override
public void onMethodCall(MethodCall call, final Result result) { public void onFail(Object error) {
registrar.addActivityResultListener(delegate); Map<String, Object> obj = new HashMap<String, Object>();
ICallback callback = new ICallback<Object>() { obj.put("success", false);
@Override obj.put("retMsg", error == null ? "" : error);
public void onSuccess(Object data) { result.success(obj);
Map<String,Object> obj = new HashMap<String,Object>(); }
obj.put("success",true); @Override
if (data != null) public void onCancel(Object cancel) {
obj.put("data",data); result.notImplemented();
obj.put("retMsg","ok"); }
result.success(obj);
}
@Override @Override
public void onFail(Object error) { public void startActivityForResult(Intent intent, int requestCode) {
Map<String,Object> obj = new HashMap<String,Object>();
obj.put("success",false);
obj.put("retMsg",error==null?"":error);
result.success(obj);
}
@Override }
public void onCancel(Object cancel) { };
result.notImplemented(); Log.d(LOG_TAG, "mopplugin: invoke " + call.method);
} Event event = new Event(call.method, call.arguments, callback);
delegate.setEvent(event);
@Override this.flutterInterface.invokeHandler(event);
public void startActivityForResult(Intent intent, int requestCode) {
}
};
Log.d(LOG_TAG,"mopplugin: invoke " + call.method);
Event event= new Event(call.method,call.arguments,callback);
delegate.setEvent(event);
this.flutterInterface.invokeHandler(event);
// if (call.method.equals("getPlatformVersion")) { // if (call.method.equals("getPlatformVersion")) {
// result.success("Android " + android.os.Build.VERSION.RELEASE); // result.success("Android " + android.os.Build.VERSION.RELEASE);
// } else { // } else {
// result.notImplemented(); // result.notImplemented();
// } // }
} }
} }

View File

@ -3,8 +3,11 @@ package com.finogeeks.mop.api;
import android.app.Activity; import android.app.Activity;
import android.text.TextUtils; import android.text.TextUtils;
import com.finogeeks.mop.api.mop.AppletHandlerModule;
import com.finogeeks.mop.api.mop.AppletManageModule;
import com.finogeeks.mop.api.mop.AppletModule; import com.finogeeks.mop.api.mop.AppletModule;
import com.finogeeks.mop.api.mop.BaseModule; import com.finogeeks.mop.api.mop.BaseModule;
import com.finogeeks.mop.api.mop.ExtensionApiModule;
import com.finogeeks.mop.interfaces.Event; import com.finogeeks.mop.interfaces.Event;
import com.finogeeks.mop.interfaces.IApi; import com.finogeeks.mop.interfaces.IApi;
@ -29,6 +32,7 @@ public class ApisManager {
mActivity = activity; mActivity = activity;
initSdkApi(activity); initSdkApi(activity);
} }
/** /**
* api * api
* *
@ -42,6 +46,7 @@ public class ApisManager {
return null; return null;
} }
/** /**
* api * api
* *
@ -59,7 +64,9 @@ public class ApisManager {
private void initSdkApi(Activity activity) { private void initSdkApi(Activity activity) {
add(new BaseModule(activity)); add(new BaseModule(activity));
add(new AppletModule(activity)); add(new AppletModule(activity));
add(new AppletManageModule(activity));
add(new AppletHandlerModule(activity));
add(new ExtensionApiModule(activity));
} }
private void add(IApi api) { private void add(IApi api) {

View File

@ -0,0 +1,160 @@
package com.finogeeks.mop.api.mop;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.finogeeks.lib.applet.client.FinAppClient;
import com.finogeeks.lib.applet.page.view.moremenu.MoreMenuItem;
import com.finogeeks.lib.applet.sdk.api.IAppletHandler;
import com.finogeeks.mop.api.BaseApi;
import com.finogeeks.mop.interfaces.ICallback;
import com.finogeeks.mop.service.MopPluginService;
import com.finogeeks.mop.utils.GsonUtil;
import com.google.gson.reflect.TypeToken;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import io.flutter.plugin.common.MethodChannel;
public class AppletHandlerModule extends BaseApi {
private Handler handler = new Handler(Looper.getMainLooper());
public AppletHandlerModule(Context context) {
super(context);
}
@Override
public String[] apis() {
return new String[]{"registerAppletHandler"};
}
@Override
public void invoke(String event, Map param, ICallback callback) {
Log.d("AppletHandlerModule", "registerAppletHandler");
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
FinAppClient.INSTANCE.getAppletApiManager().setAppletHandler(new IAppletHandler() {
@Override
public void shareAppMessage(@NotNull String s, @Nullable Bitmap bitmap, @NotNull IAppletCallback iAppletCallback) {
Log.d("MopPlugin", "shareAppMessage:" + s);
Map<String, Object> params = new HashMap<>();
params.put("appletInfo", GsonUtil.gson.fromJson(s, new TypeToken<Map<String, Object>>() {
}.getType()));
handler.post(() -> {
channel.invokeMethod("extensionApi:forwardApplet", params, new MethodChannel.Result() {
@Override
public void success(Object result) {
iAppletCallback.onSuccess(null);
}
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
iAppletCallback.onFailure();
}
@Override
public void notImplemented() {
iAppletCallback.onFailure();
}
});
});
}
@Nullable
@Override
public Map<String, String> getUserInfo() {
Log.d("AppletHandlerModule", "getUserInfo");
CountDownLatch latch = new CountDownLatch(1);
final Map<String, String>[] ret = new Map[1];
handler.post(() -> {
channel.invokeMethod("extensionApi:getUserInfo", null, new MethodChannel.Result() {
@Override
public void success(Object result) {
ret[0] = (Map<String, String>) result;
latch.countDown();
}
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
latch.countDown();
}
@Override
public void notImplemented() {
latch.countDown();
}
});
});
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (ret[0].size() > 0)
return ret[0];
else
return null;
}
@Nullable
@Override
public List<MoreMenuItem> getRegisteredMoreMenuItems(@NotNull String s) {
CountDownLatch latch = new CountDownLatch(1);
List<MoreMenuItem> moreMenuItems = new ArrayList<>();
Map<String, Object> params = new HashMap<>();
params.put("appId", s);
handler.post(() -> {
channel.invokeMethod("extensionApi:getCustomMenus", params, new MethodChannel.Result() {
@Override
public void success(Object result) {
List<Map<String, Object>> ret = (List<Map<String, Object>>) result;
if (ret != null) {
for (Map<String, Object> map : ret) {
moreMenuItems.add(new MoreMenuItem((Integer) map.get("menuId"), 0, (String) map.get("title"), true));
}
}
latch.countDown();
}
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
latch.countDown();
}
@Override
public void notImplemented() {
latch.countDown();
}
});
});
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return moreMenuItems;
}
@Override
public void onRegisteredMoreMenuItemClicked(@NotNull String s, int i) {
Map<String, Object> params = new HashMap<>();
params.put("appId", s);
params.put("menuId", i);
handler.post(() -> {
channel.invokeMethod("extensionApi:onCustomMenuClick", params);
});
}
});
callback.onSuccess(null);
}
}

View File

@ -0,0 +1,54 @@
package com.finogeeks.mop.api.mop;
import android.content.Context;
import com.finogeeks.lib.applet.client.FinAppClient;
import com.finogeeks.lib.applet.db.entity.FinApplet;
import com.finogeeks.mop.api.BaseApi;
import com.finogeeks.mop.interfaces.ICallback;
import java.util.HashMap;
import java.util.Map;
public class AppletManageModule extends BaseApi {
public AppletManageModule(Context context) {
super(context);
}
@Override
public String[] apis() {
return new String[]{"currentApplet", "closeAllApplets", "clearApplets"};
}
@Override
public void invoke(String event, Map param, ICallback callback) {
if (event.equals("currentApplet")) {
String appId = FinAppClient.INSTANCE.getAppletApiManager().getCurrentAppletId();
if (appId != null) {
FinApplet applet = FinAppClient.INSTANCE.getAppletApiManager().getUsedApplet(appId);
if (applet != null) {
Map<String, Object> res = new HashMap<>();
res.put("appId", applet.getId());
res.put("name", applet.getName());
res.put("icon", applet.getIcon());
res.put("description", applet.getDescription());
res.put("version", applet.getVersion());
res.put("thumbnail", applet.getThumbnail());
callback.onSuccess(res);
} else {
callback.onSuccess(null);
}
} else {
callback.onSuccess(null);
}
} else if (event.equals("closeAllApplets")) {
FinAppClient.INSTANCE.finishAllRunningApplets();
callback.onSuccess(null);
} else if (event.equals("clearApplets")) {
FinAppClient.INSTANCE.getAppletApiManager().clearApplets();
callback.onSuccess(null);
}
}
}

View File

@ -50,6 +50,7 @@ public class AppletModule extends BaseApi {
FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, sequence, null); FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, sequence, null);
} }
} else { } else {
Log.d("MopPlugin", "openApplet:params:" + param);
FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, params); FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, params);
} }
callback.onSuccess(new HashMap()); callback.onSuccess(new HashMap());

View File

@ -0,0 +1,80 @@
package com.finogeeks.mop.api.mop;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.finogeeks.lib.applet.client.FinAppClient;
import com.finogeeks.mop.api.BaseApi;
import com.finogeeks.mop.interfaces.ICallback;
import com.finogeeks.mop.service.MopPluginService;
import com.finogeeks.mop.utils.GsonUtil;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
public class ExtensionApiModule extends BaseApi {
private Handler handler = new Handler(Looper.getMainLooper());
public ExtensionApiModule(Context context) {
super(context);
}
@Override
public String[] apis() {
return new String[]{"registerExtensionApi"};
}
@Override
public void invoke(String s, Map param, ICallback iCallback) {
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
String name = (String) param.get("name");
FinAppClient.INSTANCE.getExtensionApiManager().registerApi(new com.finogeeks.lib.applet.api.BaseApi(getContext()) {
@Override
public String[] apis() {
return new String[]{name};
}
@Override
public void invoke(String s, JSONObject jsonObject, com.finogeeks.lib.applet.interfaces.ICallback iCallback) {
Log.d("MopPlugin", "invoke extensionApi:" + s + ",params:" + jsonObject);
Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class);
handler.post(() -> {
channel.invokeMethod("extensionApi:" + name, params, new MethodChannel.Result() {
@Override
public void success(Object result) {
String json = GsonUtil.gson.toJson(result);
JSONObject ret = null;
if (json != null && !json.equals("null"))
try {
ret = new JSONObject(json);
} catch (JSONException e) {
e.printStackTrace();
}
iCallback.onSuccess(ret);
}
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
iCallback.onFail();
}
@Override
public void notImplemented() {
iCallback.onFail();
}
});
});
}
});
}
}

View File

@ -1,12 +1,13 @@
package com.finogeeks.mop.service; package com.finogeeks.mop.service;
import android.app.Activity; import android.app.Activity;
import android.app.Application;
import android.content.Context; import android.content.Context;
import com.finogeeks.mop.MopEventStream; import com.finogeeks.mop.MopEventStream;
import com.finogeeks.mop.api.ApisManager; import com.finogeeks.mop.api.ApisManager;
import io.flutter.plugin.common.MethodChannel;
public class MopPluginService { public class MopPluginService {
private final static String TAG = MopPluginService.class.getSimpleName(); private final static String TAG = MopPluginService.class.getSimpleName();
private static volatile MopPluginService _instance = null; private static volatile MopPluginService _instance = null;
@ -17,6 +18,7 @@ public class MopPluginService {
private Context mContext; private Context mContext;
private Activity mActivity; private Activity mActivity;
private MethodChannel mMethodChannel;
MopPluginService() { MopPluginService() {
} }
@ -32,20 +34,33 @@ public class MopPluginService {
return _instance; return _instance;
} }
public ApisManager getApisManager() { return this.apisManager;} public ApisManager getApisManager() {
public MopEventStream getMopEventStream() {return this.mopEventStream;} return this.apisManager;
public void initialize(Activity activity, MopEventStream mopEventStream) { }
public MopEventStream getMopEventStream() {
return this.mopEventStream;
}
public void initialize(Activity activity, MopEventStream mopEventStream, MethodChannel methodChannel) {
this.mopEventStream = mopEventStream; this.mopEventStream = mopEventStream;
this.mContext = activity.getApplicationContext(); this.mContext = activity.getApplicationContext();
this.apisManager = new ApisManager(activity); this.apisManager = new ApisManager(activity);
this.mActivity = activity; this.mActivity = activity;
this.mMethodChannel = methodChannel;
} }
public Context getContext() { public Context getContext() {
return mContext; return mContext;
} }
public Activity getActivity() { public Activity getActivity() {
return mActivity; return mActivity;
} }
public MethodChannel getMethodChannel() {
return mMethodChannel;
}
} }

View File

@ -0,0 +1,19 @@
package com.finogeeks.mop.utils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.Map;
public class GsonUtil {
public static Gson gson = new Gson();
public static Map<String, Object> toMap(Object object) {
String str = gson.toJson(object);
if (str != null) {
return gson.fromJson(str, new TypeToken<Map<String, Object>>() {
}.getType());
}
return null;
}
}

View File

@ -1,8 +1,8 @@
PODS: PODS:
- FinApplet (2.0.196) - FinApplet (2.1.5)
- Flutter (1.0.0) - Flutter (1.0.0)
- mop (0.1.0): - mop (0.1.0):
- FinApplet - FinApplet (= 2.1.5)
- Flutter - Flutter
DEPENDENCIES: DEPENDENCIES:
@ -20,9 +20,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/mop/ios" :path: ".symlinks/plugins/mop/ios"
SPEC CHECKSUMS: SPEC CHECKSUMS:
FinApplet: 629fb114471bb68eea3aace7fd9c28a7ce6326f8 FinApplet: adb43373a01ff90832969b1534d40c08344063f6
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
mop: e3eac9de90d3e331268e9c9e8308e233e540ad1c mop: c0e0dfb65c6a482e47f0fffc9a6576d88e7636b5
PODFILE CHECKSUM: b66559db98de00d11e349a06f9e603856ed75d6e PODFILE CHECKSUM: b66559db98de00d11e349a06f9e603856ed75d6e

View File

@ -101,7 +101,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.4.0" version: "0.6.0"
path: path:
dependency: transitive dependency: transitive
description: description:

View File

@ -0,0 +1,17 @@
//
// MOPAppletDelegate.h
// mop
//
// Created by 耀 on 2020/4/20.
//
#import <Foundation/Foundation.h>
#import <FinApplet/FinApplet.h>
NS_ASSUME_NONNULL_BEGIN
@interface MOPAppletDelegate : NSObject<FATAppletDelegate>
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,53 @@
//
// MOPAppletDelegate.m
// mop
//
// Created by 耀 on 2020/4/20.
//
#import "MOPAppletDelegate.h"
#import "MopPlugin.h"
@implementation MOPAppletDelegate
- (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion
{
NSLog(@"forwardAppletWithInfo:%@",contentInfo);
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
[channel invokeMethod:@"extensionApi:forwardApplet" arguments:contentInfo result:^(id _Nullable result) {
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];
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
[channel invokeMethod:@"extensionApi:getUserInfo" arguments:nil result:^(id _Nullable result) {
userInfo = result;
dispatch_group_leave(group);
}];
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
return userInfo;
}
- (NSArray<id<FATAppletMenuProtocol>> *)customMenusInMoreItemAtPath:(NSString *)path
{
return nil;
}
- (void)customMenu:(id<FATAppletMenuProtocol>)customMenu didClickAtPath:(NSString *)path
{
}
@end

View File

@ -0,0 +1,16 @@
//
// MOP_clearApplets.h
// mop
//
// Created by 耀 on 2020/4/16.
//
#import "MOPBaseApi.h"
NS_ASSUME_NONNULL_BEGIN
@interface MOP_clearApplets : MOPBaseApi
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,21 @@
//
// MOP_clearApplets.m
// mop
//
// Created by 耀 on 2020/4/16.
//
#import "MOP_clearApplets.h"
#import <FinApplet/FinApplet.h>
@implementation MOP_clearApplets
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{
NSLog(@"clearApplets");
[[FATClient sharedClient]clearMemoryCache];
[[FATClient sharedClient]clearLocalApplets];
success(@{});
}
@end

View File

@ -0,0 +1,16 @@
//
// MOP_closeAllApplets.h
// mop
//
// Created by 耀 on 2020/4/16.
//
#import "MOPBaseApi.h"
NS_ASSUME_NONNULL_BEGIN
@interface MOP_closeAllApplets : MOPBaseApi
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,20 @@
//
// MOP_closeAllApplets.m
// mop
//
// Created by 耀 on 2020/4/16.
//
#import "MOP_closeAllApplets.h"
#import <FinApplet/FinApplet.h>
@implementation MOP_closeAllApplets
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{
NSLog(@"closeAllApplets");
[[FATClient sharedClient] closeAllApplets];
success(@{});
}
@end

View File

@ -0,0 +1,16 @@
//
// MOP_currentApplet.h
// mop
//
// Created by 耀 on 2020/4/16.
//
#import "MOPBaseApi.h"
NS_ASSUME_NONNULL_BEGIN
@interface MOP_currentApplet : MOPBaseApi
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,35 @@
//
// MOP_currentApplet.m
// mop
//
// Created by 耀 on 2020/4/16.
//
#import "MOP_currentApplet.h"
#import <FinApplet/FinApplet.h>
@implementation MOP_currentApplet
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{
FATAppletInfo *info = [[FATClient sharedClient] currentApplet];
if(info != nil)
{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
dic[@"appId"] = info.appId;
dic[@"name"]= info.appTitle;
dic[@"icon"]= info.appAvatar;
dic[@"description"]=info.appDescription;
dic[@"version"] = info.appVersion;
dic[@"thumbnail"]=info.appThumbnail;
success(dic);
}
else
{
success(@{});
}
}
@end

View File

@ -26,7 +26,7 @@
} }
}]; }];
}else{ }else{
[[FATClient sharedClient] startRemoteApplet:self.appId sequence:self.sequence startParams:self.params InParentViewController:currentVC transitionStyle:FATTranstionStylePush completion:^(BOOL result, NSError *error) { [[FATClient sharedClient] startRemoteApplet:self.appId sequence:self.sequence startParams:self.params InParentViewController:currentVC transitionStyle:FATTranstionStyleUp completion:^(BOOL result, NSError *error) {
NSLog(@"result:%d---error:%@", result, error); NSLog(@"result:%d---error:%@", result, error);
if (result){ if (result){
success(@{}); success(@{});

View File

@ -0,0 +1,16 @@
//
// MOP_registerAppletHandler.h
// mop
//
// Created by 耀 on 2020/4/20.
//
#import "MOPBaseApi.h"
NS_ASSUME_NONNULL_BEGIN
@interface MOP_registerAppletHandler : MOPBaseApi
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,22 @@
//
// MOP_registerAppletHandler.m
// mop
//
// Created by 耀 on 2020/4/20.
//
#import "MOP_registerAppletHandler.h"
#import "MopPlugin.h"
#import "MOPAppletDelegate.h"
#import <FinApplet/FinApplet.h>
@implementation MOP_registerAppletHandler
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{
NSLog(@"MOP_registerAppletHandler");
[[FATClient sharedClient] setDelegate:[[MOPAppletDelegate alloc] init]];
}
@end

View File

@ -0,0 +1,18 @@
//
// MOP_registerExtensionApi.h
// mop
//
// Created by 耀 on 2020/4/20.
//
#import "MOPBaseApi.h"
NS_ASSUME_NONNULL_BEGIN
@interface MOP_registerExtensionApi : MOPBaseApi
@property NSString* name;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,36 @@
//
// MOP_registerExtensionApi.m
// mop
//
// Created by 耀 on 2020/4/20.
//
#import "MOP_registerExtensionApi.h"
#import "MopPlugin.h"
#import <FinApplet/FinApplet.h>
@implementation MOP_registerExtensionApi
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{
NSLog(@"MOP_registerExtensionApi");
FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel];
[[FATClient sharedClient] registerExtensionApi:self.name handle:^(id param, FATExtensionApiCallback callback) {
NSLog(@"invoke ExtensionApi:");
NSLog(@"%@",self.name);
NSLog(@"%@",param);
NSString* api = [@"extensionApi:" stringByAppendingString:self.name];
[channel invokeMethod:api arguments:param result:^(id _Nullable result) {
if([result isKindOfClass:[FlutterError class]]|| [result isKindOfClass:[FlutterMethodNotImplemented class] ])
{
callback(FATExtensionCodeFailure,nil);
}else
{
callback(FATExtensionCodeSuccess,result);
}
}];
}];
success(@{});
}
@end

View File

@ -6,5 +6,7 @@
@interface MopPlugin : NSObject <FlutterPlugin> @interface MopPlugin : NSObject <FlutterPlugin>
@property MopEventStream *mopEventStreamHandler; @property MopEventStream *mopEventStreamHandler;
@property FlutterMethodChannel *methodChannel;
+ (instancetype) instance;
@end @end

View File

@ -27,20 +27,27 @@
@implementation MopPlugin @implementation MopPlugin
static MopPlugin *_instance;
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"mop" methodChannelWithName:@"mop"
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
MopPlugin* instance = [[MopPlugin alloc] init]; _instance = [[MopPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel]; [registrar addMethodCallDelegate:_instance channel:channel];
_instance.methodChannel = channel;
FlutterEventChannel *mopEventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.mop.finogeeks.com/mop_event" binaryMessenger:[registrar messenger]];
instance.mopEventStreamHandler = [[MopEventStream alloc] init];
[mopEventChannel setStreamHandler:instance.mopEventStreamHandler];
FlutterEventChannel *mopEventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.mop.finogeeks.com/mop_event" binaryMessenger:[registrar messenger]];
_instance.mopEventStreamHandler = [[MopEventStream alloc] init];
[mopEventChannel setStreamHandler:_instance.mopEventStreamHandler];
} }
+ (instancetype)instance{
return _instance;
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) { if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);

View File

@ -16,7 +16,7 @@ A new flutter plugin project.
s.public_header_files = 'Classes/**/*.h' s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter' s.dependency 'Flutter'
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.dependency 'FinApplet' s.dependency 'FinApplet', '2.1.14'
end end

33
lib/api.dart 100644
View File

@ -0,0 +1,33 @@
class CustomMenu {
int menuId;
String image;
String title;
Map<String, dynamic> toJson() =>
{"menuId": menuId, "image": image, "title": title};
}
abstract class AppletHandler {
///
///
///
///
///
void forwardApplet(Map<String, dynamic> appletInfo);
///
///
/// "userId"
/// "nickName"
/// "avatarUrl"
/// "jwt"
/// "accessToken"
///
Future<Map<String, dynamic>> getUserInfo();
///
Future<List<CustomMenu>> getCustomMenus(String appId);
///
Future onCustomMenuClick(String appId, int menuId);
}

View File

@ -1,10 +1,14 @@
import 'dart:async'; import 'dart:async';
import 'dart:math';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:mop/api.dart';
typedef MopEventCallback = void Function(dynamic event); typedef MopEventCallback = void Function(dynamic event);
typedef MopEventErrorCallback = void Function(dynamic event); typedef MopEventErrorCallback = void Function(dynamic event);
typedef ExtensionApiHandler = Future Function(dynamic params);
class Mop { class Mop {
static final Mop _instance = new Mop._internal(); static final Mop _instance = new Mop._internal();
MethodChannel _channel; MethodChannel _channel;
@ -12,6 +16,8 @@ class Mop {
int eventId = 0; int eventId = 0;
List<Map<String, dynamic>> _mopEventQueye = <Map<String, dynamic>>[]; List<Map<String, dynamic>> _mopEventQueye = <Map<String, dynamic>>[];
Map<String, ExtensionApiHandler> _extensionApis = {};
factory Mop() { factory Mop() {
return _instance; return _instance;
} }
@ -20,6 +26,7 @@ class Mop {
print('mop: _internal'); print('mop: _internal');
// init // init
_channel = new MethodChannel('mop'); _channel = new MethodChannel('mop');
_channel.setMethodCallHandler(_handlePlatformMethodCall);
_mopEventChannel = new EventChannel('plugins.mop.finogeeks.com/mop_event'); _mopEventChannel = new EventChannel('plugins.mop.finogeeks.com/mop_event');
_mopEventChannel.receiveBroadcastStream().listen((dynamic value) { _mopEventChannel.receiveBroadcastStream().listen((dynamic value) {
print('matrix: receiveBroadcastStream $value'); print('matrix: receiveBroadcastStream $value');
@ -40,6 +47,17 @@ class Mop {
return version; return version;
} }
Future<dynamic> _handlePlatformMethodCall(MethodCall call) async {
print("_handlePlatformMethodCall: method:${call.method}");
if (call.method.startsWith("extensionApi:")) {
final name = call.method.substring("extensionApi:".length);
final handler = _extensionApis[name];
if (handler != null) {
return await handler(call.arguments);
}
}
}
/// ///
/// ///
/// initialize mop miniprogram engine. /// initialize mop miniprogram engine.
@ -72,17 +90,71 @@ class Mop {
/// ///
Future<Map> openApplet(final String appId, Future<Map> openApplet(final String appId,
{final String path, final String query, final int sequence}) async { {final String path, final String query, final int sequence}) async {
Map<String, Object> params; Map<String, Object> params = {'appId': appId};
if (path != '') { Map param = {};
params = { if (path != null) param["path"] = path;
'appId': appId, if (query != null) param["query"] = query;
'params': {'path': path, 'query': query} if (param.length > 0) params["params"] = param;
};
} else {
params = {'appId': appId};
}
if (sequence != null) params["sequence"] = sequence; if (sequence != null) params["sequence"] = sequence;
final Map ret = await _channel.invokeMethod('openApplet', params); final Map ret = await _channel.invokeMethod('openApplet', params);
return ret; return ret;
} }
///
/// get current using applet
/// 使
/// {appId,name,icon,description,version,thumbnail}
///
///
Future<Map<String, dynamic>> currentApplet() async {
final ret = await _channel.invokeMapMethod("currentApplet");
return Map<String, dynamic>.from(ret);
}
///
/// close all running applets
///
///
Future closeAllApplets() async {
return await _channel.invokeMethod("closeAllApplets");
}
///
/// clear applets cache
///
///
Future clearApplets() async {
return await _channel.invokeMethod("clearApplets");
}
///
/// register handler to provide custom info or behaviour
///
///
void registerAppletHandler(AppletHandler handler) {
_extensionApis["forwardApplet"] = (params) async {
handler.forwardApplet(Map<String, dynamic>.from(params["appletInfo"]));
};
_extensionApis["getUserInfo"] = (params) {
return handler.getUserInfo();
};
_extensionApis["getCustomMenus"] = (params) async {
final res = await handler.getCustomMenus(params["appId"]);
res?.map((e) => e.toJson());
return res;
};
_extensionApis["onCustomMenuClick"] = (params) {
return handler.onCustomMenuClick(params["appId"], params["menuId"]);
};
_channel.invokeMethod("registerAppletHandler");
}
///
/// register extension api
/// api
///
void registerExtensionApi(String name, ExtensionApiHandler handler) {
_extensionApis[name] = handler;
_channel.invokeMethod("registerExtensionApi", {"name": name});
}
} }

0
publish.sh 100644 → 100755
View File

View File

@ -1,9 +1,6 @@
name: mop name: mop
description: A Finogeeks MiniProgram Flutter SDK. description: A Finogeeks MiniProgram Flutter SDK.
version: 0.5.0 version: 0.6.0
authors:
- finogeeks <finogeeks.mop@gmail.com>
- kang34814 <kang34814@gmail.com>
homepage: https://github.com/finogeeks/mop-flutter-sdk homepage: https://github.com/finogeeks/mop-flutter-sdk
environment: environment: