From ed0ba0b3c092a1fb12bc458aa053edadbdf963a9 Mon Sep 17 00:00:00 2001 From: wanghualei Date: Fri, 29 Jul 2022 14:31:56 +0000 Subject: [PATCH] Feat/start applet --- android/build.gradle | 4 +- .../mop/api/mop/AppletManageModule.java | 1 + .../finogeeks/mop/api/mop/AppletModule.java | 41 +++++++- example/ios/Runner/Info.plist | 2 + example/pubspec.lock | 30 +++--- ios/Classes/Api/MOP_initialize.m | 2 +- ios/Classes/Api/MOP_startApplet.h | 24 +++++ ios/Classes/Api/MOP_startApplet.m | 40 ++++++++ ios/mop.podspec | 4 +- lib/mop.dart | 93 ++++++++++++++++++- pubspec.lock | 28 +++--- 11 files changed, 233 insertions(+), 36 deletions(-) create mode 100644 ios/Classes/Api/MOP_startApplet.h create mode 100644 ios/Classes/Api/MOP_startApplet.m diff --git a/android/build.gradle b/android/build.gradle index d8876e9..ddb2708 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -91,6 +91,6 @@ kapt { } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.finogeeks.lib:finapplet:2.37.4-alpha20220727v13' - implementation 'com.finogeeks.mop:plugins:2.37.1' + implementation 'com.finogeeks.lib:finapplet:2.37.3' + implementation 'com.finogeeks.mop:plugins:2.37.3' } \ No newline at end of file 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 5d77784..818ecfe 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 @@ -91,6 +91,7 @@ public class AppletManageModule extends BaseApi { FinAppClient.INSTANCE.getAppletApiManager().clearApplets(); callback.onSuccess(null); } else if (event.equals("removeUsedApplet")) { + Log.d("MopPlugin", "removeUsedApplet:params:" + param); if (param.containsKey("appId") && param.get("appId") instanceof String) { String appId = (String) param.get("appId"); FinAppClient.INSTANCE.getAppletApiManager().removeUsedApplet(appId); 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 c16941a..52d8a0f 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 @@ -31,7 +31,7 @@ public class AppletModule extends BaseApi { @Override public String[] apis() { - return new String[]{"openApplet", "scanOpenApplet","qrcodeOpenApplet", "changeUserId"}; + return new String[]{"openApplet", "scanOpenApplet","qrcodeOpenApplet", "changeUserId", "startApplet"}; } @Override @@ -44,6 +44,8 @@ public class AppletModule extends BaseApi { qrcodeOpenApplet(param,callback); } else if ("changeUserId".equals(event)) { changeUserId(param, callback); + } else if ("startApplet".equals(event)) { + startApplet(param, callback); } } @@ -118,6 +120,43 @@ public class AppletModule extends BaseApi { callback.onSuccess(new HashMap()); } + private void startApplet(Map param, ICallback callback) { + if (param.get("appletId") == null) { + callback.onFail(new HashMap() { + { + put("info", "appId不能为空"); + } + }); + return; + } + Log.d("MopPlugin", "startApplet:params:" + param); + String appId = String.valueOf(param.get("appletId")); + Integer sequence = (Integer) param.get("sequence"); + Map params = (Map) param.get("startParams"); + String apiServer = (String) param.get("apiServer"); + String offlineMiniprogramZipPath = (String) param.get("offlineMiniprogramZipPath"); + String offlineFrameworkZipPath = (String) param.get("offlineFrameworkZipPath"); + Log.d("MopPlugin", "startApplet (appId=" + appId + ", sequence=" + sequence + " apiServer=" + apiServer + ")"); + // mContext是FlutterActivity, + // 在Android 6.0、7.0系统的部分设备中热启动小程序时,如果context参数用mContext,会出现无法启动小程序的问题 + // 所以这里使用Application Context + Context context = mContext.getApplicationContext(); +// String dir = context.getFilesDir(); + // FinAppInfo.StartParams startParams = params == null ? null : new FinAppInfo.StartParams(params.get("path"), params.get("query"), params.get("scene")); + // Log.d(TAG, "openApplet:" + appId + "," + param + "," + apiServer); + + FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, + IFinAppletRequest.Companion.fromAppId(apiServer, appId) + .setSequence(sequence) + .setStartParams(params) + .setOfflineParams(offlineFrameworkZipPath, offlineMiniprogramZipPath), + null); + // 改成通过request来启动小程序 + // FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, IFinAppletRequest.Companion.fromAppId("apiServer", "appId") + // .setStartParams(params).setOfflinexxxx); + callback.onSuccess(new HashMap()); + } + private void scanOpenApplet(Map param, ICallback callback) { String info = String.valueOf(param.get("info")); FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, IFinAppletRequest.Companion.fromDecrypt(info), null); diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index 1293dcb..32b5439 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -41,5 +41,7 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + diff --git a/example/pubspec.lock b/example/pubspec.lock index e42970e..e86417e 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.15.0" + version: "1.16.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.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -95,6 +95,13 @@ 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,14 +115,14 @@ packages: path: ".." relative: true source: path - version: "2.36.3" + version: "2.37.3" path: dependency: transitive description: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0" + version: "1.8.1" sky_engine: dependency: transitive description: flutter @@ -127,7 +134,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -162,21 +169,14 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.3" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=2.2.3" diff --git a/ios/Classes/Api/MOP_initialize.m b/ios/Classes/Api/MOP_initialize.m index 8786ad0..f75a922 100644 --- a/ios/Classes/Api/MOP_initialize.m +++ b/ios/Classes/Api/MOP_initialize.m @@ -126,7 +126,7 @@ return; } // [[FATExtClient sharedClient] fat_prepareExtensionApis]; - + [[FATClient sharedClient].logManager initLogWithLogDir:nil logLevel:FATLogLevelVerbose consoleLog:YES]; [[FATClient sharedClient] setEnableLog:YES]; diff --git a/ios/Classes/Api/MOP_startApplet.h b/ios/Classes/Api/MOP_startApplet.h new file mode 100644 index 0000000..d51f4df --- /dev/null +++ b/ios/Classes/Api/MOP_startApplet.h @@ -0,0 +1,24 @@ +// +// MOP_openApplet.h +// mop +// +// Created by 杨涛 on 2020/2/27. +// + +#import "MOPBaseApi.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MOP_startApplet : MOPBaseApi + +@property (nonatomic, copy) NSString *appletId; +@property (nonatomic, copy) NSString *apiServer; +@property (nonatomic, copy) NSString *sequence; +@property (nonatomic, copy) NSDictionary *startParams; +@property (nonatomic, copy) NSString *offlineMiniprogramZipPath; +@property (nonatomic, copy) NSString *offlineFrameworkZipPath; +@property (nonatomic, strong) NSString *animated; + +@end + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/Api/MOP_startApplet.m b/ios/Classes/Api/MOP_startApplet.m new file mode 100644 index 0000000..d998603 --- /dev/null +++ b/ios/Classes/Api/MOP_startApplet.m @@ -0,0 +1,40 @@ +// +// MOP_openApplet.m +// mop +// +// Created by 杨涛 on 2020/2/27. +// + +#import "MOP_startApplet.h" +#import "MOPTools.h" +#import + +@implementation MOP_startApplet + +- (void)setupApiWithSuccess:(void (^)(NSDictionary * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel +{ + UIViewController *currentVC = [MOPTools topViewController]; + + FATAppletRequest *request = [[FATAppletRequest alloc] init]; + request.appletId = self.appletId; + request.apiServer = self.apiServer; + request.startParams = self.startParams; + if (self.sequence){ + request.sequence = @([self.sequence intValue]); + } + request.offlineMiniprogramZipPath = self.offlineMiniprogramZipPath; + request.offlineFrameworkZipPath = self.offlineFrameworkZipPath; + request.animated = [self.animated boolValue]; + + // 启动小程序 + [[FATClient sharedClient] startAppletWithRequest:request InParentViewController:currentVC completion:^(BOOL result, NSError *error) { + if (result){ + success(@{}); + } else { + failure(error.description); + } + } closeCompletion:^(void) { + + }]; +} +@end diff --git a/ios/mop.podspec b/ios/mop.podspec index 084c755..35b80c8 100644 --- a/ios/mop.podspec +++ b/ios/mop.podspec @@ -17,7 +17,7 @@ A finclip miniprogram flutter sdk. s.dependency 'Flutter' s.ios.deployment_target = '9.0' - s.dependency 'FinApplet' , '2.37.3' - s.dependency 'FinAppletExt' , '2.37.3' + s.dependency 'FinApplet' , '2.37.4-alpha20220729v13' + s.dependency 'FinAppletExt' , '2.37.4-alpha20220729v13' end diff --git a/lib/mop.dart b/lib/mop.dart index 014c290..7bd54a8 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:ffi'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -217,6 +216,91 @@ class FloatWindowConfig { } } +class BaseAppletRequest { + // 服务器地址,必填 + String apiServer; + // 小程序id,必填 + String appletId; + // 小程序的启动参数,非必填 + Map? startParams; + // iOS端打开小程序时是否显示动画,默认为true。 + bool? animated; + + BaseAppletRequest({ + required this.apiServer, + required this.appletId, + this.startParams, + this.animated = true, + }); + + Map toMap() { + return { + "apiServer": apiServer, + "appletId": appletId, + "startParams": startParams, + "animated": animated + }; + } +} + +class RemoteAppletRequest { + // 服务器地址,必填 + String apiServer; + // 小程序id,必填 + String appletId; + // 小程序的启动参数,非必填 + Map? startParams; + // 小程序的索引,(审核小程序时必填) + int? sequence; + // 离线小程序压缩包路径,非必填 + String? offlineMiniprogramZipPath; + // 离线基础库压缩包路径,非必填 + String? offlineFrameworkZipPath; + // iOS端打开小程序时是否显示动画,默认为true。 + bool animated; + + RemoteAppletRequest({ + required this.apiServer, + required this.appletId, + this.startParams, + this.sequence, + this.offlineMiniprogramZipPath, + this.offlineFrameworkZipPath, + this.animated = true, + }); + + @override + Map toMap() { + Map result = { + "apiServer": apiServer, + "appletId": appletId, + "animated": animated + }; + if (startParams != null) result["startParams"] = startParams; + if (offlineMiniprogramZipPath != null) result["offlineMiniprogramZipPath"] = offlineMiniprogramZipPath; + if (offlineFrameworkZipPath != null) result["offlineFrameworkZipPath"] = offlineFrameworkZipPath; + if (sequence != null) result["sequence"] = sequence; + + return result; + } +} + +class QRCodeAppletRequest { + // 二维码内容 + String qrCode; + // 是否显示打开动画 + bool animated = true; + + QRCodeAppletRequest(this.qrCode); + + Map toMap() { + return { + "apiServer": qrCode, + "animated": animated + }; + } +} + enum Anim { SlideFromLeftToRightAnim, SlideFromRightToLeftAnim, @@ -376,6 +460,13 @@ class Mop { return ret; } + + Future startApplet(RemoteAppletRequest request) async { + Map params = request.toMap(); + final Map ret = await _channel.invokeMethod('startApplet', params); + return ret; + } + /// /// get current using applet /// 获取当前正在使用的小程序信息 diff --git a/pubspec.lock b/pubspec.lock index f39f99b..7d68fe5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,14 +42,14 @@ packages: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.15.0" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -88,6 +88,13 @@ 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: @@ -101,7 +108,7 @@ packages: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0" + version: "1.8.1" sky_engine: dependency: transitive description: flutter @@ -113,7 +120,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -148,21 +155,14 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.3" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" flutter: ">=2.2.3"