Commit eadccd2a52af26be661b017671e06acf9de8b78e

Authored by 权海
1 parent 04eefd5a

feat(ui):更新platform api

feat(ui):修复调用bridge报错

feat(ui):修复
@@ -36,6 +36,12 @@ @@ -36,6 +36,12 @@
36 @import permission_handler_apple; 36 @import permission_handler_apple;
37 #endif 37 #endif
38 38
  39 +#if __has_include(<share_plus/FPPSharePlusPlugin.h>)
  40 +#import <share_plus/FPPSharePlusPlugin.h>
  41 +#else
  42 +@import share_plus;
  43 +#endif
  44 +
39 #if __has_include(<shared_preferences_foundation/SharedPreferencesPlugin.h>) 45 #if __has_include(<shared_preferences_foundation/SharedPreferencesPlugin.h>)
40 #import <shared_preferences_foundation/SharedPreferencesPlugin.h> 46 #import <shared_preferences_foundation/SharedPreferencesPlugin.h>
41 #else 47 #else
@@ -62,6 +68,7 @@ @@ -62,6 +68,7 @@
62 [FLTImagePickerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTImagePickerPlugin"]]; 68 [FLTImagePickerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTImagePickerPlugin"]];
63 [PathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"PathProviderPlugin"]]; 69 [PathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"PathProviderPlugin"]];
64 [PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]]; 70 [PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]];
  71 + [FPPSharePlusPlugin registerWithRegistrar:[registry registrarForPlugin:@"FPPSharePlusPlugin"]];
