Showing
8 changed files
with
87 additions
and
52 deletions
| @@ -141,6 +141,8 @@ interface WearEngineHostApi { | @@ -141,6 +141,8 @@ interface WearEngineHostApi { | ||
| 141 | fun checkConnectedDevice(): WearDeviceInfo? | 141 | fun checkConnectedDevice(): WearDeviceInfo? |
| 142 | fun registerMessageReceiver(): Boolean | 142 | fun registerMessageReceiver(): Boolean |
| 143 | fun sendTextMessage(message: String): Boolean | 143 | fun sendTextMessage(message: String): Boolean |
| 144 | + /** 添加表盘 */ | ||
| 145 | + fun addWatchSurface(callback: (Result<Boolean>) -> Unit) | ||
| 144 | fun sendWatchSyncPayload(jsonPayload: String, callback: (Result<Boolean>) -> Unit) | 146 | fun sendWatchSyncPayload(jsonPayload: String, callback: (Result<Boolean>) -> Unit) |
| 145 | /** | 147 | /** |
| 146 | * Opens the system photo picker and returns a local PNG file path after | 148 | * Opens the system photo picker and returns a local PNG file path after |
| @@ -222,6 +224,24 @@ interface WearEngineHostApi { | @@ -222,6 +224,24 @@ interface WearEngineHostApi { | ||
| 222 | } | 224 | } |
| 223 | } | 225 | } |
| 224 | run { | 226 | run { |
| 227 | + val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.addWatchSurface$separatedMessageChannelSuffix", codec) | ||
| 228 | + if (api != null) { | ||
| 229 | + channel.setMessageHandler { _, reply -> | ||
| 230 | + api.addWatchSurface{ result: Result<Boolean> -> | ||
| 231 | + val error = result.exceptionOrNull() | ||
| 232 | + if (error != null) { | ||
| 233 | + reply.reply(WearEngineApiPigeonUtils.wrapError(error)) | ||
| 234 | + } else { | ||
| 235 | + val data = result.getOrNull() | ||
| 236 | + reply.reply(WearEngineApiPigeonUtils.wrapResult(data)) | ||
| 237 | + } | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + } else { | ||
| 241 | + channel.setMessageHandler(null) | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + run { | ||
| 225 | val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.sendWatchSyncPayload$separatedMessageChannelSuffix", codec) | 245 | val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.sendWatchSyncPayload$separatedMessageChannelSuffix", codec) |
| 226 | if (api != null) { | 246 | if (api != null) { |
| 227 | channel.setMessageHandler { message, reply -> | 247 | channel.setMessageHandler { message, reply -> |
| @@ -215,66 +215,22 @@ struct HealthSleepUploadDataPoint: Hashable { | @@ -215,66 +215,22 @@ struct HealthSleepUploadDataPoint: Hashable { | ||
| 215 | struct HealthActivityTargetData: Hashable { | 215 | struct HealthActivityTargetData: Hashable { |
| 216 | var move: Int64? = nil | 216 | var move: Int64? = nil |
| 217 | var stand: Int64? = nil | 217 | var stand: Int64? = nil |
| 218 | - var activityMoveMode: Int64? = nil | ||
| 219 | - var activeEnergyBurned: Double? = nil | ||
| 220 | - var activeEnergyBurnedGoal: Double? = nil | ||
| 221 | - var appleMoveTime: Double? = nil | ||
| 222 | - var appleMoveTimeGoal: Double? = nil | ||
| 223 | - var appleExerciseTime: Double? = nil | ||
| 224 | - var appleExerciseTimeGoal: Double? = nil | ||
| 225 | - var exerciseTimeGoal: Double? = nil | ||
| 226 | - var appleStandHours: Double? = nil | ||
| 227 | - var appleStandHoursGoal: Double? = nil | ||
| 228 | - var standHoursGoal: Double? = nil | ||
| 229 | 218 | ||
| 230 | 219 | ||
| 231 | // swift-format-ignore: AlwaysUseLowerCamelCase | 220 | // swift-format-ignore: AlwaysUseLowerCamelCase |
| 232 | static func fromList(_ pigeonVar_list: [Any?]) -> HealthActivityTargetData? { | 221 | static func fromList(_ pigeonVar_list: [Any?]) -> HealthActivityTargetData? { |
| 233 | let move: Int64? = nilOrValue(pigeonVar_list[0]) | 222 | let move: Int64? = nilOrValue(pigeonVar_list[0]) |
| 234 | let stand: Int64? = nilOrValue(pigeonVar_list[1]) | 223 | let stand: Int64? = nilOrValue(pigeonVar_list[1]) |
| 235 | - let activityMoveMode: Int64? = nilOrValue(pigeonVar_list[2]) | ||
| 236 | - let activeEnergyBurned: Double? = nilOrValue(pigeonVar_list[3]) | ||
| 237 | - let activeEnergyBurnedGoal: Double? = nilOrValue(pigeonVar_list[4]) | ||
| 238 | - let appleMoveTime: Double? = nilOrValue(pigeonVar_list[5]) | ||
| 239 | - let appleMoveTimeGoal: Double? = nilOrValue(pigeonVar_list[6]) | ||
| 240 | - let appleExerciseTime: Double? = nilOrValue(pigeonVar_list[7]) | ||
| 241 | - let appleExerciseTimeGoal: Double? = nilOrValue(pigeonVar_list[8]) | ||
| 242 | - let exerciseTimeGoal: Double? = nilOrValue(pigeonVar_list[9]) | ||
| 243 | - let appleStandHours: Double? = nilOrValue(pigeonVar_list[10]) | ||
| 244 | - let appleStandHoursGoal: Double? = nilOrValue(pigeonVar_list[11]) | ||
| 245 | - let standHoursGoal: Double? = nilOrValue(pigeonVar_list[12]) | ||
| 246 | 224 | ||
| 247 | return HealthActivityTargetData( | 225 | return HealthActivityTargetData( |
| 248 | move: move, | 226 | move: move, |
| 249 | - stand: stand, | ||
| 250 | - activityMoveMode: activityMoveMode, | ||
| 251 | - activeEnergyBurned: activeEnergyBurned, | ||
| 252 | - activeEnergyBurnedGoal: activeEnergyBurnedGoal, | ||
| 253 | - appleMoveTime: appleMoveTime, | ||
| 254 | - appleMoveTimeGoal: appleMoveTimeGoal, | ||
| 255 | - appleExerciseTime: appleExerciseTime, | ||
| 256 | - appleExerciseTimeGoal: appleExerciseTimeGoal, | ||
| 257 | - exerciseTimeGoal: exerciseTimeGoal, | ||
| 258 | - appleStandHours: appleStandHours, | ||
| 259 | - appleStandHoursGoal: appleStandHoursGoal, | ||
| 260 | - standHoursGoal: standHoursGoal | 227 | + stand: stand |
| 261 | ) | 228 | ) |
| 262 | } | 229 | } |
| 263 | func toList() -> [Any?] { | 230 | func toList() -> [Any?] { |
| 264 | return [ | 231 | return [ |
| 265 | move, | 232 | move, |
| 266 | stand, | 233 | stand, |
| 267 | - activityMoveMode, | ||
| 268 | - activeEnergyBurned, | ||
| 269 | - activeEnergyBurnedGoal, | ||
| 270 | - appleMoveTime, | ||
| 271 | - appleMoveTimeGoal, | ||
| 272 | - appleExerciseTime, | ||
| 273 | - appleExerciseTimeGoal, | ||
| 274 | - exerciseTimeGoal, | ||
| 275 | - appleStandHours, | ||
| 276 | - appleStandHoursGoal, | ||
| 277 | - standHoursGoal, | ||
| 278 | ] | 234 | ] |
| 279 | } | 235 | } |
| 280 | static func == (lhs: HealthActivityTargetData, rhs: HealthActivityTargetData) -> Bool { | 236 | static func == (lhs: HealthActivityTargetData, rhs: HealthActivityTargetData) -> Bool { |
| @@ -188,6 +188,8 @@ protocol WearEngineHostApi { | @@ -188,6 +188,8 @@ protocol WearEngineHostApi { | ||
| 188 | func checkConnectedDevice() throws -> WearDeviceInfo? | 188 | func checkConnectedDevice() throws -> WearDeviceInfo? |
| 189 | func registerMessageReceiver() throws -> Bool | 189 | func registerMessageReceiver() throws -> Bool |
| 190 | func sendTextMessage(message: String) throws -> Bool | 190 | func sendTextMessage(message: String) throws -> Bool |
| 191 | + /// 添加表盘 | ||
| 192 | + func addWatchSurface(completion: @escaping (Result<Bool, Error>) -> Void) | ||
| 191 | func sendWatchSyncPayload(jsonPayload: String, completion: @escaping (Result<Bool, Error>) -> Void) | 193 | func sendWatchSyncPayload(jsonPayload: String, completion: @escaping (Result<Bool, Error>) -> Void) |
| 192 | /// Opens the system photo picker and returns a local PNG file path after | 194 | /// Opens the system photo picker and returns a local PNG file path after |
| 193 | /// removing the image background on the host platform. | 195 | /// removing the image background on the host platform. |
| @@ -256,6 +258,22 @@ class WearEngineHostApiSetup { | @@ -256,6 +258,22 @@ class WearEngineHostApiSetup { | ||
| 256 | } else { | 258 | } else { |
| 257 | sendTextMessageChannel.setMessageHandler(nil) | 259 | sendTextMessageChannel.setMessageHandler(nil) |
| 258 | } | 260 | } |
| 261 | + /// 添加表盘 | ||
| 262 | + let addWatchSurfaceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.addWatchSurface\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) | ||
| 263 | + if let api = api { | ||
| 264 | + addWatchSurfaceChannel.setMessageHandler { _, reply in | ||
| 265 | + api.addWatchSurface { result in | ||
| 266 | + switch result { | ||
| 267 | + case .success(let res): | ||
| 268 | + reply(wrapResult(res)) | ||
| 269 | + case .failure(let error): | ||
| 270 | + reply(wrapError(error)) | ||
| 271 | + } | ||
| 272 | + } | ||
| 273 | + } | ||
| 274 | + } else { | ||
| 275 | + addWatchSurfaceChannel.setMessageHandler(nil) | ||
| 276 | + } | ||
| 259 | let sendWatchSyncPayloadChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.sendWatchSyncPayload\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) | 277 | let sendWatchSyncPayloadChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.sendWatchSyncPayload\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) |
| 260 | if let api = api { | 278 | if let api = api { |
| 261 | sendWatchSyncPayloadChannel.setMessageHandler { message, reply in | 279 | sendWatchSyncPayloadChannel.setMessageHandler { message, reply in |
| @@ -5,9 +5,14 @@ import Vision | @@ -5,9 +5,14 @@ import Vision | ||
| 5 | 5 | ||
| 6 | enum ImageProcessError: Error{ | 6 | enum ImageProcessError: Error{ |
| 7 | case invalidatePath | 7 | case invalidatePath |
| 8 | + case noWatchFound | ||
| 8 | } | 9 | } |
| 9 | 10 | ||
| 10 | final class WearEngineHostApiImpl: WearEngineHostApi { | 11 | final class WearEngineHostApiImpl: WearEngineHostApi { |
| 12 | + func addWatchSurface(completion: @escaping (Result<Bool, any Error>) -> Void) { | ||
| 13 | + completion(.failure(ImageProcessError.noWatchFound)) | ||
| 14 | + } | ||
| 15 | + | ||
| 11 | func hasInstalledWatchSurface(completion: @escaping (Result<Bool, any Error>) -> Void) { | 16 | func hasInstalledWatchSurface(completion: @escaping (Result<Bool, any Error>) -> Void) { |
| 12 | // iOS does not expose the user's active watch face. The closest | 17 | // iOS does not expose the user's active watch face. The closest |
| 13 | // supported equivalent is a paired Apple Watch with this Watch App installed. | 18 | // supported equivalent is a paired Apple Watch with this Watch App installed. |
| @@ -152,10 +152,11 @@ class CustomWatchThemePreviewController extends GetxController { | @@ -152,10 +152,11 @@ class CustomWatchThemePreviewController extends GetxController { | ||
| 152 | ); | 152 | ); |
| 153 | return; | 153 | return; |
| 154 | } | 154 | } |
| 155 | - | ||
| 156 | - bool success = await PlatformHostApi().nativeHandleUrl("itms-watchs://"); | ||
| 157 | - if (!success) { | ||
| 158 | - await PlatformHostApi().nativeHandleUrl("itms-watch://"); | 155 | + try { |
| 156 | + await WearEngineHostApi().addWatchSurface(); | ||
| 157 | + await PlatformHostApi().nativeHandleUrl("itms-watchs://"); | ||
| 158 | + } catch (e) { | ||
| 159 | + AppToast.show(e.toString()); | ||
| 159 | } | 160 | } |
| 160 | } | 161 | } |
| 161 | 162 |
| @@ -124,9 +124,11 @@ class WatchThemePreviewController extends GetxController { | @@ -124,9 +124,11 @@ class WatchThemePreviewController extends GetxController { | ||
| 124 | return; | 124 | return; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | - bool success = await PlatformHostApi().nativeHandleUrl("itms-watchs://"); | ||
| 128 | - if (!success) { | ||
| 129 | - await PlatformHostApi().nativeHandleUrl("itms-watch://"); | 127 | + try { |
| 128 | + await WearEngineHostApi().addWatchSurface(); | ||
| 129 | + await PlatformHostApi().nativeHandleUrl("itms-watchs://"); | ||
| 130 | + } catch (e) { | ||
| 131 | + AppToast.show(e.toString()); | ||
| 130 | } | 132 | } |
| 131 | } | 133 | } |
| 132 | 134 |
| @@ -228,6 +228,35 @@ class WearEngineHostApi { | @@ -228,6 +228,35 @@ class WearEngineHostApi { | ||
| 228 | } | 228 | } |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | + /// 添加表盘 | ||
| 232 | + Future<bool> addWatchSurface() async { | ||
| 233 | + final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.addWatchSurface$pigeonVar_messageChannelSuffix'; | ||
| 234 | + final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>( | ||
| 235 | + pigeonVar_channelName, | ||
| 236 | + pigeonChannelCodec, | ||
| 237 | + binaryMessenger: pigeonVar_binaryMessenger, | ||
| 238 | + ); | ||
| 239 | + final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null); | ||
| 240 | + final List<Object?>? pigeonVar_replyList = | ||
| 241 | + await pigeonVar_sendFuture as List<Object?>?; | ||
| 242 | + if (pigeonVar_replyList == null) { | ||
| 243 | + throw _createConnectionError(pigeonVar_channelName); | ||
| 244 | + } else if (pigeonVar_replyList.length > 1) { | ||
| 245 | + throw PlatformException( | ||
| 246 | + code: pigeonVar_replyList[0]! as String, | ||
| 247 | + message: pigeonVar_replyList[1] as String?, | ||
| 248 | + details: pigeonVar_replyList[2], | ||
| 249 | + ); | ||
| 250 | + } else if (pigeonVar_replyList[0] == null) { | ||
| 251 | + throw PlatformException( | ||
| 252 | + code: 'null-error', | ||
| 253 | + message: 'Host platform returned null value for non-null return value.', | ||
| 254 | + ); | ||
| 255 | + } else { | ||
| 256 | + return (pigeonVar_replyList[0] as bool?)!; | ||
| 257 | + } | ||
| 258 | + } | ||
| 259 | + | ||
| 231 | Future<bool> sendWatchSyncPayload(String jsonPayload) async { | 260 | Future<bool> sendWatchSyncPayload(String jsonPayload) async { |
| 232 | final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.sendWatchSyncPayload$pigeonVar_messageChannelSuffix'; | 261 | final String pigeonVar_channelName = 'dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.sendWatchSyncPayload$pigeonVar_messageChannelSuffix'; |
| 233 | final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>( | 262 | final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>( |
| @@ -38,6 +38,10 @@ abstract class WearEngineHostApi { | @@ -38,6 +38,10 @@ abstract class WearEngineHostApi { | ||
| 38 | 38 | ||
| 39 | bool sendTextMessage(String message); | 39 | bool sendTextMessage(String message); |
| 40 | 40 | ||
| 41 | + /// 添加表盘 | ||
| 42 | + @async | ||
| 43 | + bool addWatchSurface(); | ||
| 44 | + | ||
| 41 | @async | 45 | @async |
| 42 | bool sendWatchSyncPayload(String jsonPayload); | 46 | bool sendWatchSyncPayload(String jsonPayload); |
| 43 | 47 |
-
Please register or login to post a comment