diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java index c9e23fa..a37c969 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java @@ -11,6 +11,8 @@ import com.finogeeks.lib.applet.anim.SlideFromRightToLeftAnim; import com.finogeeks.lib.applet.anim.SlideFromTopToBottomAnim; import com.finogeeks.lib.applet.client.FinAppClient; import com.finogeeks.lib.applet.client.FinAppInfo; +import com.finogeeks.lib.applet.client.FinAppProcessClient; +import com.finogeeks.lib.applet.db.entity.FinApplet; import com.finogeeks.lib.applet.interfaces.FinCallback; import com.finogeeks.lib.applet.rest.model.WechatLoginInfo; import com.finogeeks.mop.api.BaseApi; @@ -54,6 +56,7 @@ public class AppletManageModule extends BaseApi { res.put("version", appletInfo.getAppVersion()); res.put("thumbnail", appletInfo.getAppThumbnail()); res.put("appletType", appletInfo.getAppType()); + res.put("isSingleProcess", FinAppProcessClient.INSTANCE.getAppletProcessActivity(applet.getId()) != null); Map wechatLoginInfo = new HashMap<>(4); WechatLoginInfo wechatLogin = appletInfo.getWechatLoginInfo(); if (wechatLogin != null) { diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java index d14d97c..9091047 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java @@ -63,23 +63,31 @@ public class AppletModule extends BaseApi { Integer sequence = (Integer) param.get("sequence"); Map params = (Map) param.get("params"); String apiServer = (String) param.get("apiServer"); + Boolean isSingleProcess = (Boolean) param.get("isSingleProcess"); // mContext是FlutterActivity, // 在Android 6.0、7.0系统的部分设备中热启动小程序时,如果context参数用mContext,会出现无法启动小程序的问题 // 所以这里使用Application Context Context context = mContext.getApplicationContext(); FinAppInfo.StartParams startParams = params == null ? null : new FinAppInfo.StartParams(params.get("path"), params.get("query"), params.get("scene")); - Log.d(TAG, "openApplet:" + appId + "," + param + "," + sequence + "," + apiServer); + Log.d(TAG, "openApplet:" + appId + "," + param + "," + sequence + "," + apiServer + ", isSingleProcess:" + isSingleProcess); if (apiServer != null) { FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, IFinAppletRequest.Companion.fromAppId(apiServer, appId) .setStartParams(startParams) - .setSequence(sequence), + .setSequence(sequence) + .setSingleProcess(Boolean.TRUE.equals(isSingleProcess)), null ); // FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, apiServer, appId, sequence, startParams,null); } else { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, sequence, startParams,null); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, + IFinAppletRequest.Companion.fromAppId(appId) + .setStartParams(startParams) + .setSequence(sequence) + .setSingleProcess(Boolean.TRUE.equals(isSingleProcess)), + null + ); } // String apiServer = (String) param.get("apiServer"); @@ -136,6 +144,8 @@ public class AppletModule extends BaseApi { String apiServer = (String) param.get("apiServer"); String offlineMiniprogramZipPath = (String) param.get("offlineMiniprogramZipPath"); String offlineFrameworkZipPath = (String) param.get("offlineFrameworkZipPath"); + Boolean isSingleProcess = (Boolean) param.get("isSingleProcess"); + Log.d("MopPlugin", "startApplet (appId=" + appId + ", sequence=" + sequence + " apiServer=" + apiServer + ")"); // mContext是FlutterActivity, // 在Android 6.0、7.0系统的部分设备中热启动小程序时,如果context参数用mContext,会出现无法启动小程序的问题 @@ -149,7 +159,8 @@ public class AppletModule extends BaseApi { IFinAppletRequest.Companion.fromAppId(apiServer, appId) .setSequence(sequence) .setStartParams(params) - .setOfflineParams(offlineFrameworkZipPath, offlineMiniprogramZipPath), + .setOfflineParams(offlineFrameworkZipPath, offlineMiniprogramZipPath) + .setSingleProcess(Boolean.TRUE.equals(isSingleProcess)), null); // 改成通过request来启动小程序 // FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, IFinAppletRequest.Companion.fromAppId("apiServer", "appId") @@ -159,14 +170,18 @@ public class AppletModule extends BaseApi { private void scanOpenApplet(Map param, ICallback callback) { String info = String.valueOf(param.get("info")); - FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, IFinAppletRequest.Companion.fromDecrypt(info), null); + Boolean isSingleProcess = (Boolean) param.get("isSingleProcess"); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, IFinAppletRequest.Companion.fromDecrypt(info) + .setSingleProcess(Boolean.TRUE.equals(isSingleProcess)), null); // FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, new StartAppletDecryptRequest(info),null); callback.onSuccess(new HashMap()); } private void qrcodeOpenApplet(Map param, ICallback callback){ String qrcode = String.valueOf(param.get("qrcode")); - FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, IFinAppletRequest.Companion.fromQrCode(qrcode), new FinCallback() { + Boolean isSingleProcess = (Boolean) param.get("isSingleProcess"); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, IFinAppletRequest.Companion.fromQrCode(qrcode) + .setSingleProcess(Boolean.TRUE.equals(isSingleProcess)), new FinCallback() { @Override public void onSuccess(String s) { callback.onSuccess(new HashMap()); diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java index 8cb637f..802b8e2 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java @@ -12,9 +12,11 @@ import com.finogeeks.lib.applet.interfaces.FinCallback; import com.finogeeks.mop.api.BaseApi; import com.finogeeks.mop.interfaces.ICallback; import com.finogeeks.mop.service.MopPluginService; +import com.finogeeks.xlog.XLogLevel; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -121,7 +123,9 @@ public class BaseModule extends BaseApi { .setUserId(userId) .setDebugMode(debug) .setDisableRequestPermissions(disablePermission) - .setBindAppletWithMainProcess(bindAppletWithMainProcess); + .setBindAppletWithMainProcess(bindAppletWithMainProcess) + .setLogLevel(XLogLevel.LEVEL_VERBOSE) + .setXLogDir(new File(getContext().getExternalCacheDir(),"xlog")); // .setPageCountLimit(pageCountLimit); if (customWebViewUserAgent != null) diff --git a/example/pubspec.lock b/example/pubspec.lock index e86417e..f69158c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -42,7 +42,7 @@ packages: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.16.0" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -95,13 +95,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.1.4" meta: dependency: transitive description: @@ -115,14 +108,14 @@ packages: path: ".." relative: true source: path - version: "2.37.3" + version: "2.37.13" path: dependency: transitive description: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -134,7 +127,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.2" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -169,14 +162,21 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.9" + version: "0.4.3" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.2" + version: "2.1.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=2.2.3" diff --git a/lib/mop.dart b/lib/mop.dart index dd61dc4..c689d15 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -225,12 +225,15 @@ class BaseAppletRequest { Map? startParams; // iOS端打开小程序时是否显示动画,默认为true。 bool? animated; + // 是否以单进程模式运行,仅限android,默认为false + bool isSingleProcess; BaseAppletRequest({ - required this.apiServer, + required this.apiServer, required this.appletId, this.startParams, this.animated = true, + this.isSingleProcess = false, }); Map toMap() { @@ -238,7 +241,8 @@ class BaseAppletRequest { "apiServer": apiServer, "appletId": appletId, "startParams": startParams, - "animated": animated + "animated": animated, + "isSingleProcess": isSingleProcess, }; } } @@ -258,15 +262,18 @@ class RemoteAppletRequest { String? offlineFrameworkZipPath; // iOS端打开小程序时是否显示动画,默认为true。 bool animated; +// 是否以单进程模式运行,仅限android,默认为false + bool isSingleProcess; RemoteAppletRequest({ - required this.apiServer, + required this.apiServer, required this.appletId, this.startParams, this.sequence, this.offlineMiniprogramZipPath, this.offlineFrameworkZipPath, this.animated = true, + this.isSingleProcess = false, }); @override @@ -274,7 +281,8 @@ class RemoteAppletRequest { Map result = { "apiServer": apiServer, "appletId": appletId, - "animated": animated + "animated": animated, + "isSingleProcess": isSingleProcess, }; if (startParams != null) result["startParams"] = startParams; if (offlineMiniprogramZipPath != null) result["offlineMiniprogramZipPath"] = offlineMiniprogramZipPath; @@ -290,13 +298,16 @@ class QRCodeAppletRequest { String qrCode; // 是否显示打开动画 bool animated = true; + // 是否以单进程模式运行,仅限android,默认为false + bool isSingleProcess; - QRCodeAppletRequest(this.qrCode); + QRCodeAppletRequest(this.qrCode, {this.isSingleProcess = false}); Map toMap() { return { "apiServer": qrCode, - "animated": animated + "animated": animated, + "isSingleProcess": isSingleProcess, }; } } @@ -447,6 +458,7 @@ class Mop { final int? sequence, final String? apiServer, final String? scene, + final bool isSingleProcess = false, }) async { Map params = {'appId': appId}; Map param = {}; @@ -456,6 +468,7 @@ class Mop { if (sequence != null) params["sequence"] = sequence; if (apiServer != null) params["apiServer"] = apiServer; if (scene != null) param["scene"] = scene; + params["isSingleProcess"] = isSingleProcess; final Map ret = await _channel.invokeMethod('openApplet', params); return ret; } @@ -524,8 +537,11 @@ class Mop { /// /// (扫码后)解密-鉴权-打开小程序 /// - Future scanOpenApplet(String info) async { - Map params = {'info': info}; + Future scanOpenApplet(String info, {bool isSingleProcess = false}) async { + Map params = { + 'info': info, + 'isSingleProcess': isSingleProcess, + }; return await _channel.invokeMapMethod("scanOpenApplet", params); } @@ -533,8 +549,11 @@ class Mop { /// 通过二维码打开小程序 /// [qrcode] 二维码内容 /// - Future qrcodeOpenApplet(String qrcode) async { - Map params = {'qrcode': qrcode}; + Future qrcodeOpenApplet(String qrcode, {bool isSingleProcess = false}) async { + Map params = { + 'qrcode': qrcode, + 'isSingleProcess': isSingleProcess, + }; return await _channel.invokeMapMethod("qrcodeOpenApplet", params); } diff --git a/pubspec.lock b/pubspec.lock index 7d68fe5..f39f99b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,14 +42,14 @@ packages: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.16.0" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -88,13 +88,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.1.4" meta: dependency: transitive description: @@ -108,7 +101,7 @@ packages: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -120,7 +113,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.2" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -155,14 +148,21 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.9" + version: "0.4.3" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.2" + version: "2.1.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=2.2.3"