65 [SharedPreferencesPlugin registerWithRegistrar:[registry registrarForPlugin:@"SharedPreferencesPlugin"]]; 72 [SharedPreferencesPlugin registerWithRegistrar:[registry registrarForPlugin:@"SharedPreferencesPlugin"]];
66 [SqflitePlugin registerWithRegistrar:[registry registrarForPlugin:@"SqflitePlugin"]]; 73 [SqflitePlugin registerWithRegistrar:[registry registrarForPlugin:@"SqflitePlugin"]];
67 [WebViewFlutterPlugin registerWithRegistrar:[registry registrarForPlugin:@"WebViewFlutterPlugin"]]; 74 [WebViewFlutterPlugin registerWithRegistrar:[registry registrarForPlugin:@"WebViewFlutterPlugin"]];
@@ -324,10 +324,15 @@ interface PlatformHostApi { @@ -324,10 +324,15 @@ interface PlatformHostApi {
324 * baseUrl: 请求地址, https://api.doublefeel.cn 324 * baseUrl: 请求地址, https://api.doublefeel.cn
325 */ 325 */
326 fun updateLoginInfo(jsonString: String, baseUrl: String) 326 fun updateLoginInfo(jsonString: String, baseUrl: String)
327 - /** 设置好友显示到表盘 */  
328 - fun updateWatchOtherUserInfo(otherInfo: WatchAppOtherInfo?)  
329 - /** 刷新表盘 */  
330 - fun refreshWatchSurface() 327 + /** 退出登录 */
  328 + fun logout()
  329 + /** 刷新会员信息 */
  330 + fun refreshVip()
  331 + /**
  332 + * 刷新watch app 和 表盘的所有数据:
  333 + * 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
  334 + */
  335 + fun refreshWatchAppAndWidgets()
331 /** 请求苹果登录 */ 336 /** 请求苹果登录 */
332 fun requestAppleSignIn(callback: (Result<AppleSignInModel?>) -> Unit) 337 fun requestAppleSignIn(callback: (Result<AppleSignInModel?>) -> Unit)
333 /** 338 /**
@@ -385,13 +390,27 @@ interface PlatformHostApi { @@ -385,13 +390,27 @@ interface PlatformHostApi {
385 } 390 }
386 } 391 }
387 run { 392 run {
388 - val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.updateWatchOtherUserInfo$separatedMessageChannelSuffix", codec) 393 + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.logout$separatedMessageChannelSuffix", codec)
389 if (api != null) { 394 if (api != null) {
390 - channel.setMessageHandler { message, reply ->  
391 - val args = message as List<Any?>  
392 - val otherInfoArg = args[0] as WatchAppOtherInfo? 395 + channel.setMessageHandler { _, reply ->
  396 + val wrapped: List<Any?> = try {
  397 + api.logout()
  398 + listOf(null)
  399 + } catch (exception: Throwable) {
  400 + PlatformApiPigeonUtils.wrapError(exception)
  401 + }
  402 + reply.reply(wrapped)
  403 + }
  404 + } else {
  405 + channel.setMessageHandler(null)
  406 + }
  407 + }
  408 + run {
  409 + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshVip$separatedMessageChannelSuffix", codec)
  410 + if (api != null) {
  411 + channel.setMessageHandler { _, reply ->
393 val wrapped: List<Any?> = try { 412 val wrapped: List<Any?> = try {
394 - api.updateWatchOtherUserInfo(otherInfoArg) 413 + api.refreshVip()
395 listOf(null) 414 listOf(null)
396 } catch (exception: Throwable) { 415 } catch (exception: Throwable) {
397 PlatformApiPigeonUtils.wrapError(exception) 416 PlatformApiPigeonUtils.wrapError(exception)
@@ -403,11 +422,11 @@ interface PlatformHostApi { @@ -403,11 +422,11 @@ interface PlatformHostApi {
403 } 422 }
404 } 423 }
405 run { 424 run {
406 - val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchSurface$separatedMessageChannelSuffix", codec) 425 + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchAppAndWidgets$separatedMessageChannelSuffix", codec)
407 if (api != null) { 426 if (api != null) {
408 channel.setMessageHandler { _, reply -> 427 channel.setMessageHandler { _, reply ->
409 val wrapped: List<Any?> = try { 428 val wrapped: List<Any?> = try {
410 - api.refreshWatchSurface() 429 + api.refreshWatchAppAndWidgets()
411 listOf(null) 430 listOf(null)
412 } catch (exception: Throwable) { 431 } catch (exception: Throwable) {
413 PlatformApiPigeonUtils.wrapError(exception) 432 PlatformApiPigeonUtils.wrapError(exception)
@@ -358,10 +358,13 @@ protocol PlatformHostApi { @@ -358,10 +358,13 @@ protocol PlatformHostApi {
358 /// jsonString: UserPreferences的序列化string 358 /// jsonString: UserPreferences的序列化string
359 /// baseUrl: 请求地址, https://api.doublefeel.cn 359 /// baseUrl: 请求地址, https://api.doublefeel.cn
360 func updateLoginInfo(jsonString: String, baseUrl: String) throws 360 func updateLoginInfo(jsonString: String, baseUrl: String) throws
361 - /// 设置好友显示到表盘  
362 - func updateWatchOtherUserInfo(otherInfo: WatchAppOtherInfo?) throws  
363 - /// 刷新表盘  
364 - func refreshWatchSurface() throws 361 + /// 退出登录
  362 + func logout() throws
  363 + /// 刷新会员信息
  364 + func refreshVip() throws
  365 + /// 刷新watch app 和 表盘的所有数据:
  366 + /// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
  367 + func refreshWatchAppAndWidgets() throws
365 /// 请求苹果登录 368 /// 请求苹果登录
366 func requestAppleSignIn(completion: @escaping (Result<AppleSignInModel?, Error>) -> Void) 369 func requestAppleSignIn(completion: @escaping (Result<AppleSignInModel?, Error>) -> Void)
367 /// 查询指定id的苹果商品 370 /// 查询指定id的苹果商品
@@ -414,35 +417,48 @@ class PlatformHostApiSetup { @@ -414,35 +417,48 @@ class PlatformHostApiSetup {
414 } else { 417 } else {
415 updateLoginInfoChannel.setMessageHandler(nil) 418 updateLoginInfoChannel.setMessageHandler(nil)
416 } 419 }
417 - /// 设置好友显示到表盘  
418 - let updateWatchOtherUserInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.updateWatchOtherUserInfo\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) 420 + /// 退出登录
  421 + let logoutChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.logout\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
419 if let api = api { 422 if let api = api {
420 - updateWatchOtherUserInfoChannel.setMessageHandler { message, reply in  
421 - let args = message as! [Any?]  
422 - let otherInfoArg: WatchAppOtherInfo? = nilOrValue(args[0]) 423 + logoutChannel.setMessageHandler { _, reply in
  424 + do {
  425 + try api.logout()
  426 + reply(wrapResult(nil))
  427 + } catch {
  428 + reply(wrapError(error))
  429 + }
  430 + }
  431 + } else {
  432 + logoutChannel.setMessageHandler(nil)
  433 + }
  434 + /// 刷新会员信息
  435 + let refreshVipChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshVip\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
  436 + if let api = api {
  437 + refreshVipChannel.setMessageHandler { _, reply in
423 do { 438 do {
424 - try api.updateWatchOtherUserInfo(otherInfo: otherInfoArg) 439 + try api.refreshVip()
425 reply(wrapResult(nil)) 440 reply(wrapResult(nil))
426 } catch { 441 } catch {
427 reply(wrapError(error)) 442 reply(wrapError(error))
428 } 443 }
429 } 444 }
430 } else { 445 } else {
431 - updateWatchOtherUserInfoChannel.setMessageHandler(nil) 446 + refreshVipChannel.setMessageHandler(nil)
432 } 447 }
433 - /// 刷新表盘  
434 - let refreshWatchSurfaceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchSurface\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) 448 + /// 刷新watch app 和 表盘的所有数据:
  449 + /// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
  450 + let refreshWatchAppAndWidgetsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchAppAndWidgets\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
435 if let api = api { 451 if let api = api {
436 - refreshWatchSurfaceChannel.setMessageHandler { _, reply in 452 + refreshWatchAppAndWidgetsChannel.setMessageHandler { _, reply in
437 do { 453 do {
438 - try api.refreshWatchSurface() 454 + try api.refreshWatchAppAndWidgets()
439 reply(wrapResult(nil)) 455 reply(wrapResult(nil))
440 } catch { 456 } catch {
441 reply(wrapError(error)) 457 reply(wrapError(error))
442 } 458 }
443 } 459 }
444 } else { 460 } else {
445 - refreshWatchSurfaceChannel.setMessageHandler(nil) 461 + refreshWatchAppAndWidgetsChannel.setMessageHandler(nil)
446 } 462 }
447 /// 请求苹果登录 463 /// 请求苹果登录
448 let requestAppleSignInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppleSignIn\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) 464 let requestAppleSignInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.requestAppleSignIn\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
@@ -37,6 +37,18 @@ class PriceFormatter{ @@ -37,6 +37,18 @@ class PriceFormatter{
37 * `{systemWebViewUA} doublefeel/{versionCode}({versionName})(Apple##Apple##{model}; iOS{osVersion}; {height}x{width})(huawei)` 37 * `{systemWebViewUA} doublefeel/{versionCode}({versionName})(Apple##Apple##{model}; iOS{osVersion}; {height}x{width})(huawei)`
38 */ 38 */
39 final class PlatformHostApiImpl: PlatformHostApi { 39 final class PlatformHostApiImpl: PlatformHostApi {
  40 + func logout() throws {
  41 +
  42 + }
  43 +
  44 + func refreshVip() throws {
  45 +
  46 + }
  47 +
  48 + func refreshWatchAppAndWidgets() throws {
  49 +
  50 + }
  51 +
40 func performRestore(completion: @escaping (Result<Bool, any Error>) -> Void) { 52 func performRestore(completion: @escaping (Result<Bool, any Error>) -> Void) {
41 Task{ 53 Task{
42 let success = await AppShared.shared.payment.restore() 54 let success = await AppShared.shared.payment.restore()
@@ -28,7 +28,7 @@ class FriendsController extends GetxController { @@ -28,7 +28,7 @@ class FriendsController extends GetxController {
28 _selfHealthRepository = selfHealthRepository ?? 28 _selfHealthRepository = selfHealthRepository ??
29 SelfHealthRepositoryImpl(Get.find<HealthApi>()), 29 SelfHealthRepositoryImpl(Get.find<HealthApi>()),
30 _updateWatchOtherUserInfo = updateWatchOtherUserInfo ?? 30 _updateWatchOtherUserInfo = updateWatchOtherUserInfo ??
31 - ((info) => PlatformHostApi().updateWatchOtherUserInfo(info)); 31 + ((info) => PlatformHostApi().refreshWatchAppAndWidgets());
32 32
33 static const maxFriends = 10; 33 static const maxFriends = 10;
34 34
@@ -408,15 +408,39 @@ class PlatformHostApi { @@ -408,15 +408,39 @@ class PlatformHostApi {
408 } 408 }
409 } 409 }
410 410
411 - /// 设置好友显示到表盘  
412 - Future<void> updateWatchOtherUserInfo(WatchAppOtherInfo? otherInfo) async {  
413 - final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.updateWatchOtherUserInfo$pigeonVar_messageChannelSuffix'; 411 + /// 退出登录
  412 + Future<void> logout() async {
  413 + final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.logout$pigeonVar_messageChannelSuffix';
414 final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>( 414 final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
415 pigeonVar_channelName, 415 pigeonVar_channelName,
416 pigeonChannelCodec, 416 pigeonChannelCodec,
417 binaryMessenger: pigeonVar_binaryMessenger, 417 binaryMessenger: pigeonVar_binaryMessenger,
418 ); 418 );
419 - final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[otherInfo]); 419 + final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
  420 + final List<Object?>? pigeonVar_replyList =
  421 + await pigeonVar_sendFuture as List<Object?>?;
  422 + if (pigeonVar_replyList == null) {
  423 + throw _createConnectionError(pigeonVar_channelName);
  424 + } else if (pigeonVar_replyList.length > 1) {
  425 + throw PlatformException(
  426 + code: pigeonVar_replyList[0]! as String,
  427 + message: pigeonVar_replyList[1] as String?,
  428 + details: pigeonVar_replyList[2],
  429 + );
  430 + } else {
  431 + return;
  432 + }
  433 + }
  434 +
  435 + /// 刷新会员信息
  436 + Future<void> refreshVip() async {
  437 + final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshVip$pigeonVar_messageChannelSuffix';
  438 + final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
  439 + pigeonVar_channelName,
  440 + pigeonChannelCodec,
  441 + binaryMessenger: pigeonVar_binaryMessenger,
  442 + );
  443 + final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
420 final List<Object?>? pigeonVar_replyList = 444 final List<Object?>? pigeonVar_replyList =
421 await pigeonVar_sendFuture as List<Object?>?; 445 await pigeonVar_sendFuture as List<Object?>?;
422 if (pigeonVar_replyList == null) { 446 if (pigeonVar_replyList == null) {
@@ -432,9 +456,10 @@ class PlatformHostApi { @@ -432,9 +456,10 @@ class PlatformHostApi {
432 } 456 }
433 } 457 }
434 458
435 - /// 刷新表盘  
436 - Future<void> refreshWatchSurface() async {  
437 - final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchSurface$pigeonVar_messageChannelSuffix'; 459 + /// 刷新watch app 和 表盘的所有数据:
  460 + /// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
  461 + Future<void> refreshWatchAppAndWidgets() async {
  462 + final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.PlatformHostApi.refreshWatchAppAndWidgets$pigeonVar_messageChannelSuffix';
438 final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>( 463 final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
439 pigeonVar_channelName, 464 pigeonVar_channelName,
440 pigeonChannelCodec, 465 pigeonChannelCodec,
@@ -116,11 +116,15 @@ abstract class PlatformHostApi { @@ -116,11 +116,15 @@ abstract class PlatformHostApi {
116 /// baseUrl: 请求地址, https://api.doublefeel.cn 116 /// baseUrl: 请求地址, https://api.doublefeel.cn
117 void updateLoginInfo(String jsonString, String baseUrl); 117 void updateLoginInfo(String jsonString, String baseUrl);
118 118
119 - /// 设置好友显示到表盘  
120 - void updateWatchOtherUserInfo(WatchAppOtherInfo? otherInfo);  
121 -  
122 - /// 刷新表盘  
123 - void refreshWatchSurface(); 119 + /// 退出登录
  120 + void logout();
  121 +
  122 + /// 刷新会员信息
  123 + void refreshVip();
  124 +
  125 + /// 刷新watch app 和 表盘的所有数据:
  126 + /// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
  127 + void refreshWatchAppAndWidgets();
124 128
125 /// 请求苹果登录 129 /// 请求苹果登录
126 @async 130 @async