Commit a3a0c7ad6e72abf99b893c8ae6f4f72807222a71

Authored by 权海
1 parent 1e2747f2

feat(ui):修改pigeon api中间层

(cherry picked from commit ffa69d85)

# Conflicts:
#	lib/core/platform/pigeon_api_facade.dart
#	ohos/entry/src/main/ets/pigeon/HealthKitApi.ets
#	pubspec.lock
@@ -135,8 +135,6 @@ private open class HealthKitApiPigeonCodec : StandardMessageCodec() { @@ -135,8 +135,6 @@ private open class HealthKitApiPigeonCodec : StandardMessageCodec() {
135 135
136 /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ 136 /** Generated interface from Pigeon that represents a handler of messages from Flutter. */
137 interface HealthKitHostApi { 137 interface HealthKitHostApi {
138 - fun getHealthServerAuthUrl(callback: (Result<String>) -> Unit)  
139 - fun cancelHealthAppAuthorization(): Boolean  
140 /** Opens Huawei Health client authorization UI. Returns whether user granted. */ 138 /** Opens Huawei Health client authorization UI. Returns whether user granted. */
141 fun checkHealthAppAuthorization(callback: (Result<HealthAuthorization>) -> Unit) 139 fun checkHealthAppAuthorization(callback: (Result<HealthAuthorization>) -> Unit)
142 fun requestHealthClientAuthorization(callback: (Result<Boolean>) -> Unit) 140 fun requestHealthClientAuthorization(callback: (Result<Boolean>) -> Unit)
@@ -151,39 +149,6 @@ interface HealthKitHostApi { @@ -151,39 +149,6 @@ interface HealthKitHostApi {
151 fun setUp(binaryMessenger: BinaryMessenger, api: HealthKitHostApi?, messageChannelSuffix: String = "") { 149 fun setUp(binaryMessenger: BinaryMessenger, api: HealthKitHostApi?, messageChannelSuffix: String = "") {
152 val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" 150 val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
153 run { 151 run {
154 - val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.getHealthServerAuthUrl$separatedMessageChannelSuffix", codec)  
155 - if (api != null) {  
156 - channel.setMessageHandler { _, reply ->  
157 - api.getHealthServerAuthUrl{ result: Result<String> ->  
158 - val error = result.exceptionOrNull()  
159 - if (error != null) {  
160 - reply.reply(HealthKitApiPigeonUtils.wrapError(error))  
161 - } else {  
162 - val data = result.getOrNull()  
163 - reply.reply(HealthKitApiPigeonUtils.wrapResult(data))  
164 - }  
165 - }  
166 - }  
167 - } else {  
168 - channel.setMessageHandler(null)  
169 - }  
170 - }  
171 - run {  
172 - val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.cancelHealthAppAuthorization$separatedMessageChannelSuffix", codec)  
173 - if (api != null) {  
174 - channel.setMessageHandler { _, reply ->  
175 - val wrapped: List<Any?> = try {  
176 - listOf(api.cancelHealthAppAuthorization())  
177 - } catch (exception: Throwable) {  
178 - HealthKitApiPigeonUtils.wrapError(exception)  
179 - }  
180 - reply.reply(wrapped)  
181 - }  
182 - } else {  
183 - channel.setMessageHandler(null)  
184 - }  
185 - }  
186 - run {  
187 val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$separatedMessageChannelSuffix", codec) 152 val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$separatedMessageChannelSuffix", codec)
188 if (api != null) { 153 if (api != null) {
189 channel.setMessageHandler { _, reply -> 154 channel.setMessageHandler { _, reply ->
@@ -181,8 +181,6 @@ class HealthKitApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable @@ -181,8 +181,6 @@ class HealthKitApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable
181 181
182 /// Generated protocol from Pigeon that represents a handler of messages from Flutter. 182 /// Generated protocol from Pigeon that represents a handler of messages from Flutter.
183 protocol HealthKitHostApi { 183 protocol HealthKitHostApi {
184 - func getHealthServerAuthUrl(completion: @escaping (Result<String, Error>) -> Void)  
185 - func cancelHealthAppAuthorization() throws -> Bool  
186 /// Opens Huawei Health client authorization UI. Returns whether user granted. 184 /// Opens Huawei Health client authorization UI. Returns whether user granted.
187 func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void) 185 func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void)
188 func requestHealthClientAuthorization(completion: @escaping (Result<Bool, Error>) -> Void) 186 func requestHealthClientAuthorization(completion: @escaping (Result<Bool, Error>) -> Void)
@@ -194,34 +192,6 @@ class HealthKitHostApiSetup { @@ -194,34 +192,6 @@ class HealthKitHostApiSetup {
194 /// Sets up an instance of `HealthKitHostApi` to handle messages through the `binaryMessenger`. 192 /// Sets up an instance of `HealthKitHostApi` to handle messages through the `binaryMessenger`.
195 static func setUp(binaryMessenger: FlutterBinaryMessenger, api: HealthKitHostApi?, messageChannelSuffix: String = "") { 193 static func setUp(binaryMessenger: FlutterBinaryMessenger, api: HealthKitHostApi?, messageChannelSuffix: String = "") {
196 let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" 194 let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
197 - let getHealthServerAuthUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.getHealthServerAuthUrl\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)  
198 - if let api = api {  
199 - getHealthServerAuthUrlChannel.setMessageHandler { _, reply in  
200 - api.getHealthServerAuthUrl { result in  
201 - switch result {  
202 - case .success(let res):  
203 - reply(wrapResult(res))  
204 - case .failure(let error):  
205 - reply(wrapError(error))  
206 - }  
207 - }  
208 - }  
209 - } else {  
210 - getHealthServerAuthUrlChannel.setMessageHandler(nil)  
211 - }  
212 - let cancelHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.cancelHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)  
213 - if let api = api {  
214 - cancelHealthAppAuthorizationChannel.setMessageHandler { _, reply in  
215 - do {  
216 - let result = try api.cancelHealthAppAuthorization()  
217 - reply(wrapResult(result))  
218 - } catch {  
219 - reply(wrapError(error))  
220 - }  
221 - }  
222 - } else {  
223 - cancelHealthAppAuthorizationChannel.setMessageHandler(nil)  
224 - }  
225 /// Opens Huawei Health client authorization UI. Returns whether user granted. 195 /// Opens Huawei Health client authorization UI. Returns whether user granted.
226 let checkHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) 196 let checkHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
227 if let api = api { 197 if let api = api {
@@ -8,16 +8,6 @@ final class HealthKitHostApiImpl: HealthKitHostApi { @@ -8,16 +8,6 @@ final class HealthKitHostApiImpl: HealthKitHostApi {
8 self.service = service 8 self.service = service
9 } 9 }
10 10
11 - func getHealthServerAuthUrl(completion: @escaping (Result<String, Error>) -> Void) {  
12 - // Apple Health authorization is system-managed, not URL based.  
13 - completion(.success(""))  
14 - }  
15 -  
16 - func cancelHealthAppAuthorization() throws -> Bool {  
17 - // iOS does not let apps revoke HealthKit permission programmatically.  
18 - false  
19 - }  
20 -  
21 func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void) { 11 func checkHealthAppAuthorization(completion: @escaping (Result<HealthAuthorization, Error>) -> Void) {
22 Task { 12 Task {
23 let authorization: HealthAuthorization 13 let authorization: HealthAuthorization
  1 +import 'package:flutter/foundation.dart';
  2 +import 'package:doublefeel_flutter/pigeon/alipay_api.g.dart' as alipay;
  3 +import 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart' as health_kit;
  4 +import 'package:doublefeel_flutter/pigeon/health_kit_raw_data_api.g.dart'
  5 + as health_raw;
  6 +import 'package:doublefeel_flutter/pigeon/platform_api.g.dart' as platform;
  7 +import 'package:doublefeel_flutter/pigeon/wear_engine_api.g.dart' as wear;
  8 +
  9 +export 'package:doublefeel_flutter/pigeon/alipay_api.g.dart';
  10 +export 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart';
  11 +export 'package:doublefeel_flutter/pigeon/health_kit_raw_data_api.g.dart';
  12 +export 'package:doublefeel_flutter/pigeon/platform_api.g.dart';
  13 +export 'package:doublefeel_flutter/pigeon/wear_engine_api.g.dart';
  14 +
  15 +enum AppPigeonPlatform { ios, android, ohos }
  16 +
  17 +typedef AppPigeonPlatformProvider = AppPigeonPlatform Function();
  18 +
  19 +AppPigeonPlatform resolveAppPigeonPlatform({TargetPlatform? targetPlatform}) {
  20 + final platform = targetPlatform ?? defaultTargetPlatform;
  21 + if (platform.name == 'ohos') {
  22 + return AppPigeonPlatform.ohos;
  23 + }
  24 + if (platform == TargetPlatform.iOS) {
  25 + return AppPigeonPlatform.ios;
  26 + }
  27 + return AppPigeonPlatform.android;
  28 +}
  29 +
  30 +abstract class _AppPigeonApiFacade {
  31 + _AppPigeonApiFacade({
  32 + AppPigeonPlatform? appPlatform,
  33 + AppPigeonPlatformProvider? platformProvider,
  34 + }) : _platformProvider = platformProvider ??
  35 + (() => appPlatform ?? resolveAppPigeonPlatform());
  36 +
  37 + final AppPigeonPlatformProvider _platformProvider;
  38 +
  39 + AppPigeonPlatform get appPigeonPlatform => _platformProvider();
  40 +
  41 + Future<T> dispatch<T>({
  42 + required Future<T> Function() ios,
  43 + Future<T> Function()? android,
  44 + Future<T> Function()? ohos,
  45 + }) {
  46 + return switch (appPigeonPlatform) {
  47 + AppPigeonPlatform.ios => ios(),
  48 + AppPigeonPlatform.android => (android ?? ios)(),
  49 + AppPigeonPlatform.ohos => (ohos ?? android ?? ios)(),
  50 + };
  51 + }
  52 +}
  53 +
  54 +class AppPlatformHostApi extends _AppPigeonApiFacade {
  55 + AppPlatformHostApi({
  56 + platform.PlatformHostApi? api,
  57 + super.appPlatform,
  58 + super.platformProvider,
  59 + }) : _api = api ?? platform.PlatformHostApi();
  60 +
  61 + final platform.PlatformHostApi _api;
  62 +
  63 + Future<String> getFullUserAgent() => dispatch(
  64 + ios: () => _api.getFullUserAgent(),
  65 + ohos: () async {
  66 + //TODO: - 组装agent
  67 + return "";
  68 + },
  69 + );
  70 +
  71 + Future<bool> isChinaRegion() => dispatch(
  72 + ios: () => _api.isChinaRegion(),
  73 + ohos: () async {
  74 + return true;
  75 + });
  76 +
  77 + Future<int> getApnsAuthStatus() => dispatch(
  78 + ios: () => _api.getApnsAuthStatus(),
  79 + ohos: () async {
  80 + //TODO: - 检查通知权限
  81 + return 0;
  82 + },
  83 + );
  84 +
  85 + Future<bool> requestNotificationAuth() => dispatch(
  86 + ios: () => _api.requestNotificationAuth(),
  87 + ohos: () async {
  88 + //TODO: - 请求通知权限
  89 + return false;
  90 + },
  91 + );
  92 +
  93 + Future<bool> isDebugEnvoriment() => dispatch(
  94 + ios: () => _api.isDebugEnvoriment(),
  95 + ohos: () async {
  96 + return false;
  97 + });
  98 +
  99 + Future<bool> shareText(String text) => dispatch(
  100 + ios: () => _api.shareText(text),
  101 + ohos: () async {
  102 + //TODO: - 分享文本(配对信息)
  103 + return false;
  104 + });
  105 +
  106 + Future<bool> shareFileData(Uint8List databytes) => dispatch(
  107 + ios: () => _api.shareFileData(databytes),
  108 + ohos: () async {
  109 + return false;
  110 + });
  111 +
  112 + Future<void> updateLoginInfo(String jsonString, String baseUrl) => dispatch(
  113 + ios: () => _api.updateLoginInfo(jsonString, baseUrl),
  114 + ohos: () async {
  115 + return;
  116 + });
  117 +
  118 + Future<void> logout() => dispatch(
  119 + ios: () => _api.logout(),
  120 + ohos: () async {
  121 + return;
  122 + });
  123 +
  124 + Future<void> refreshVip() => dispatch(
  125 + ios: () => _api.refreshVip(),
  126 + ohos: () async {
  127 + return;
  128 + });
  129 +
  130 + Future<void> refreshWatchAppAndWidgets() => dispatch(
  131 + ios: () => _api.refreshWatchAppAndWidgets(),
  132 + ohos: () async {
  133 + return;
  134 + });
  135 +
  136 + Future<bool> requestAppReview() => dispatch(
  137 + ios: () => _api.requestAppReview(),
  138 + ohos: () async {
  139 + return false;
  140 + });
  141 +
  142 + Future<bool> jumpAppSetting() => dispatch(
  143 + ios: () => _api.jumpAppSetting(),
  144 + ohos: () async {
  145 + return false;
  146 + });
  147 +
  148 + Future<bool> nativeHandleUrl(String urlString) => dispatch(
  149 + ios: () => _api.nativeHandleUrl(urlString),
  150 + ohos: () async {
  151 + //TODO: - 处理url跳转
  152 + return false;
  153 + });
  154 +
  155 + Future<String?> requestUnhandedUrl() => dispatch(
  156 + ios: () => _api.requestUnhandedUrl(),
  157 + ohos: () async {
  158 + //TODO: - 请求未处理的url(通知点击启动app后,启动flutter引擎交给flutter处理url)
  159 + return null;
  160 + });
  161 +
  162 + Future<platform.AppleSignInModel?> requestAppleSignIn() => dispatch(
  163 + ios: () => _api.requestAppleSignIn(),
  164 + ohos: () async {
  165 + return null;
  166 + });
  167 +
  168 + Future<platform.GoogleSignInModel?> requestGoogleSignIn() => dispatch(
  169 + ios: () => _api.requestGoogleSignIn(),
  170 + ohos: () async {
  171 + return null;
  172 + });
  173 +
  174 + Future<bool> sendEmail(String mailTo, String title, String content) =>
  175 + dispatch(
  176 + ios: () => _api.sendEmail(mailTo, title, content),
  177 + ohos: () async {
  178 + //TODO: - 发送邮件
  179 + return false;
  180 + });
  181 +
  182 + Future<platform.AppleProductInfo?> requestAppleProductInfo(
  183 + String productId,
  184 + int baseUnit,
  185 + ) =>
  186 + dispatch(
  187 + ios: () => _api.requestAppleProductInfo(productId, baseUnit),
  188 + ohos: () async {
  189 + return null;
  190 + });
  191 +
  192 + Future<platform.AppleProductPaymentResult?> performApplePayment(
  193 + String productId,
  194 + String uuid,
  195 + ) =>
  196 + dispatch(
  197 + ios: () => _api.performApplePayment(productId, uuid),
  198 + ohos: () async {
  199 + return null;
  200 + });
  201 +
  202 + Future<bool> performRestore() => dispatch(
  203 + ios: () => _api.performRestore(),
  204 + ohos: () async {
  205 + return false;
  206 + });
  207 +
  208 + Future<String?> uploadFile(
  209 + String filePath,
  210 + platform.HResourceType resourceType,
  211 + ) =>
  212 + dispatch(
  213 + ios: () => _api.uploadFile(filePath, resourceType),
  214 + ohos: () async {
  215 + //TODO: - 上传文件(头像)
  216 + return null;
  217 + });
  218 +
  219 + Future<String?> performCropImage(
  220 + String imageUrl,
  221 + int? maxKB,
  222 + int? width,
  223 + int? height,
  224 + ) =>
  225 + dispatch(
  226 + ios: () => _api.performCropImage(imageUrl, maxKB, width, height),
  227 + ohos: () async {
  228 + return null;
  229 + });
  230 +
  231 + Future<bool> sendLocalNotification(
  232 + int dataType,
  233 + int dateTime,
  234 + String title,
  235 + String content,
  236 + String link,
  237 + ) =>
  238 + dispatch(
  239 + ios: () => _api.sendLocalNotification(
  240 + dataType, dateTime, title, content, link),
  241 + ohos: () async {
  242 + //TODO: - 发送本地通知
  243 + return false;
  244 + });
  245 +}
  246 +
  247 +class AppHealthKitHostApi extends _AppPigeonApiFacade {
  248 + AppHealthKitHostApi({
  249 + health_kit.HealthKitHostApi? api,
  250 + super.appPlatform,
  251 + super.platformProvider,
  252 + }) : _api = api ?? health_kit.HealthKitHostApi();
  253 +
  254 + final health_kit.HealthKitHostApi _api;
  255 +
  256 + Future<health_kit.HealthAuthorization> checkHealthAppAuthorization() =>
  257 + dispatch(
  258 + ios: () => _api.checkHealthAppAuthorization(),
  259 + ohos: () async {
  260 + //TODO: - 检查华为健康授权状态
  261 + return health_kit.HealthAuthorization(status: -1, hasData: false);
  262 + });
  263 +
  264 + Future<bool> requestHealthClientAuthorization() => dispatch(
  265 + ios: () => _api.requestHealthClientAuthorization(),
  266 + ohos: () async {
  267 + //TODO: - 请求华为健康授权
  268 + return false;
  269 + });
  270 +}
  271 +
  272 +class AppHealthKitRawDataHostApi extends _AppPigeonApiFacade {
  273 + AppHealthKitRawDataHostApi({
  274 + health_raw.HealthKitRawDataHostApi? api,
  275 + super.appPlatform,
  276 + super.platformProvider,
  277 + }) : _api = api ?? health_raw.HealthKitRawDataHostApi();
  278 +
  279 + final health_raw.HealthKitRawDataHostApi _api;
  280 +
  281 + Future<bool> hasHealthData() => dispatch(ios: () => _api.hasHealthData());
  282 +
  283 + Future<List<health_raw.HealthKitRawDataPoint>> getHealthKitRawData(
  284 + int dataType,
  285 + int startTime,
  286 + int endTime,
  287 + ) =>
  288 + dispatch(
  289 + ios: () => _api.getHealthKitRawData(dataType, startTime, endTime),
  290 + ohos: () async {
  291 + //TODO: - 获取华为健康原始数据
  292 + return [];
  293 + },
  294 + );
  295 +
  296 + Future<bool> performHealthDataUpload() => dispatch(
  297 + ios: () => _api.performHealthDataUpload(),
  298 + ohos: () async {
  299 + return false;
  300 + });
  301 +
  302 + Future<bool> syncDatabase({
  303 + required String hrDataPath,
  304 + required String hrvDataPath,
  305 + required String sleepDataPath,
  306 + required String avgRealtimeStressDataPath,
  307 + }) =>
  308 + dispatch(
  309 + ios: () => _api.syncDatabase(
  310 + hrDataPath: hrDataPath,
  311 + hrvDataPath: hrvDataPath,
  312 + sleepDataPath: sleepDataPath,
  313 + avgRealtimeStressDataPath: avgRealtimeStressDataPath,
  314 + ),
  315 + ohos: () async {
  316 + return false;
  317 + });
  318 +
  319 + Future<int> performHRDataUpload({required String sqliteFilePath}) => dispatch(
  320 + ios: () => _api.performHRDataUpload(sqliteFilePath: sqliteFilePath),
  321 + ohos: () async {
  322 + //TODO: - 上传HR数据
  323 + return 0;
  324 + });
  325 +
  326 + Future<int> performHRVDataUpload({required String sqliteFilePath}) =>
  327 + dispatch(
  328 + ios: () => _api.performHRVDataUpload(sqliteFilePath: sqliteFilePath),
  329 + ohos: () async {
  330 + //TODO: - 上传HRV数据
  331 + return 0;
  332 + });
  333 +
  334 + Future<int> performSleepAnalysisDataUpload(
  335 + {required String sqliteFilePath}) =>
  336 + dispatch(
  337 + ios: () => _api.performSleepAnalysisDataUpload(
  338 + sqliteFilePath: sqliteFilePath,
  339 + ),
  340 + ohos: () async {
  341 + //TODO: - 上传睡眠数据
  342 + return 0;
  343 + });
  344 +
  345 + Future<int> performAvgRealtimeStressDataUpload({
  346 + required String sqliteFilePath,
  347 + }) =>
  348 + dispatch(
  349 + ios: () => _api.performAvgRealtimeStressDataUpload(
  350 + sqliteFilePath: sqliteFilePath,
  351 + ),
  352 + ohos: () async {
  353 + //TODO: - 上传平均实时压力数据
  354 + return 0;
  355 + });
  356 +
  357 + Future<List<health_raw.HealthKitRawSleepDataPoint>> getHealthKitRawSleepData(
  358 + int startTime,
  359 + int endTime,
  360 + ) =>
  361 + dispatch(
  362 + ios: () => _api.getHealthKitRawSleepData(startTime, endTime),
  363 + ohos: () async {
  364 + //TODO: - 获取华为健康原始睡眠数据
  365 + return [];
  366 + });
  367 +
  368 + Future<List<health_raw.HealthKitRawActivityDataPoint>>
  369 + getHealthKitRawActivityData(
  370 + int startTime,
  371 + int endTime,
  372 + ) =>
  373 + dispatch(
  374 + ios: () => _api.getHealthKitRawActivityData(startTime, endTime),
  375 + ohos: () async {
  376 + //TODO: - 获取华为健康原始活动数据
  377 + return [];
  378 + });
  379 +
  380 + Future<List<health_raw.HealthKitRawWorkoutDataPoint>>
  381 + getHealthKitRawWorkoutData(
  382 + int startTime,
  383 + int endTime,
  384 + ) =>
  385 + dispatch(
  386 + ios: () => _api.getHealthKitRawWorkoutData(startTime, endTime),
  387 + ohos: () async {
  388 + //TODO: - 获取华为健康原始锻炼数据
  389 + return [];
  390 + });
  391 +
  392 + Future<bool> saveNativeCallFlutterChange({
  393 + required List<int> relativeDataTypes,
  394 + }) =>
  395 + dispatch(
  396 + ios: () => _api.saveNativeCallFlutterChange(
  397 + relativeDataTypes: relativeDataTypes,
  398 + ),
  399 + ohos: () => Future.value(false),
  400 + );
  401 +
  402 + Future<bool> saveFlutterCaculateFinished({
  403 + required List<int> relativeDataTypes,
  404 + }) =>
  405 + dispatch(
  406 + ios: () => _api.saveFlutterCaculateFinished(
  407 + relativeDataTypes: relativeDataTypes,
  408 + ),
  409 + ohos: () => Future.value(false),
  410 + );
  411 +
  412 + Future<bool> saveLocalNotificationRecord({
  413 + required String notificationType,
  414 + required int timestamp,
  415 + }) =>
  416 + dispatch(
  417 + ios: () => _api.saveLocalNotificationRecord(
  418 + notificationType: notificationType,
  419 + timestamp: timestamp,
  420 + ),
  421 + ohos: () => Future.value(false),
  422 + );
  423 +
  424 + Future<bool> shareNativeAppleHealthObserverRecord() => dispatch(
  425 + ios: () => _api.shareNativeAppleHealthObserverRecord(),
  426 + ohos: () => Future.value(false));
  427 +
  428 + Future<bool> saveLocalNotificationDebugEvent({
  429 + required Map<String, Object?> event,
  430 + }) =>
  431 + dispatch(
  432 + ios: () => _api.saveLocalNotificationDebugEvent(event: event),
  433 + ohos: () => Future.value(false));
  434 +
  435 + Future<bool> shareFlutterObserverRecord() => dispatch(
  436 + ios: () => _api.shareFlutterObserverRecord(),
  437 + ohos: () => Future.value(false));
  438 +
  439 + Future<bool> shareLocalNotificationDebugRecord() => dispatch(
  440 + ios: () => _api.shareLocalNotificationDebugRecord(),
  441 + ohos: () => Future.value(false));
  442 +
  443 + Future<bool> shareUploadTaskRecord() => dispatch(
  444 + ios: () => _api.shareUploadTaskRecord(), ohos: () => Future.value(false));
  445 +}
  446 +
  447 +class AppWearEngineHostApi extends _AppPigeonApiFacade {
  448 + AppWearEngineHostApi({
  449 + wear.WearEngineHostApi? api,
  450 + super.appPlatform,
  451 + super.platformProvider,
  452 + }) : _api = api ?? wear.WearEngineHostApi();
  453 +
  454 + final wear.WearEngineHostApi _api;
  455 +
  456 + Future<bool> hasAvailableDevices() => dispatch(
  457 + ios: () => _api.hasAvailableDevices(), ohos: () => Future.value(false));
  458 +
  459 + Future<wear.WearDeviceInfo?> checkConnectedDevice() => dispatch(
  460 + ios: () => _api.checkConnectedDevice(), ohos: () => Future.value(null));
  461 +
  462 + Future<bool> registerMessageReceiver() => dispatch(
  463 + ios: () => _api.registerMessageReceiver(),
  464 + ohos: () => Future.value(false));
  465 +
  466 + Future<bool> sendTextMessage(String message) => dispatch(
  467 + ios: () => _api.sendTextMessage(message),
  468 + ohos: () => Future.value(false));
  469 +
  470 + Future<bool> addWatchSurface() => dispatch(
  471 + ios: () => _api.addWatchSurface(), ohos: () => Future.value(false));
  472 +
  473 + Future<bool> syncWatchTheme(wear.WatchTransformTheme? theme) => dispatch(
  474 + ios: () => _api.syncWatchTheme(theme), ohos: () => Future.value(false));
  475 +
  476 + Future<String?> removeBackground(String originImagePath) => dispatch(
  477 + ios: () => _api.removeBackground(originImagePath),
  478 + ohos: () => Future.value(null));
  479 +
  480 + Future<bool> hasInstalledWatchSurface() => dispatch(
  481 + ios: () => _api.hasInstalledWatchSurface(),
  482 + ohos: () => Future.value(false));
  483 +}
@@ -117,62 +117,6 @@ class HealthKitHostApi { @@ -117,62 +117,6 @@ class HealthKitHostApi {
117 117
118 final String pigeonVar_messageChannelSuffix; 118 final String pigeonVar_messageChannelSuffix;
119 119
120 - Future<String> getHealthServerAuthUrl() async {  
121 - final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.getHealthServerAuthUrl$pigeonVar_messageChannelSuffix';  
122 - final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(  
123 - pigeonVar_channelName,  
124 - pigeonChannelCodec,  
125 - binaryMessenger: pigeonVar_binaryMessenger,  
126 - );  
127 - final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);  
128 - final List<Object?>? pigeonVar_replyList =  
129 - await pigeonVar_sendFuture as List<Object?>?;  
130 - if (pigeonVar_replyList == null) {  
131 - throw _createConnectionError(pigeonVar_channelName);  
132 - } else if (pigeonVar_replyList.length > 1) {  
133 - throw PlatformException(  
134 - code: pigeonVar_replyList[0]! as String,  
135 - message: pigeonVar_replyList[1] as String?,  
136 - details: pigeonVar_replyList[2],  
137 - );  
138 - } else if (pigeonVar_replyList[0] == null) {  
139 - throw PlatformException(  
140 - code: 'null-error',  
141 - message: 'Host platform returned null value for non-null return value.',  
142 - );  
143 - } else {  
144 - return (pigeonVar_replyList[0] as String?)!;  
145 - }  
146 - }  
147 -  
148 - Future<bool> cancelHealthAppAuthorization() async {  
149 - final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.cancelHealthAppAuthorization$pigeonVar_messageChannelSuffix';  
150 - final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(  
151 - pigeonVar_channelName,  
152 - pigeonChannelCodec,  
153 - binaryMessenger: pigeonVar_binaryMessenger,  
154 - );  
155 - final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);  
156 - final List<Object?>? pigeonVar_replyList =  
157 - await pigeonVar_sendFuture as List<Object?>?;  
158 - if (pigeonVar_replyList == null) {  
159 - throw _createConnectionError(pigeonVar_channelName);  
160 - } else if (pigeonVar_replyList.length > 1) {  
161 - throw PlatformException(  
162 - code: pigeonVar_replyList[0]! as String,  
163 - message: pigeonVar_replyList[1] as String?,  
164 - details: pigeonVar_replyList[2],  
165 - );  
166 - } else if (pigeonVar_replyList[0] == null) {  
167 - throw PlatformException(  
168 - code: 'null-error',  
169 - message: 'Host platform returned null value for non-null return value.',  
170 - );  
171 - } else {  
172 - return (pigeonVar_replyList[0] as bool?)!;  
173 - }  
174 - }  
175 -  
176 /// Opens Huawei Health client authorization UI. Returns whether user granted. 120 /// Opens Huawei Health client authorization UI. Returns whether user granted.
177 Future<HealthAuthorization> checkHealthAppAuthorization() async { 121 Future<HealthAuthorization> checkHealthAppAuthorization() async {
178 final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$pigeonVar_messageChannelSuffix'; 122 final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization$pigeonVar_messageChannelSuffix';
  1 +/*
  2 +* // Copyright 2013 The Flutter Authors. All rights reserved.
  3 +*/
  4 +import StandardMessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec';
  5 +import BasicMessageChannel, { Reply } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessageChannel';
  6 +import { BinaryMessenger } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger';
  7 +import MessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/MessageCodec';
  8 +import { ByteBuffer } from '@ohos/flutter_ohos/src/main/ets/util/ByteBuffer';
  9 +
  10 +
  11 +/** Error class for passing custom error details to Flutter via a thrown PlatformException. */
  12 +export class FlutterError implements Error {
  13 +
  14 + /** The error code. */
  15 + public code: string;
  16 +
  17 + /** The error name. */
  18 + public name: string;
  19 +
  20 + /** The error message. */
  21 + public message: string;
  22 + /** The error stack. */
  23 + public stack?: string;
  24 +
  25 + constructor(code: string, name: string, message: string, stack?: string) {
  26 + this.code = code;
  27 + this.name = name;
  28 + this.message = message;
  29 + this.stack = stack;
  30 + }
  31 +}
  32 +
  33 +function wrapError(error: Error): Array<Object | null> {
  34 + let errorList: Array<Object | null> = new Array<Object | null>(3);
  35 + if (error instanceof FlutterError) {
  36 + let err: FlutterError = error as FlutterError;
  37 + errorList[0] = err.code;
  38 + errorList[1] = err.name;
  39 + errorList[2] = err.message;
  40 + } else {
  41 + errorList[0] = error.toString();
  42 + errorList[1] = error.name;
  43 + errorList[2] = "Cause: " + error.message + ", Stacktrace: " + error.stack;
  44 + }
  45 + return errorList;
  46 +}
  47 +
  48 +/* Generated class from Pigeon that represents data sent in messages.*/
  49 +export class HealthAuthorization {
  50 + private status: number;
  51 +
  52 + public setStatus(status: number): void {
  53 + this.status = status;
  54 + }
  55 +
  56 + getStatus(): number {
  57 + return this.status;
  58 + }
  59 +
  60 + private hasData: boolean;
  61 +
  62 + public setHasData(hasData: boolean): void {
  63 + this.hasData = hasData;
  64 + }
  65 +
  66 + getHasData(): boolean {
  67 + return this.hasData;
  68 + }
  69 +
  70 + constructor(status: number, hasData: boolean) {
  71 + this.status = status;
  72 + this.hasData = hasData;
  73 + }
  74 +
  75 + toList(): Array<Object | null> {
  76 + let arr: Array<Object | null> = new Array<Object | null>();
  77 + if (this.status === undefined || this.status === null) {
  78 + arr.push(null);
  79 + } else {
  80 + arr.push(this.status);
  81 + }
  82 + if (this.hasData === undefined || this.hasData === null) {
  83 + arr.push(null);
  84 + } else {
  85 + arr.push(this.hasData);
  86 + }
  87 + return arr;
  88 + }
  89 +
  90 + static fromList(arr: Object[]): HealthAuthorization {
  91 + let statusObject: Object = arr[0];
  92 + const status: number = statusObject as number;
  93 + let hasDataObject: Object = arr[1];
  94 + const hasData: boolean = hasDataObject as boolean;
  95 + return new HealthAuthorization(status, hasData);
  96 + }
  97 +}
  98 +
  99 +export class PigeonCodec extends StandardMessageCodec {
  100 + static readonly INSTANCE: PigeonCodec = new PigeonCodec();
  101 +
  102 + getByte(n: number): number {
  103 + let byteArray = new Uint8Array(1);
  104 + byteArray[0] = n;
  105 + return byteArray[0] as number;
  106 + }
  107 + private constructor() {
  108 + super();
  109 + }
  110 +
  111 + readValueOfType(type: number, buffer: ByteBuffer): ESObject {
  112 + switch (type) {
  113 + case this.getByte(129):
  114 + return HealthAuthorization.fromList(super.readValue(buffer) as Object[]);
  115 + default:
  116 + return super.readValueOfType(type, buffer);
  117 + }
  118 + }
  119 +
  120 + writeValue(stream: ByteBuffer, value: ESObject): ESObject {
  121 + if (value instanceof HealthAuthorization) {
  122 + stream.writeUint8(this.getByte(129));
  123 + this.writeValue(stream, (value as HealthAuthorization).toList());
  124 + } else {
  125 + super.writeValue(stream, value);
  126 + }
  127 + }
  128 +}
  129 +
  130 +
  131 +export interface Result<T> {
  132 + success(result: T): void;
  133 +
  134 + error(error: Error): void;
  135 +}
  136 +/* Generated abstract class from Pigeon that represents a handler of messages from Flutter.*/
  137 +export abstract class HealthKitHostApi {
  138 + /* Opens Huawei Health client authorization UI. Returns whether user granted.*/
  139 + abstract checkHealthAppAuthorization(result: Result<HealthAuthorization>): void;
  140 +
  141 + abstract requestHealthClientAuthorization(result: Result<boolean>): void;
  142 + /** The codec used by HealthKitHostApi. */
  143 + static getCodec(): MessageCodec<Object> {
  144 + return PigeonCodec.INSTANCE;
  145 + }
  146 + /*Sets up an instance of `HealthKitHostApi` to handle messages through the `binaryMessenger`.*/
  147 + static setup(binaryMessenger: BinaryMessenger, api: HealthKitHostApi | null, messageChannelSuffix: string = ''): void {
  148 + const separatedMessageChannelSuffix: string = messageChannelSuffix !== '' ? '.' + messageChannelSuffix : '';
  149 + {
  150 + let channel: BasicMessageChannel<Object> =
  151 + new BasicMessageChannel(
  152 + binaryMessenger, 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization' + separatedMessageChannelSuffix, HealthKitHostApi.getCodec());
  153 + if (api != null) {
  154 + channel.setMessageHandler({
  155 + onMessage(message: Object, reply: Reply<Object>) {
  156 + class ResultImp implements Result<HealthAuthorization>{
  157 + success(result: HealthAuthorization): void {
  158 + let res: Array<Object | null> = [];
  159 + res.push(result);
  160 + reply.reply(res);
  161 + }
  162 +
  163 + error(error: Error): void {
  164 + let wrappedError: Array<Object | null> = wrapError(error);
  165 + reply.reply(wrappedError);
  166 + }
  167 + }
  168 + let resultCallback: Result<HealthAuthorization> = new ResultImp();
  169 +
  170 + api!.checkHealthAppAuthorization(resultCallback);
  171 + } });
  172 + } else {
  173 + channel.setMessageHandler(null);
  174 + }
  175 + }
  176 + {
  177 + let channel: BasicMessageChannel<Object> =
  178 + new BasicMessageChannel(
  179 + binaryMessenger, 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.requestHealthClientAuthorization' + separatedMessageChannelSuffix, HealthKitHostApi.getCodec());
  180 + if (api != null) {
  181 + channel.setMessageHandler({
  182 + onMessage(message: Object, reply: Reply<Object>) {
  183 + class ResultImp implements Result<boolean>{
  184 + success(result: boolean): void {
  185 + let res: Array<Object | null> = [];
  186 + res.push(result);
  187 + reply.reply(res);
  188 + }
  189 +
  190 + error(error: Error): void {
  191 + let wrappedError: Array<Object | null> = wrapError(error);
  192 + reply.reply(wrappedError);
  193 + }
  194 + }
  195 + let resultCallback: Result<boolean> = new ResultImp();
  196 +
  197 + api!.requestHealthClientAuthorization(resultCallback);
  198 + } });
  199 + } else {
  200 + channel.setMessageHandler(null);
  201 + }
  202 + }
  203 + }
  204 +}
@@ -27,15 +27,6 @@ class HealthAuthorization { @@ -27,15 +27,6 @@ class HealthAuthorization {
27 ) 27 )
28 @HostApi() 28 @HostApi()
29 abstract class HealthKitHostApi { 29 abstract class HealthKitHostApi {
30 - // @optional  
31 -  
32 - @async  
33 - String getHealthServerAuthUrl();  
34 -  
35 - bool cancelHealthAppAuthorization();  
36 -  
37 -  
38 -// @required  
39 30
40 /// Opens Huawei Health client authorization UI. Returns whether user granted. 31 /// Opens Huawei Health client authorization UI. Returns whether user granted.
41 @async 32 @async
@@ -43,87 +34,4 @@ abstract class HealthKitHostApi { @@ -43,87 +34,4 @@ abstract class HealthKitHostApi {
43 34
44 @async 35 @async
45 bool requestHealthClientAuthorization(); 36 bool requestHealthClientAuthorization();
46 -  
47 -/*  
48 -  
49 - ///测试使用- 导出本地存储的observer日志  
50 - @async  
51 - bool exportHealthObserverRecord();  
52 -  
53 - /// Runs native health read and server upload pipeline.  
54 - @async  
55 - HealthUploadResult performHealthUpload();  
56 -  
57 - @async  
58 - List<HealthUploadDataPoint> fetchHrvData(int startTime, int endTime);  
59 -  
60 - @async  
61 - List<HealthUploadDataPoint> fetchHeartRateData(int startTime, int endTime);  
62 -  
63 - @async  
64 - List<HealthUploadDataPoint> fetchWalkingHeartRateData(  
65 - int startTime,  
66 - int endTime,  
67 - );  
68 -  
69 - @async  
70 - List<HealthUploadDataPoint> fetchRestingHeartRateData(  
71 - int startTime,  
72 - int endTime,  
73 - );  
74 -  
75 - @async  
76 - List<HealthUploadDataPoint> fetchSleepingHeartRateData(  
77 - int startTime,  
78 - int endTime,  
79 - );  
80 -  
81 - @async  
82 - List<HealthUploadDataPoint> fetchOxygenSaturationData(  
83 - int startTime,  
84 - int endTime,  
85 - );  
86 -  
87 - @async  
88 - List<HealthUploadDataPoint> fetchActiveEnergyData(  
89 - int startTime,  
90 - int endTime,  
91 - );  
92 -  
93 - @async  
94 - List<HealthUploadDataPoint> fetchExerciseData(int startTime, int endTime);  
95 -  
96 - @async  
97 - List<HealthUploadDataPoint> fetchStandData(int startTime, int endTime);  
98 -  
99 - @async  
100 - List<HealthUploadDataPoint> fetchStepCountData(int startTime, int endTime);  
101 -  
102 - @async  
103 - List<HealthSleepUploadDataPoint> fetchSleepData(int startTime, int endTime);  
104 -  
105 - @async  
106 - List<HealthUploadDataPoint> fetchSleepingWristTemperatureData(  
107 - int startTime,  
108 - int endTime,  
109 - );  
110 -  
111 - @async  
112 - List<HealthUploadDataPoint> fetchRespiratoryRateData(  
113 - int startTime,  
114 - int endTime,  
115 - );  
116 -  
117 - @async  
118 - List<HealthUploadDataPoint> fetchIrregularHeartRhythmData(  
119 - int startTime,  
120 - int endTime,  
121 - );  
122 -  
123 - @async  
124 - HealthActivityTargetData? fetchActivityTargetData(  
125 - int startTime,  
126 - int endTime,  
127 - );  
128 - */  
129 } 37 }