Merge branch 'master' into github-master
commit
52cdc4a3df
|
@ -1,3 +1,5 @@
|
||||||
|
## 0.6.0
|
||||||
|
增加api接口
|
||||||
## 0.5.0
|
## 0.5.0
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
支持小程序最新依赖
|
支持小程序最新依赖
|
||||||
|
|
|
@ -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'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@ 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();
|
||||||
|
|
||||||
|
@ -29,24 +31,22 @@ public class MopPlugin implements MethodCallHandler {
|
||||||
private MopPluginDelegate delegate;
|
private MopPluginDelegate delegate;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin registration.
|
* Plugin registration.
|
||||||
*/
|
*/
|
||||||
public static void registerWith(Registrar registrar) {
|
public static void registerWith(Registrar registrar) {
|
||||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
|
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
|
||||||
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
|
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
|
||||||
final MopPlugin instance = new MopPlugin(registrar,delegate);
|
final MopPlugin instance = new MopPlugin(registrar, delegate);
|
||||||
channel.setMethodCallHandler(instance);
|
channel.setMethodCallHandler(instance);
|
||||||
final EventChannel eventChannel=new EventChannel(registrar.messenger(),"plugins.mop.finogeeks.com/mop_event");
|
final EventChannel eventChannel = new EventChannel(registrar.messenger(), "plugins.mop.finogeeks.com/mop_event");
|
||||||
MopEventStream mopEventStream = new MopEventStream();
|
MopEventStream mopEventStream = new MopEventStream();
|
||||||
eventChannel.setStreamHandler(mopEventStream);
|
eventChannel.setStreamHandler(mopEventStream);
|
||||||
MopPluginService.getInstance().initialize(registrar.activity(),mopEventStream);
|
MopPluginService.getInstance().initialize(registrar.activity(), mopEventStream, channel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MopPlugin(PluginRegistry.Registrar registrar,MopPluginDelegate delegate) {
|
MopPlugin(PluginRegistry.Registrar registrar, MopPluginDelegate delegate) {
|
||||||
this.registrar = registrar;
|
this.registrar = registrar;
|
||||||
this.flutterInterface = new FlutterInterface();
|
this.flutterInterface = new FlutterInterface();
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
@ -58,20 +58,20 @@ public class MopPlugin implements MethodCallHandler {
|
||||||
ICallback callback = new ICallback<Object>() {
|
ICallback callback = new ICallback<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object data) {
|
public void onSuccess(Object data) {
|
||||||
Map<String,Object> obj = new HashMap<String,Object>();
|
Map<String, Object> obj = new HashMap<String, Object>();
|
||||||
|
|
||||||
obj.put("success",true);
|
obj.put("success", true);
|
||||||
if (data != null)
|
if (data != null)
|
||||||
obj.put("data",data);
|
obj.put("data", data);
|
||||||
obj.put("retMsg","ok");
|
obj.put("retMsg", "ok");
|
||||||
result.success(obj);
|
result.success(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFail(Object error) {
|
public void onFail(Object error) {
|
||||||
Map<String,Object> obj = new HashMap<String,Object>();
|
Map<String, Object> obj = new HashMap<String, Object>();
|
||||||
obj.put("success",false);
|
obj.put("success", false);
|
||||||
obj.put("retMsg",error==null?"":error);
|
obj.put("retMsg", error == null ? "" : error);
|
||||||
result.success(obj);
|
result.success(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ public class MopPlugin implements MethodCallHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Log.d(LOG_TAG,"mopplugin: invoke " + call.method);
|
Log.d(LOG_TAG, "mopplugin: invoke " + call.method);
|
||||||
Event event= new Event(call.method,call.arguments,callback);
|
Event event = new Event(call.method, call.arguments, callback);
|
||||||
delegate.setEvent(event);
|
delegate.setEvent(event);
|
||||||
this.flutterInterface.invokeHandler(event);
|
this.flutterInterface.invokeHandler(event);
|
||||||
// if (call.method.equals("getPlatformVersion")) {
|
// if (call.method.equals("getPlatformVersion")) {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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(@{});
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||||
|
|
|
@ -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]];
|
FlutterEventChannel *mopEventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.mop.finogeeks.com/mop_event" binaryMessenger:[registrar messenger]];
|
||||||
instance.mopEventStreamHandler = [[MopEventStream alloc] init];
|
_instance.mopEventStreamHandler = [[MopEventStream alloc] init];
|
||||||
[mopEventChannel setStreamHandler:instance.mopEventStreamHandler];
|
[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]]);
|
||||||
|
|
|
@ -17,6 +17,6 @@ A new flutter plugin project.
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
90
lib/mop.dart
90
lib/mop.dart
|
@ -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});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue