From 17579d8f65d05085c03c0404485783f1b43bc475 Mon Sep 17 00:00:00 2001 From: wanghualei Date: Fri, 7 Apr 2023 13:40:02 +0000 Subject: [PATCH] Feat/opt --- .gitignore | 1 + .vscode/settings.json | 3 + android/.classpath | 2 +- .../org.eclipse.buildship.core.prefs | 6 +- .../mop/api/mop/AppletHandlerModule.java | 1 + .../finogeeks/mop/api/mop/AppletModule.java | 3 + .../finogeeks/mop/api/mop/InitSDKModule.java | 7 ++ .../finogeeks/mop/api/mop/util/InitUtils.java | 55 ++++++--- example/android/.project | 4 +- .../org.eclipse.buildship.core.prefs | 4 +- example/android/app/.classpath | 2 +- example/android/app/.project | 4 +- example/android/app/build.gradle | 27 ++++- .../android/app/src/main/AndroidManifest.xml | 1 + .../mop_example/MainApplication.java | 38 ++++++ example/android/build.gradle | 2 +- example/ios/Podfile.lock | 18 +-- example/ios/Runner.xcodeproj/project.pbxproj | 12 +- example/ios/Runner/Info.plist | 4 +- example/lib/main.dart | 111 +++++++++++++----- example/pubspec.lock | 36 +++--- ios/Classes/Api/MOPAppletDelegate.m | 15 +++ ios/Classes/Api/MOP_initSDK.m | 6 + ios/Classes/Api/MOP_registerAppletHandler.m | 1 + lib/api.dart | 3 + lib/mop.dart | 43 +++++-- pubspec.lock | 31 +++-- 27 files changed, 320 insertions(+), 120 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 example/android/app/src/main/java/com/finogeeks/mop_example/MainApplication.java diff --git a/.gitignore b/.gitignore index 45fc440..201fbd4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ doc/api/ *.js_ *.js.deps *.js.map +*.lock *.iml .gradle diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/android/.classpath b/android/.classpath index 4a04201..eb19361 100644 --- a/android/.classpath +++ b/android/.classpath @@ -1,6 +1,6 @@ - + diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index 1755e36..41f5edb 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -1,11 +1,11 @@ -arguments= +arguments=--init-script /var/folders/tv/dbm7kt650fvdxrtf0k7xgxcm0000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/tv/dbm7kt650fvdxrtf0k7xgxcm0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle auto.sync=false build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.0-rc-1)) +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.4.2)) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home=C\:/Program Files/Eclipse Foundation/jdk-11.0.12.7-hotspot +java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home jvm.arguments= offline.mode=false override.workspace.settings=true diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java index 88dab1d..a19b4db 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java @@ -10,6 +10,7 @@ import android.util.Log; import androidx.annotation.NonNull; +import com.finogeeks.lib.applet.client.FinAppProcessClient; import com.finogeeks.lib.applet.client.FinAppClient; import com.finogeeks.lib.applet.client.FinAppTrace; import com.finogeeks.lib.applet.interfaces.FinCallback; 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 9091047..a7c81f1 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 @@ -141,6 +141,9 @@ public class AppletModule extends BaseApi { String appId = String.valueOf(param.get("appletId")); Integer sequence = (Integer) param.get("sequence"); Map params = (Map) param.get("startParams"); + if (params == null) { + params = new HashMap<>(); + } String apiServer = (String) param.get("apiServer"); String offlineMiniprogramZipPath = (String) param.get("offlineMiniprogramZipPath"); String offlineFrameworkZipPath = (String) param.get("offlineFrameworkZipPath"); diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/InitSDKModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/InitSDKModule.java index fe11cdd..a55e5de 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/InitSDKModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/InitSDKModule.java @@ -19,6 +19,7 @@ import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Locale; public class InitSDKModule extends BaseApi { @@ -179,6 +180,12 @@ public class InitSDKModule extends BaseApi { if (appletText != null) { configBuilder.setAppletText(appletText); } + Integer languageInteger = (Integer) configMap.get("language"); + if (languageInteger == 1) { + configBuilder.setLocale(Locale.ENGLISH); + } else { + configBuilder.setLocale(Locale.SIMPLIFIED_CHINESE); + } // uiConfig FinAppConfig.UIConfig uiConfig = InitUtils.createUIConfigFromMap(uiConfigMap); diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/util/InitUtils.java b/android/src/main/java/com/finogeeks/mop/api/mop/util/InitUtils.java index 2c104de..5279c98 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/util/InitUtils.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/util/InitUtils.java @@ -7,6 +7,23 @@ import java.util.Map; public class InitUtils { + private static float covertNumToFloat(Object obj) { + if (obj instanceof Float) { + return ((Float) obj).floatValue(); + } else if (float.class.isInstance(obj)) { + return (float) obj; + } else if (obj instanceof Double) { + return ((Double) obj).floatValue(); + } else if (double.class.isInstance(obj)) { + return (float) obj; + } else if (obj instanceof Integer) { + return ((Integer) obj).floatValue(); + } else if (int.class.isInstance(obj)) { + return (float) obj; + } + throw new IllegalArgumentException("Unsupported argument type " + obj.getClass().getName()); + } + public static FinAppConfig.UIConfig createUIConfigFromMap(Map map) { if (map != null) { FinAppConfig.UIConfig uiConfig = new FinAppConfig.UIConfig(); @@ -27,11 +44,11 @@ public class InitUtils { Map capsuleConfigMap = (Map) map.get("capsuleConfig"); if (capsuleConfigMap != null) { FinAppConfig.UIConfig.CapsuleConfig capsuleConfig = new FinAppConfig.UIConfig.CapsuleConfig(); - capsuleConfig.capsuleWidth = (float) capsuleConfigMap.get("capsuleWidth"); - capsuleConfig.capsuleHeight = (float) capsuleConfigMap.get("capsuleHeight"); - capsuleConfig.capsuleRightMargin = (float) capsuleConfigMap.get("capsuleRightMargin"); - capsuleConfig.capsuleCornerRadius = (float) capsuleConfigMap.get("capsuleCornerRadius"); - capsuleConfig.capsuleBorderWidth = (float) capsuleConfigMap.get("capsuleBorderWidth"); + capsuleConfig.capsuleWidth = covertNumToFloat(capsuleConfigMap.get("capsuleWidth")); + capsuleConfig.capsuleHeight = covertNumToFloat(capsuleConfigMap.get("capsuleHeight")); + capsuleConfig.capsuleRightMargin = covertNumToFloat(capsuleConfigMap.get("capsuleRightMargin")); + capsuleConfig.capsuleCornerRadius = covertNumToFloat(capsuleConfigMap.get("capsuleCornerRadius")); + capsuleConfig.capsuleBorderWidth = covertNumToFloat(capsuleConfigMap.get("capsuleBorderWidth")); capsuleConfig.capsuleBgLightColor = (int) capsuleConfigMap.get("capsuleBgLightColor"); capsuleConfig.capsuleBgDarkColor = (int) capsuleConfigMap.get("capsuleBgDarkColor"); capsuleConfig.capsuleBorderLightColor = (int) capsuleConfigMap.get("capsuleBorderLightColor"); @@ -46,8 +63,8 @@ public class InitUtils { if (moreDarkImage != null) { capsuleConfig.moreDarkImage = moreDarkImage; } - capsuleConfig.moreBtnWidth = (float) capsuleConfigMap.get("moreBtnWidth"); - capsuleConfig.moreBtnLeftMargin = (float) capsuleConfigMap.get("moreBtnLeftMargin"); + capsuleConfig.moreBtnWidth = covertNumToFloat(capsuleConfigMap.get("moreBtnWidth")); + capsuleConfig.moreBtnLeftMargin = covertNumToFloat(capsuleConfigMap.get("moreBtnLeftMargin")); Integer closeLightImage = (Integer) capsuleConfigMap.get("closeLightImage"); if (closeLightImage != null) { capsuleConfig.closeLightImage = closeLightImage; @@ -56,18 +73,18 @@ public class InitUtils { if (closeDarkImage != null) { capsuleConfig.closeDarkImage = closeDarkImage; } - capsuleConfig.closeBtnWidth = (float) capsuleConfigMap.get("closeBtnWidth"); - capsuleConfig.closeBtnLeftMargin = (float) capsuleConfigMap.get("closeBtnLeftMargin"); + capsuleConfig.closeBtnWidth = covertNumToFloat(capsuleConfigMap.get("closeBtnWidth")); + capsuleConfig.closeBtnLeftMargin = covertNumToFloat(capsuleConfigMap.get("closeBtnLeftMargin")); uiConfig.setCapsuleConfig(capsuleConfig); } Map navHomeConfigMap = (Map) map.get("navHomeConfig"); if (navHomeConfigMap != null) { FinAppConfig.UIConfig.NavHomeConfig navHomeConfig = new FinAppConfig.UIConfig.NavHomeConfig(); - navHomeConfig.width = (float) navHomeConfigMap.get("width"); - navHomeConfig.height = (float) navHomeConfigMap.get("height"); - navHomeConfig.leftMargin = (float) navHomeConfigMap.get("leftMargin"); - navHomeConfig.cornerRadius = (float) navHomeConfigMap.get("cornerRadius"); - navHomeConfig.borderWidth = (float) navHomeConfigMap.get("borderWidth"); + navHomeConfig.width = covertNumToFloat(navHomeConfigMap.get("width")); + navHomeConfig.height = covertNumToFloat(navHomeConfigMap.get("height")); + navHomeConfig.leftMargin = covertNumToFloat(navHomeConfigMap.get("leftMargin")); + navHomeConfig.cornerRadius = covertNumToFloat(navHomeConfigMap.get("cornerRadius")); + navHomeConfig.borderWidth = covertNumToFloat(navHomeConfigMap.get("borderWidth")); navHomeConfig.borderLightColor = (int) navHomeConfigMap.get("borderLightColor"); navHomeConfig.borderDarkColor = (int) navHomeConfigMap.get("borderDarkColor"); navHomeConfig.bgLightColor = (int) navHomeConfigMap.get("bgLightColor"); @@ -77,19 +94,19 @@ public class InitUtils { Map authViewConfigMap = (Map) map.get("authViewConfig"); if (authViewConfigMap != null) { FinAppConfig.UIConfig.AuthViewConfig authViewConfig = new FinAppConfig.UIConfig.AuthViewConfig(); - authViewConfig.appletNameTextSize = (float) authViewConfigMap.get("appletNameTextSize"); + authViewConfig.appletNameTextSize = covertNumToFloat(authViewConfigMap.get("appletNameTextSize")); authViewConfig.appletNameLightColor = (int) authViewConfigMap.get("appletNameLightColor"); authViewConfig.appletNameDarkColor = (int) authViewConfigMap.get("appletNameDarkColor"); - authViewConfig.authorizeTitleTextSize = (float) authViewConfigMap.get("authorizeTitleTextSize"); + authViewConfig.authorizeTitleTextSize = covertNumToFloat(authViewConfigMap.get("authorizeTitleTextSize")); authViewConfig.authorizeTitleLightColor = (int) authViewConfigMap.get("authorizeTitleLightColor"); authViewConfig.authorizeTitleDarkColor = (int) authViewConfigMap.get("authorizeTitleDarkColor"); - authViewConfig.authorizeDescriptionTextSize = (float) authViewConfigMap.get("authorizeDescriptionTextSize"); + authViewConfig.authorizeDescriptionTextSize = covertNumToFloat(authViewConfigMap.get("authorizeDescriptionTextSize")); authViewConfig.authorizeDescriptionLightColor = (int) authViewConfigMap.get("authorizeDescriptionLightColor"); authViewConfig.authorizeDescriptionDarkColor = (int) authViewConfigMap.get("authorizeDescriptionDarkColor"); - authViewConfig.agreementTitleTextSize = (float) authViewConfigMap.get("agreementTitleTextSize"); + authViewConfig.agreementTitleTextSize = covertNumToFloat(authViewConfigMap.get("agreementTitleTextSize")); authViewConfig.agreementTitleLightColor = (int) authViewConfigMap.get("agreementTitleLightColor"); authViewConfig.agreementTitleDarkColor = (int) authViewConfigMap.get("agreementTitleDarkColor"); - authViewConfig.agreementDescriptionTextSize = (float) authViewConfigMap.get("agreementDescriptionTextSize"); + authViewConfig.agreementDescriptionTextSize = covertNumToFloat(authViewConfigMap.get("agreementDescriptionTextSize")); authViewConfig.agreementDescriptionLightColor = (int) authViewConfigMap.get("agreementDescriptionLightColor"); authViewConfig.agreementDescriptionDarkColor = (int) authViewConfigMap.get("agreementDescriptionDarkColor"); authViewConfig.linkLightColor = (int) authViewConfigMap.get("linkLightColor"); diff --git a/example/android/.project b/example/android/.project index b87df96..dbd42f6 100644 --- a/example/android/.project +++ b/example/android/.project @@ -16,12 +16,12 @@ - 1633860434667 + 1680241888118 30 org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ diff --git a/example/android/.settings/org.eclipse.buildship.core.prefs b/example/android/.settings/org.eclipse.buildship.core.prefs index a1eaa33..26ccfb0 100644 --- a/example/android/.settings/org.eclipse.buildship.core.prefs +++ b/example/android/.settings/org.eclipse.buildship.core.prefs @@ -1,11 +1,11 @@ -arguments= +arguments=--init-script /var/folders/tv/dbm7kt650fvdxrtf0k7xgxcm0000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/tv/dbm7kt650fvdxrtf0k7xgxcm0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle auto.sync=false build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home=C\:/Program Files/Eclipse Foundation/jdk-11.0.12.7-hotspot +java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home jvm.arguments= offline.mode=false override.workspace.settings=true diff --git a/example/android/app/.classpath b/example/android/app/.classpath index 4a04201..eb19361 100644 --- a/example/android/app/.classpath +++ b/example/android/app/.classpath @@ -1,6 +1,6 @@ - + diff --git a/example/android/app/.project b/example/android/app/.project index 1f8babd..5f167c1 100644 --- a/example/android/app/.project +++ b/example/android/app/.project @@ -22,12 +22,12 @@ - 1633860434672 + 1680241888252 30 org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 2b00e8a..9a095ec 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,8 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 - + compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 @@ -34,7 +33,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.finogeeks.finclip.demo" + applicationId "com.finogeeks.finosprite" minSdkVersion 21 targetSdkVersion 30 versionCode flutterVersionCode.toInteger() @@ -48,8 +47,30 @@ android { signingConfig signingConfigs.debug } } + packagingOptions { + // libsdkcore.so、libyuvutil.so是被加固过的,不能被压缩,否则加载动态库时会报错 + doNotStrip "*/x86/libsdkcore.so" + doNotStrip "*/x86_64/libsdkcore.so" + doNotStrip "*/armeabi/libsdkcore.so" + doNotStrip "*/armeabi-v7a/libsdkcore.so" + doNotStrip "*/arm64-v8a/libsdkcore.so" + + doNotStrip "*/x86/libfin-yuvutil.so" + doNotStrip "*/x86_64/libfin-yuvutil.so" + doNotStrip "*/armeabi/libfin-yuvutil.so" + doNotStrip "*/armeabi-v7a/libfin-yuvutil.so" + doNotStrip "*/arm64-v8a/libfin-yuvutil.so" + + exclude 'META-INF/beans.xml' + } } flutter { source '../..' } + +dependencies { + def sdk_version = "2.40.1" + compileOnly "com.finogeeks.lib:finapplet:${sdk_version}" + implementation "com.finogeeks.mop:plugins:${sdk_version}" +} diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 77c19dc..de9d78e 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -41,7 +43,5 @@ UIViewControllerBasedStatusBarAppearance - CADisableMinimumFrameDurationOnPhone - diff --git a/example/lib/main.dart b/example/lib/main.dart index e212afc..17d8685 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:ffi'; import 'package:flutter/material.dart'; +import 'package:mop/api.dart'; import 'dart:async'; import 'dart:io'; import 'package:mop/mop.dart'; @@ -23,50 +24,56 @@ class _MyAppState extends State { // Platform messages are asynchronous, so we initialize in an async method. Future init() async { - UIConfig uiconfig = UIConfig(); - //多服务器配置 + //多服务器配置 FinStoreConfig storeConfigA = FinStoreConfig( - "2LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=", - "bdfd76cae24d4313", - "https://api.finclip.com", + "22LyZEib0gLTQdU3MUauAfJ/xujwNfM6OvvEqQyH4igA", + "703b9026be3d6bc5", "https://api.finclip.com", + cryptType: "SM", ); FinStoreConfig storeConfigB = FinStoreConfig( - "2LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=", - "bdfd76cae24d4313", - "https://finchat-mop-b.finogeeks.club", - "https://finchat-mop-b.finogeeks.club", + "22LyZEib0gLTQdU3MUauAfJ/xujwNfM6OvvEqQyH4igA", + "703b9026be3d6bc5", + "https://finchat-mop-b.finogeeks.club" ); List storeConfigs = [storeConfigA]; + Config config = Config(storeConfigs); + config.language = LanguageType.English; + + UIConfig uiconfig = UIConfig(); uiconfig.isAlwaysShowBackInDefaultNavigationBar = false; uiconfig.isClearNavigationBarNavButtonBackground = false; uiconfig.isHideFeedbackAndComplaints = true; uiconfig.isHideBackHome = true; uiconfig.isHideForwardMenu = true; - uiconfig.hideTransitionCloseButton = true; - uiconfig.disableSlideCloseAppletGesture = true; CapsuleConfig capsuleConfig = CapsuleConfig(); - capsuleConfig.capsuleBgLightColor = 0x33ff00ee; - capsuleConfig.capsuleRightMargin = 25; + // capsuleConfig.capsuleBgLightColor = 0x33ff00ee; + capsuleConfig.capsuleCornerRadius = 16; + // capsuleConfig.capsuleRightMargin = 25; uiconfig.capsuleConfig = capsuleConfig; uiconfig.appletText = "applet"; - if (Platform.isIOS) { - final res = await Mop.instance.initialize( - '22LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=', 'bdfd76cae24d4313', - apiServer: 'https://api.finclip.com', - apiPrefix: '/api/v1/mop', - uiConfig: uiconfig, - finStoreConfigs: storeConfigs); - print(res); - } else if (Platform.isAndroid) { - final res = await Mop.instance.initialize( - '22LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=', 'bdfd76cae24d4313', - apiServer: 'https://api.finclip.com', apiPrefix: '/api/v1/mop'); - print(res); - } + // if (Platform.isIOS) { + // final res = await Mop.instance.initialize( + // '22LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=', 'bdfd76cae24d4313', + // apiServer: 'https://api.finclip.com', + // apiPrefix: '/api/v1/mop', + // uiConfig: uiconfig, + // finStoreConfigs: storeConfigs); + // print(res); + // } else if (Platform.isAndroid) { + // final res = await Mop.instance.initialize( + // '22LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=', 'bdfd76cae24d4313', + // apiServer: 'https://api.finclip.com', apiPrefix: '/api/v1/mop'); + // print(res); + // } + + final res = await Mop.instance.initSDK(config, uiConfig: uiconfig); + print(res); + Mop.instance.registerAppletHandler(MyAppletHandler()); + if (!mounted) return; } @@ -117,8 +124,10 @@ class _MyAppState extends State { // physics: NeverScrollableScrollPhysics(), children: [ _buildAppletItem(appletId, "打开小程序", () { - Mop.instance.openApplet(appletId, - path: 'pages/index/index', query: ''); + // Mop.instance.openApplet(appletId, + // path: 'pages/index/index', query: ''); + RemoteAppletRequest request = RemoteAppletRequest(apiServer: 'https://api.finclip.com', appletId: appletId); + Mop.instance.startApplet(request); }), _buildAppletItem(appletId, "finishRunningApplet", () { Mop.instance.finishRunningApplet(appletId, true); @@ -148,7 +157,7 @@ class _MyAppState extends State { body: Column( children: [ _buildAppletWidget("5facb3a52dcbff00017469bd", "画图小程序"), - _buildAppletWidget("5fa214a29a6a7900019b5cc1", "官方小程序"), + _buildAppletWidget("5f72e3559a6a7900019b5baa", "官方小程序"), _buildAppletWidget("5fa215459a6a7900019b5cc3", "我的对账单"), ], ), @@ -156,3 +165,45 @@ class _MyAppState extends State { ); } } + +class MyAppletHandler extends AppletHandler { + @override + Future appletDidOpen(String appId) async { + print("appletDidOpen appId:$appId"); + } + + @override + bool customCapsuleMoreButtonClick(String appId) { + return false; + } + + @override + void forwardApplet(Map appletInfo) { + print("forwardApplet ---"); + } + + @override + Future> getCustomMenus(String appId) { + List customMenus = []; + return Future.value(customMenus); + } + + @override + Future getMobileNumber(Function(dynamic params) param0) { + // TODO: implement getMobileNumber + throw UnimplementedError(); + } + + @override + Future> getUserInfo() { + // TODO: implement getUserInfo + throw UnimplementedError(); + } + + @override + Future onCustomMenuClick(String appId, String path, String menuId, String appInfo) { + // TODO: implement onCustomMenuClick + throw UnimplementedError(); + } + +} diff --git a/example/pubspec.lock b/example/pubspec.lock index 86b7e85..3013f95 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -42,21 +42,21 @@ 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: name: cupertino_icons url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.4" + version: "1.0.5" 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 @@ -75,7 +75,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.5" + version: "2.0.9" flutter_test: dependency: "direct dev" 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.39.1" + version: "2.40.1" 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" - flutter: ">=2.2.3" + dart: ">=2.17.0-0 <3.0.0" + flutter: ">=3.0.0" diff --git a/ios/Classes/Api/MOPAppletDelegate.m b/ios/Classes/Api/MOPAppletDelegate.m index 9dab0d9..57f10ef 100644 --- a/ios/Classes/Api/MOPAppletDelegate.m +++ b/ios/Classes/Api/MOPAppletDelegate.m @@ -56,6 +56,21 @@ return userInfo; } +- (BOOL)appletInfo:(FATAppletInfo *)appletInfo didClickMoreBtnAtPath:(NSString *)path { + NSLog(@"appletInfo:didClickMoreBtnAtPath"); + __block BOOL flag; + FlutterMethodChannel *channel = [[MopPlugin instance] methodChannel]; + [channel invokeMethod:@"extensionApi:customCapsuleMoreButtonClick" arguments:@{@"appId": appletInfo.appId} result:^(id _Nullable result) { + CFRunLoopStop(CFRunLoopGetMain()); + if ([result isKindOfClass:[NSNumber class]]) { + flag = [result boolValue]; + } + }]; + CFRunLoopRun(); + + return flag; +} + - (NSArray> *)customMenusInApplet:(FATAppletInfo *)appletInfo atPath:(NSString *)path { NSLog(@"customMenusInApplet"); __block NSArray *list; diff --git a/ios/Classes/Api/MOP_initSDK.m b/ios/Classes/Api/MOP_initSDK.m index 27c89cb..1603fc8 100644 --- a/ios/Classes/Api/MOP_initSDK.m +++ b/ios/Classes/Api/MOP_initSDK.m @@ -62,6 +62,12 @@ config.h5AjaxHookRequestKey = self.config[@"h5AjaxHookRequestKey"]; config.pageCountLimit = [self.config[@"pageCountLimit"] integerValue]; config.schemes = self.config[@"schemes"]; + NSInteger languageInteger = [self.config[@"language"] integerValue]; + if (languageInteger == 1) { + config.language = FATPreferredLanguageEnglish; + } else { + config.language = FATPreferredLanguageSimplifiedChinese; + } NSError* error = nil; diff --git a/ios/Classes/Api/MOP_registerAppletHandler.m b/ios/Classes/Api/MOP_registerAppletHandler.m index a1a0b63..69e137e 100644 --- a/ios/Classes/Api/MOP_registerAppletHandler.m +++ b/ios/Classes/Api/MOP_registerAppletHandler.m @@ -16,6 +16,7 @@ { NSLog(@"MOP_registerAppletHandler"); [FATClient sharedClient].delegate = [MOPAppletDelegate instance]; + [FATClient sharedClient].shareItemDelegate = [MOPAppletDelegate instance]; } @end diff --git a/lib/api.dart b/lib/api.dart index db43d4b..f4c554b 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -28,6 +28,9 @@ abstract class AppletHandler { /// Future> getUserInfo(); + /// 是否自定义胶囊里更多按钮的点击事件(该代理方法只对iOS端生效) + bool customCapsuleMoreButtonClick(String appId); + /// 获取自定义菜单 Future> getCustomMenus(String appId); diff --git a/lib/mop.dart b/lib/mop.dart index 2258100..66c48f2 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -202,6 +202,9 @@ class Config { /// 是否提前创建进程 bool enablePreNewProcess = true; + /// SDK的语言类型,默认为中文 + LanguageType language = LanguageType.Chinese; + Config(this.finStoreConfigs); Map toMap() { @@ -243,6 +246,7 @@ class Config { "logMaxAliveSec": logMaxAliveSec, "logDir": logDir, "enablePreNewProcess": enablePreNewProcess, + "language":language.index, }; } } @@ -339,7 +343,7 @@ class UIConfig { /// 加载小程序过程中(小程序Service层还未加载成功,基础库还没有向SDK传递小程序配置信息),是否隐藏导航栏的关闭按钮 bool hideTransitionCloseButton = false; - /// 是否禁用侧滑关闭小程序的手势。默认为NO + /// 是否禁用侧滑关闭小程序的手势。默认为false /// 该手势禁用,不影响小程序里页面的侧滑返回上一页的功能 bool disableSlideCloseAppletGesture = false; @@ -405,14 +409,20 @@ class CapsuleConfig { /// 右上角胶囊视图的圆角半径,默认值为5 double capsuleCornerRadius = 5; - /// 右上角胶囊视图的边框宽度,默认值为0.8 + /// 右上角胶囊视图的边框宽度,默认值为1 double capsuleBorderWidth = 1; + // /// 胶囊背景颜色浅色 + // int capsuleBgLightColor = 0x80ffffff; + + // /// 胶囊背景颜色深色 + // int capsuleBgDarkColor = 0x33000000; + /// 胶囊背景颜色浅色 - int capsuleBgLightColor = 0x33000000; + int capsuleBgLightColor = Platform.isAndroid ? 0x33000000 : 0x80ffffff; /// 胶囊背景颜色深色 - int capsuleBgDarkColor = 0x80ffffff; + int capsuleBgDarkColor = Platform.isAndroid ? 0x80ffffff : 0x33000000; /// 右上角胶囊视图的边框浅色颜色 int capsuleBorderLightColor = 0x80ffffff; @@ -432,11 +442,11 @@ class CapsuleConfig { /// 胶囊里的深色更多按钮的图片对象,如果不传,会使用默认图标 int? moreDarkImage; - /// 胶囊里的更多按钮的宽度,高度与宽度相等 - double moreBtnWidth = 32; + /// 胶囊里的更多按钮的宽度,高度与宽度相等。android默认值为32;ios默认值为20 + double moreBtnWidth = Platform.isAndroid ? 32 : 20; - /// 胶囊里的更多按钮的左边距 - double moreBtnLeftMargin = 6; + /// 胶囊里的更多按钮的左边距。android默认值为6;ios默认值为12 + double moreBtnLeftMargin = Platform.isAndroid ? 6 : 12; /// 胶囊里的浅色更多按钮的图片对象,如果不传,会使用默认图标 int? closeLightImage; @@ -444,11 +454,11 @@ class CapsuleConfig { /// 胶囊里的深色更多按钮的图片对象,如果不传,会使用默认图标 int? closeDarkImage; - /// 胶囊里的关闭按钮的宽度,高度与宽度相等 - double closeBtnWidth = 32; + /// 胶囊里的关闭按钮的宽度,高度与宽度相等。android默认值为32;ios默认值为20 + double closeBtnWidth = Platform.isAndroid ? 32 : 20; - /// 胶囊里的关闭按钮的左边距 - double closeBtnLeftMargin = 6; + /// 胶囊里的关闭按钮的左边距。android默认值为6;ios默认值为12 + double closeBtnLeftMargin = Platform.isAndroid ? 6 : 12; Map toMap() { return { @@ -758,6 +768,7 @@ class RemoteAppletRequest { String appletId; // 小程序的启动参数,非必填 + // key 仅支持 'path' 和 'query' Map? startParams; // 小程序的索引,(审核小程序时必填) @@ -853,6 +864,11 @@ enum BOOLState { BOOLStateForbidden, // 所有版本强制关闭vconsole,且不可调api开启,多面板不展示打开、关闭调试菜单 } +enum LanguageType { + Chinese, // 中文 + English, // 英文 +} + enum LogLevel { LEVEL_ERROR, // 设置为该等级,将会记录ERROR级别的日志 LEVEL_WARNING, // 设置为该等级,将会记录ERROR和WARNING级别的日志 @@ -1114,6 +1130,9 @@ class Mop { _appletHandlerApis["getUserInfo"] = (params) { return handler.getUserInfo(); }; + _appletHandlerApis["customCapsuleMoreButtonClick"] = (params) async { + return handler.customCapsuleMoreButtonClick(params["appId"]); + }; _appletHandlerApis["getCustomMenus"] = (params) async { final res = await handler.getCustomMenus(params["appId"]); List> list = []; diff --git a/pubspec.lock b/pubspec.lock index e3f3961..7d68fe5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.9.0" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,21 @@ packages: name: characters url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.2.0" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.1" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.1" + version: "1.1.0" collection: dependency: transitive description: @@ -42,7 +49,7 @@ packages: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.1" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -80,28 +87,28 @@ packages: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.12" + 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.5" + version: "0.1.4" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0" + version: "1.7.0" path: dependency: transitive description: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.2" + 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.9.0" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -134,21 +141,21 @@ packages: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.12" + version: "0.4.9" vector_math: dependency: transitive description: