|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:doublefeel_flutter/pigeon/alipay_api.g.dart' as alipay;
|
|
|
|
import 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart' as health_kit;
|
|
|
|
import 'package:doublefeel_flutter/pigeon/health_kit_raw_data_api.g.dart'
|
|
|
|
as health_raw;
|
|
|
|
import 'package:doublefeel_flutter/pigeon/platform_api.g.dart' as platform;
|
|
|
|
import 'package:doublefeel_flutter/pigeon/wear_engine_api.g.dart' as wear;
|
|
|
|
|
|
|
|
export 'package:doublefeel_flutter/pigeon/alipay_api.g.dart';
|
|
|
|
export 'package:doublefeel_flutter/pigeon/health_kit_api.g.dart';
|
|
|
|
export 'package:doublefeel_flutter/pigeon/health_kit_raw_data_api.g.dart';
|
|
|
|
export 'package:doublefeel_flutter/pigeon/platform_api.g.dart';
|
|
|
|
export 'package:doublefeel_flutter/pigeon/wear_engine_api.g.dart';
|
|
|
|
|
|
|
|
enum AppPigeonPlatform { ios, android, ohos }
|
|
|
|
|
|
|
|
typedef AppPigeonPlatformProvider = AppPigeonPlatform Function();
|
|
|
|
|
|
|
|
AppPigeonPlatform resolveAppPigeonPlatform({TargetPlatform? targetPlatform}) {
|
|
|
|
final platform = targetPlatform ?? defaultTargetPlatform;
|
|
|
|
if (platform.name == 'ohos') {
|
|
|
|
return AppPigeonPlatform.ohos;
|
|
|
|
}
|
|
|
|
if (platform == TargetPlatform.iOS) {
|
|
|
|
return AppPigeonPlatform.ios;
|
|
|
|
}
|
|
|
|
return AppPigeonPlatform.android;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class _AppPigeonApiFacade {
|
|
|
|
_AppPigeonApiFacade({
|
|
|
|
AppPigeonPlatform? appPlatform,
|
|
|
|
AppPigeonPlatformProvider? platformProvider,
|
|
|
|
}) : _platformProvider = platformProvider ??
|
|
|
|
(() => appPlatform ?? resolveAppPigeonPlatform());
|
|
|
|
|
|
|
|
final AppPigeonPlatformProvider _platformProvider;
|
|
|
|
|
|
|
|
AppPigeonPlatform get appPigeonPlatform => _platformProvider();
|
|
|
|
|
|
|
|
Future<T> dispatch<T>({
|
|
|
|
required Future<T> Function() ios,
|
|
|
|
Future<T> Function()? android,
|
|
|
|
Future<T> Function()? ohos,
|
|
|
|
}) {
|
|
|
|
return switch (appPigeonPlatform) {
|
|
|
|
AppPigeonPlatform.ios => ios(),
|
|
|
|
AppPigeonPlatform.android => (android ?? ios)(),
|
|
|
|
AppPigeonPlatform.ohos => (ohos ?? android ?? ios)(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AppPlatformHostApi extends _AppPigeonApiFacade {
|
|
|
|
AppPlatformHostApi({
|
|
|
|
platform.PlatformHostApi? api,
|
|
|
|
super.appPlatform,
|
|
|
|
super.platformProvider,
|
|
|
|
}) : _api = api ?? platform.PlatformHostApi();
|
|
|
|
|
|
|
|
final platform.PlatformHostApi _api;
|
|
|
|
|
|
|
|
Future<String> getFullUserAgent() => dispatch(
|
|
|
|
ios: () => _api.getFullUserAgent(),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 组装agent
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> isChinaRegion() => dispatch(
|
|
|
|
ios: () => _api.isChinaRegion(),
|
|
|
|
ohos: () async {
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<int> getApnsAuthStatus() => dispatch(
|
|
|
|
ios: () => _api.getApnsAuthStatus(),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 检查通知权限
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> requestNotificationAuth() => dispatch(
|
|
|
|
ios: () => _api.requestNotificationAuth(),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 请求通知权限
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> isDebugEnvoriment() => dispatch(
|
|
|
|
ios: () => _api.isDebugEnvoriment(),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> shareText(String text) => dispatch(
|
|
|
|
ios: () => _api.shareText(text),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 分享文本(配对信息)
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> shareFileData(Uint8List databytes) => dispatch(
|
|
|
|
ios: () => _api.shareFileData(databytes),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<void> updateLoginInfo(String jsonString, String baseUrl) => dispatch(
|
|
|
|
ios: () => _api.updateLoginInfo(jsonString, baseUrl),
|
|
|
|
ohos: () async {
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<void> logout() => dispatch(
|
|
|
|
ios: () => _api.logout(),
|
|
|
|
ohos: () async {
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<void> refreshVip() => dispatch(
|
|
|
|
ios: () => _api.refreshVip(),
|
|
|
|
ohos: () async {
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<void> refreshWatchAppAndWidgets() => dispatch(
|
|
|
|
ios: () => _api.refreshWatchAppAndWidgets(),
|
|
|
|
ohos: () async {
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> requestAppReview() => dispatch(
|
|
|
|
ios: () => _api.requestAppReview(),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> jumpAppSetting() => dispatch(
|
|
|
|
ios: () => _api.jumpAppSetting(),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> nativeHandleUrl(String urlString) => dispatch(
|
|
|
|
ios: () => _api.nativeHandleUrl(urlString),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 处理url跳转
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<String?> requestUnhandedUrl() => dispatch(
|
|
|
|
ios: () => _api.requestUnhandedUrl(),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 请求未处理的url(通知点击启动app后,启动flutter引擎交给flutter处理url)
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<platform.AppleSignInModel?> requestAppleSignIn() => dispatch(
|
|
|
|
ios: () => _api.requestAppleSignIn(),
|
|
|
|
ohos: () async {
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<platform.GoogleSignInModel?> requestGoogleSignIn() => dispatch(
|
|
|
|
ios: () => _api.requestGoogleSignIn(),
|
|
|
|
ohos: () async {
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> sendEmail(String mailTo, String title, String content) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.sendEmail(mailTo, title, content),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 发送邮件
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<platform.AppleProductInfo?> requestAppleProductInfo(
|
|
|
|
String productId,
|
|
|
|
int baseUnit,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.requestAppleProductInfo(productId, baseUnit),
|
|
|
|
ohos: () async {
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<platform.AppleProductPaymentResult?> performApplePayment(
|
|
|
|
String productId,
|
|
|
|
String uuid,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.performApplePayment(productId, uuid),
|
|
|
|
ohos: () async {
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> performRestore() => dispatch(
|
|
|
|
ios: () => _api.performRestore(),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<String?> uploadFile(
|
|
|
|
String filePath,
|
|
|
|
platform.HResourceType resourceType,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.uploadFile(filePath, resourceType),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 上传文件(头像)
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<String?> performCropImage(
|
|
|
|
String imageUrl,
|
|
|
|
int? maxKB,
|
|
|
|
int? width,
|
|
|
|
int? height,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.performCropImage(imageUrl, maxKB, width, height),
|
|
|
|
ohos: () async {
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> sendLocalNotification(
|
|
|
|
int dataType,
|
|
|
|
int dateTime,
|
|
|
|
String title,
|
|
|
|
String content,
|
|
|
|
String link,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.sendLocalNotification(
|
|
|
|
dataType, dateTime, title, content, link),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 发送本地通知
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class AppHealthKitHostApi extends _AppPigeonApiFacade {
|
|
|
|
AppHealthKitHostApi({
|
|
|
|
health_kit.HealthKitHostApi? api,
|
|
|
|
super.appPlatform,
|
|
|
|
super.platformProvider,
|
|
|
|
}) : _api = api ?? health_kit.HealthKitHostApi();
|
|
|
|
|
|
|
|
final health_kit.HealthKitHostApi _api;
|
|
|
|
|
|
|
|
Future<health_kit.HealthAuthorization> checkHealthAppAuthorization() =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.checkHealthAppAuthorization(),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 检查华为健康授权状态
|
|
|
|
return health_kit.HealthAuthorization(status: -1, hasData: false);
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> requestHealthClientAuthorization() => dispatch(
|
|
|
|
ios: () => _api.requestHealthClientAuthorization(),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 请求华为健康授权
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class AppHealthKitRawDataHostApi extends _AppPigeonApiFacade {
|
|
|
|
AppHealthKitRawDataHostApi({
|
|
|
|
health_raw.HealthKitRawDataHostApi? api,
|
|
|
|
super.appPlatform,
|
|
|
|
super.platformProvider,
|
|
|
|
}) : _api = api ?? health_raw.HealthKitRawDataHostApi();
|
|
|
|
|
|
|
|
final health_raw.HealthKitRawDataHostApi _api;
|
|
|
|
|
|
|
|
Future<bool> hasHealthData() => dispatch(ios: () => _api.hasHealthData());
|
|
|
|
|
|
|
|
Future<List<health_raw.HealthKitRawDataPoint>> getHealthKitRawData(
|
|
|
|
int dataType,
|
|
|
|
int startTime,
|
|
|
|
int endTime,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.getHealthKitRawData(dataType, startTime, endTime),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 获取华为健康原始数据
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> performHealthDataUpload() => dispatch(
|
|
|
|
ios: () => _api.performHealthDataUpload(),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> syncDatabase({
|
|
|
|
required String hrDataPath,
|
|
|
|
required String hrvDataPath,
|
|
|
|
required String sleepDataPath,
|
|
|
|
required String avgRealtimeStressDataPath,
|
|
|
|
}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.syncDatabase(
|
|
|
|
hrDataPath: hrDataPath,
|
|
|
|
hrvDataPath: hrvDataPath,
|
|
|
|
sleepDataPath: sleepDataPath,
|
|
|
|
avgRealtimeStressDataPath: avgRealtimeStressDataPath,
|
|
|
|
),
|
|
|
|
ohos: () async {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<int> performHRDataUpload({required String sqliteFilePath}) => dispatch(
|
|
|
|
ios: () => _api.performHRDataUpload(sqliteFilePath: sqliteFilePath),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 上传HR数据
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<int> performHRVDataUpload({required String sqliteFilePath}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.performHRVDataUpload(sqliteFilePath: sqliteFilePath),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 上传HRV数据
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<int> performSleepAnalysisDataUpload(
|
|
|
|
{required String sqliteFilePath}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.performSleepAnalysisDataUpload(
|
|
|
|
sqliteFilePath: sqliteFilePath,
|
|
|
|
),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 上传睡眠数据
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<int> performAvgRealtimeStressDataUpload({
|
|
|
|
required String sqliteFilePath,
|
|
|
|
}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.performAvgRealtimeStressDataUpload(
|
|
|
|
sqliteFilePath: sqliteFilePath,
|
|
|
|
),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 上传平均实时压力数据
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<List<health_raw.HealthKitRawSleepDataPoint>> getHealthKitRawSleepData(
|
|
|
|
int startTime,
|
|
|
|
int endTime,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.getHealthKitRawSleepData(startTime, endTime),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 获取华为健康原始睡眠数据
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<List<health_raw.HealthKitRawActivityDataPoint>>
|
|
|
|
getHealthKitRawActivityData(
|
|
|
|
int startTime,
|
|
|
|
int endTime,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.getHealthKitRawActivityData(startTime, endTime),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 获取华为健康原始活动数据
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<List<health_raw.HealthKitRawWorkoutDataPoint>>
|
|
|
|
getHealthKitRawWorkoutData(
|
|
|
|
int startTime,
|
|
|
|
int endTime,
|
|
|
|
) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.getHealthKitRawWorkoutData(startTime, endTime),
|
|
|
|
ohos: () async {
|
|
|
|
//TODO: - 获取华为健康原始锻炼数据
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<bool> saveNativeCallFlutterChange({
|
|
|
|
required List<int> relativeDataTypes,
|
|
|
|
}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.saveNativeCallFlutterChange(
|
|
|
|
relativeDataTypes: relativeDataTypes,
|
|
|
|
),
|
|
|
|
ohos: () => Future.value(false),
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> saveFlutterCaculateFinished({
|
|
|
|
required List<int> relativeDataTypes,
|
|
|
|
}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.saveFlutterCaculateFinished(
|
|
|
|
relativeDataTypes: relativeDataTypes,
|
|
|
|
),
|
|
|
|
ohos: () => Future.value(false),
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> saveLocalNotificationRecord({
|
|
|
|
required String notificationType,
|
|
|
|
required int timestamp,
|
|
|
|
}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.saveLocalNotificationRecord(
|
|
|
|
notificationType: notificationType,
|
|
|
|
timestamp: timestamp,
|
|
|
|
),
|
|
|
|
ohos: () => Future.value(false),
|
|
|
|
);
|
|
|
|
|
|
|
|
Future<bool> shareNativeAppleHealthObserverRecord() => dispatch(
|
|
|
|
ios: () => _api.shareNativeAppleHealthObserverRecord(),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> saveLocalNotificationDebugEvent({
|
|
|
|
required Map<String, Object?> event,
|
|
|
|
}) =>
|
|
|
|
dispatch(
|
|
|
|
ios: () => _api.saveLocalNotificationDebugEvent(event: event),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> shareFlutterObserverRecord() => dispatch(
|
|
|
|
ios: () => _api.shareFlutterObserverRecord(),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> shareLocalNotificationDebugRecord() => dispatch(
|
|
|
|
ios: () => _api.shareLocalNotificationDebugRecord(),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> shareUploadTaskRecord() => dispatch(
|
|
|
|
ios: () => _api.shareUploadTaskRecord(), ohos: () => Future.value(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
class AppWearEngineHostApi extends _AppPigeonApiFacade {
|
|
|
|
AppWearEngineHostApi({
|
|
|
|
wear.WearEngineHostApi? api,
|
|
|
|
super.appPlatform,
|
|
|
|
super.platformProvider,
|
|
|
|
}) : _api = api ?? wear.WearEngineHostApi();
|
|
|
|
|
|
|
|
final wear.WearEngineHostApi _api;
|
|
|
|
|
|
|
|
Future<bool> hasAvailableDevices() => dispatch(
|
|
|
|
ios: () => _api.hasAvailableDevices(), ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<wear.WearDeviceInfo?> checkConnectedDevice() => dispatch(
|
|
|
|
ios: () => _api.checkConnectedDevice(), ohos: () => Future.value(null));
|
|
|
|
|
|
|
|
Future<bool> registerMessageReceiver() => dispatch(
|
|
|
|
ios: () => _api.registerMessageReceiver(),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> sendTextMessage(String message) => dispatch(
|
|
|
|
ios: () => _api.sendTextMessage(message),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> addWatchSurface() => dispatch(
|
|
|
|
ios: () => _api.addWatchSurface(), ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<bool> syncWatchTheme(wear.WatchTransformTheme? theme) => dispatch(
|
|
|
|
ios: () => _api.syncWatchTheme(theme), ohos: () => Future.value(false));
|
|
|
|
|
|
|
|
Future<String?> removeBackground(String originImagePath) => dispatch(
|
|
|
|
ios: () => _api.removeBackground(originImagePath),
|
|
|
|
ohos: () => Future.value(null));
|
|
|
|
|
|
|
|
Future<bool> hasInstalledWatchSurface() => dispatch(
|
|
|
|
ios: () => _api.hasInstalledWatchSurface(),
|
|
|
|
ohos: () => Future.value(false));
|
|
|
|
} |
...
|
...
|
|