Commit 0e0293a334c99c76d3f1b011c5ccb0127e9f6589

Authored by 权海
1 parent 94ddfe45

feat(ui):增加AppleHealth日志导出接口

@@ -308,10 +308,9 @@ interface HealthKitHostApi { @@ -308,10 +308,9 @@ interface HealthKitHostApi {
308 fun cancelHealthAppAuthorization(): Boolean 308 fun cancelHealthAppAuthorization(): Boolean
309 /** Runs native health read and server upload pipeline. */ 309 /** Runs native health read and server upload pipeline. */
310 fun performHealthUpload(callback: (Result<HealthUploadResult>) -> Unit) 310 fun performHealthUpload(callback: (Result<HealthUploadResult>) -> Unit)
311 - /**  
312 - * 获取当前已上传的健康数据点,主要用于调试  
313 - * Opens Huawei Health client authorization UI. Returns whether user granted.  
314 - */ 311 + /**测试使用- 导出本地存储的observer日志 */
  312 + fun exportHealthObserverRecord(callback: (Result<Boolean>) -> Unit)
  313 + /** Opens Huawei Health client authorization UI. Returns whether user granted. */
315 fun checkHealthAppAuthorization(callback: (Result<HealthAuthorization>) -> Unit) 314 fun checkHealthAppAuthorization(callback: (Result<HealthAuthorization>) -> Unit)
316 fun requestHealthClientAuthorization(callback: (Result<Boolean>) -> Unit) 315 fun requestHealthClientAuthorization(callback: (Result<Boolean>) -> Unit)
317 fun fetchHrvData(startTime: Long, endTime: Long, callback: (Result<List<HealthUploadDataPoint>>) -> Unit) 316 fun fetchHrvData(startTime: Long, endTime: Long, callback: (Result<List<HealthUploadDataPoint>>) -> Unit)
@@ -391,6 +390,24 @@ interface HealthKitHostApi { @@ -391,6 +390,24 @@ interface HealthKitHostApi {
391 } 390 }
392 } 391 }
393 run { 392 run {
  393 + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.exportHealthObserverRecord$separatedMessageChannelSuffix", codec)
  394 + if (api != null) {
  395 + channel.setMessageHandler { _, reply ->
  396 + api.exportHealthObserverRecord{ result: Result<Boolean> ->
  397 + val error = result.exceptionOrNull()
  398 + if (error != null) {
  399 + reply.reply(HealthKitApiPigeonUtils.wrapError(error))
  400 + } else {
  401 + val data = result.getOrNull()
  402 + reply.reply(HealthKitApiPigeonUtils.wrapResult(data))
  403 + }
  404 + }
  405 + }
  406 + } else {
  407 + channel.setMessageHandler(null)
  408 + }
  409 + }
  410 + run {
394 val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$separatedMessageChannelSuffix", codec) 411 val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$separatedMessageChannelSuffix", codec)
395 if (api != null) { 412 if (api != null) {
396 channel.setMessageHandler { _, reply -> 413 channel.setMessageHandler { _, reply ->
@@ -333,7 +333,8 @@ protocol HealthKitHostApi { @@ -333,7 +333,8 @@ protocol HealthKitHostApi {
333 func cancelHealthAppAuthorization() throws -> Bool 333 func cancelHealthAppAuthorization() throws -> Bool
334 /// Runs native health read and server upload pipeline. 334 /// Runs native health read and server upload pipeline.
335 func performHealthUpload(completion: @escaping (Result<HealthUploadResult, Error>) -> Void) 335 func performHealthUpload(completion: @escaping (Result<HealthUploadResult, Error>) -> Void)
336 - /// 获取当前已上传的健康数据点,主要用于调试 336 + ///测试使用- 导出本地存储的observer日志
  337 + func exportHealthObserverRecord(completion: @escaping (Result<Bool, Error>) -> Void)
337 /// Opens Huawei Health client authorization UI. Returns whether user granted. 338 /// Opens Huawei Health client authorization UI. Returns whether user granted.
338 func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void) 339 func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void)
339 func requestHealthClientAuthorization(completion: @escaping (Result<Bool, Error>) -> Void) 340 func requestHealthClientAuthorization(completion: @escaping (Result<Bool, Error>) -> Void)
@@ -404,7 +405,22 @@ class HealthKitHostApiSetup { @@ -404,7 +405,22 @@ class HealthKitHostApiSetup {
404 } else { 405 } else {
405 performHealthUploadChannel.setMessageHandler(nil) 406 performHealthUploadChannel.setMessageHandler(nil)
406 } 407 }
407 - /// 获取当前已上传的健康数据点,主要用于调试 408 + ///测试使用- 导出本地存储的observer日志
  409 + let exportHealthObserverRecordChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.exportHealthObserverRecord\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
  410 + if let api = api {
  411 + exportHealthObserverRecordChannel.setMessageHandler { _, reply in
  412 + api.exportHealthObserverRecord { result in
  413 + switch result {
  414 + case .success(let res):
  415 + reply(wrapResult(res))
  416 + case .failure(let error):
  417 + reply(wrapError(error))
  418 + }
  419 + }
  420 + }
  421 + } else {
  422 + exportHealthObserverRecordChannel.setMessageHandler(nil)
  423 + }
408 /// Opens Huawei Health client authorization UI. Returns whether user granted. 424 /// Opens Huawei Health client authorization UI. Returns whether user granted.
409 let checkHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) 425 let checkHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
410 if let api = api { 426 if let api = api {
@@ -2,6 +2,10 @@ import Foundation @@ -2,6 +2,10 @@ import Foundation
2 import HealthKit 2 import HealthKit
3 3
4 final class HealthKitHostApiImpl: HealthKitHostApi { 4 final class HealthKitHostApiImpl: HealthKitHostApi {
  5 + func exportHealthObserverRecord(completion: @escaping (Result<Bool, any Error>) -> Void) {
  6 + completion(.success(false))
  7 + }
  8 +
5 private let service: HealthKitService 9 private let service: HealthKitService
6 10
7 init(service: HealthKitService = .shared) { 11 init(service: HealthKitService = .shared) {
  1 +import 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart';
1 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
2 import 'package:get/get.dart'; 3 import 'package:get/get.dart';
3 4
@@ -33,6 +34,10 @@ class DeveloperOptionsController extends GetxController { @@ -33,6 +34,10 @@ class DeveloperOptionsController extends GetxController {
33 title: 'Token Login', 34 title: 'Token Login',
34 routeName: Routes.TOKEN_LOGIN, 35 routeName: Routes.TOKEN_LOGIN,
35 ), 36 ),
  37 + DeveloperOptionsItem(
  38 + title: '导出AppleHealth监听回调日志',
  39 + routeName: '',
  40 + ),
36 ]; 41 ];
37 42
38 @override 43 @override
@@ -41,6 +46,14 @@ class DeveloperOptionsController extends GetxController { @@ -41,6 +46,14 @@ class DeveloperOptionsController extends GetxController {
41 tokenController.text = _userPreferencesStorage.accessToken; 46 tokenController.text = _userPreferencesStorage.accessToken;
42 } 47 }
43 48
  49 + optionItemOnTap(DeveloperOptionsItem item) {
  50 + if (item.routeName.isEmpty) {
  51 + HealthKitHostApi().exportHealthObserverRecord();
  52 + return;
  53 + }
  54 + Get.toNamed(item.routeName);
  55 + }
  56 +
44 Future<void> saveAccessToken() async { 57 Future<void> saveAccessToken() async {
45 final token = tokenController.text.trim(); 58 final token = tokenController.text.trim();
46 await _userPreferencesStorage.updateAccessToken(token); 59 await _userPreferencesStorage.updateAccessToken(token);
@@ -17,7 +17,7 @@ class DeveloperOptionsView extends GetView<DeveloperOptionsController> { @@ -17,7 +17,7 @@ class DeveloperOptionsView extends GetView<DeveloperOptionsController> {
17 return ListTile( 17 return ListTile(
18 title: Text(item.title), 18 title: Text(item.title),
19 trailing: const Icon(Icons.chevron_right), 19 trailing: const Icon(Icons.chevron_right),
20 - onTap: () => Get.toNamed(item.routeName), 20 + onTap: () => controller.optionItemOnTap(item),
21 ); 21 );
22 }, 22 },
23 separatorBuilder: (context, index) => const Padding( 23 separatorBuilder: (context, index) => const Padding(
@@ -421,7 +421,35 @@ class HealthKitHostApi { @@ -421,7 +421,35 @@ class HealthKitHostApi {
421 } 421 }
422 } 422 }
423 423
424 - /// 获取当前已上传的健康数据点,主要用于调试 424 + ///测试使用- 导出本地存储的observer日志
  425 + Future<bool> exportHealthObserverRecord() async {
  426 + final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.exportHealthObserverRecord$pigeonVar_messageChannelSuffix';
  427 + final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
  428 + pigeonVar_channelName,
  429 + pigeonChannelCodec,
  430 + binaryMessenger: pigeonVar_binaryMessenger,
  431 + );
  432 + final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
  433 + final List<Object?>? pigeonVar_replyList =
  434 + await pigeonVar_sendFuture as List<Object?>?;
  435 + if (pigeonVar_replyList == null) {
  436 + throw _createConnectionError(pigeonVar_channelName);
  437 + } else if (pigeonVar_replyList.length > 1) {
  438 + throw PlatformException(
  439 + code: pigeonVar_replyList[0]! as String,
  440 + message: pigeonVar_replyList[1] as String?,
  441 + details: pigeonVar_replyList[2],
  442 + );
  443 + } else if (pigeonVar_replyList[0] == null) {
  444 + throw PlatformException(
  445 + code: 'null-error',
  446 + message: 'Host platform returned null value for non-null return value.',
  447 + );
  448 + } else {
  449 + return (pigeonVar_replyList[0] as bool?)!;
  450 + }
  451 + }
  452 +
425 /// Opens Huawei Health client authorization UI. Returns whether user granted. 453 /// Opens Huawei Health client authorization UI. Returns whether user granted.
426 Future<HealthAuthorization> checkHealthAppAuthorization() async { 454 Future<HealthAuthorization> checkHealthAppAuthorization() async {
427 final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$pigeonVar_messageChannelSuffix'; 455 final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$pigeonVar_messageChannelSuffix';
@@ -83,8 +83,9 @@ abstract class HealthKitHostApi { @@ -83,8 +83,9 @@ abstract class HealthKitHostApi {
83 @async 83 @async
84 HealthUploadResult performHealthUpload(); 84 HealthUploadResult performHealthUpload();
85 85
86 - /// 获取当前已上传的健康数据点,主要用于调试  
87 - // List<HealthUploadDataPoint> getDebugCurrentUploadedData(); 86 + ///测试使用- 导出本地存储的observer日志
  87 + @async
  88 + bool exportHealthObserverRecord();
88 89
89 // @required 90 // @required
90 91