Commit 0e0293a334c99c76d3f1b011c5ccb0127e9f6589

Authored by 权海
1 parent 94ddfe45

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

... ... @@ -308,10 +308,9 @@ interface HealthKitHostApi {
fun cancelHealthAppAuthorization(): Boolean
/** Runs native health read and server upload pipeline. */
fun performHealthUpload(callback: (Result<HealthUploadResult>) -> Unit)
/**
* 获取当前已上传的健康数据点,主要用于调试
* Opens Huawei Health client authorization UI. Returns whether user granted.
*/
/**测试使用- 导出本地存储的observer日志 */
fun exportHealthObserverRecord(callback: (Result<Boolean>) -> Unit)
/** Opens Huawei Health client authorization UI. Returns whether user granted. */
fun checkHealthAppAuthorization(callback: (Result<HealthAuthorization>) -> Unit)
fun requestHealthClientAuthorization(callback: (Result<Boolean>) -> Unit)
fun fetchHrvData(startTime: Long, endTime: Long, callback: (Result<List<HealthUploadDataPoint>>) -> Unit)
... ... @@ -391,6 +390,24 @@ interface HealthKitHostApi {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.exportHealthObserverRecord$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
api.exportHealthObserverRecord{ result: Result<Boolean> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(HealthKitApiPigeonUtils.wrapError(error))
} else {
val data = result.getOrNull()
reply.reply(HealthKitApiPigeonUtils.wrapResult(data))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
... ...
... ... @@ -333,7 +333,8 @@ protocol HealthKitHostApi {
func cancelHealthAppAuthorization() throws -> Bool
/// Runs native health read and server upload pipeline.
func performHealthUpload(completion: @escaping (Result<HealthUploadResult, Error>) -> Void)
/// 获取当前已上传的健康数据点,主要用于调试
///测试使用- 导出本地存储的observer日志
func exportHealthObserverRecord(completion: @escaping (Result<Bool, Error>) -> Void)
/// Opens Huawei Health client authorization UI. Returns whether user granted.
func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void)
func requestHealthClientAuthorization(completion: @escaping (Result<Bool, Error>) -> Void)
... ... @@ -404,7 +405,22 @@ class HealthKitHostApiSetup {
} else {
performHealthUploadChannel.setMessageHandler(nil)
}
/// 获取当前已上传的健康数据点,主要用于调试
///测试使用- 导出本地存储的observer日志
let exportHealthObserverRecordChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.exportHealthObserverRecord\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
exportHealthObserverRecordChannel.setMessageHandler { _, reply in
api.exportHealthObserverRecord { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
exportHealthObserverRecordChannel.setMessageHandler(nil)
}
/// Opens Huawei Health client authorization UI. Returns whether user granted.
let checkHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
... ...
... ... @@ -2,6 +2,10 @@ import Foundation
import HealthKit
final class HealthKitHostApiImpl: HealthKitHostApi {
func exportHealthObserverRecord(completion: @escaping (Result<Bool, any Error>) -> Void) {
completion(.success(false))
}
private let service: HealthKitService
init(service: HealthKitService = .shared) {
... ...
import 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
... ... @@ -33,6 +34,10 @@ class DeveloperOptionsController extends GetxController {
title: 'Token Login',
routeName: Routes.TOKEN_LOGIN,
),
DeveloperOptionsItem(
title: '导出AppleHealth监听回调日志',
routeName: '',
),
];
@override
... ... @@ -41,6 +46,14 @@ class DeveloperOptionsController extends GetxController {
tokenController.text = _userPreferencesStorage.accessToken;
}
optionItemOnTap(DeveloperOptionsItem item) {
if (item.routeName.isEmpty) {
HealthKitHostApi().exportHealthObserverRecord();
return;
}
Get.toNamed(item.routeName);
}
Future<void> saveAccessToken() async {
final token = tokenController.text.trim();
await _userPreferencesStorage.updateAccessToken(token);
... ...
... ... @@ -17,7 +17,7 @@ class DeveloperOptionsView extends GetView<DeveloperOptionsController> {
return ListTile(
title: Text(item.title),
trailing: const Icon(Icons.chevron_right),
onTap: () => Get.toNamed(item.routeName),
onTap: () => controller.optionItemOnTap(item),
);
},
separatorBuilder: (context, index) => const Padding(
... ...
... ... @@ -421,7 +421,35 @@ class HealthKitHostApi {
}
}
/// 获取当前已上传的健康数据点,主要用于调试
///测试使用- 导出本地存储的observer日志
Future<bool> exportHealthObserverRecord() async {
final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.exportHealthObserverRecord$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else if (pigeonVar_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (pigeonVar_replyList[0] as bool?)!;
}
}
/// Opens Huawei Health client authorization UI. Returns whether user granted.
Future<HealthAuthorization> checkHealthAppAuthorization() async {
final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$pigeonVar_messageChannelSuffix';
... ...
... ... @@ -83,8 +83,9 @@ abstract class HealthKitHostApi {
@async
HealthUploadResult performHealthUpload();
/// 获取当前已上传的健康数据点,主要用于调试
// List<HealthUploadDataPoint> getDebugCurrentUploadedData();
///测试使用- 导出本地存储的observer日志
@async
bool exportHealthObserverRecord();
// @required
... ...