Showing
4 changed files
with
21 additions
and
14 deletions
| @@ -141,7 +141,7 @@ interface WearEngineHostApi { | @@ -141,7 +141,7 @@ 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 | - fun sendWatchSyncPayload(jsonPayload: String): Boolean | 144 | + fun sendWatchSyncPayload(jsonPayload: String, callback: (Result<Boolean>) -> Unit) |
| 145 | /** | 145 | /** |
| 146 | * Opens the system photo picker and returns a local PNG file path after | 146 | * Opens the system photo picker and returns a local PNG file path after |
| 147 | * removing the image background on the host platform. | 147 | * removing the image background on the host platform. |
| @@ -227,12 +227,15 @@ interface WearEngineHostApi { | @@ -227,12 +227,15 @@ interface WearEngineHostApi { | ||
| 227 | channel.setMessageHandler { message, reply -> | 227 | channel.setMessageHandler { message, reply -> |
| 228 | val args = message as List<Any?> | 228 | val args = message as List<Any?> |
| 229 | val jsonPayloadArg = args[0] as String | 229 | val jsonPayloadArg = args[0] as String |
| 230 | - val wrapped: List<Any?> = try { | ||
| 231 | - listOf(api.sendWatchSyncPayload(jsonPayloadArg)) | ||
| 232 | - } catch (exception: Throwable) { | ||
| 233 | - WearEngineApiPigeonUtils.wrapError(exception) | 230 | + api.sendWatchSyncPayload(jsonPayloadArg) { 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 | + } | ||
| 234 | } | 238 | } |
| 235 | - reply.reply(wrapped) | ||
| 236 | } | 239 | } |
| 237 | } else { | 240 | } else { |
| 238 | channel.setMessageHandler(null) | 241 | channel.setMessageHandler(null) |
| @@ -188,7 +188,7 @@ protocol WearEngineHostApi { | @@ -188,7 +188,7 @@ 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 | - func sendWatchSyncPayload(jsonPayload: String) throws -> Bool | 191 | + func sendWatchSyncPayload(jsonPayload: String, completion: @escaping (Result<Bool, Error>) -> Void) |
| 192 | /// Opens the system photo picker and returns a local PNG file path after | 192 | /// Opens the system photo picker and returns a local PNG file path after |
| 193 | /// removing the image background on the host platform. | 193 | /// removing the image background on the host platform. |
| 194 | func removeBackground(originImagePath: String, completion: @escaping (Result<String?, Error>) -> Void) | 194 | func removeBackground(originImagePath: String, completion: @escaping (Result<String?, Error>) -> Void) |
| @@ -261,11 +261,13 @@ class WearEngineHostApiSetup { | @@ -261,11 +261,13 @@ class WearEngineHostApiSetup { | ||
| 261 | sendWatchSyncPayloadChannel.setMessageHandler { message, reply in | 261 | sendWatchSyncPayloadChannel.setMessageHandler { message, reply in |
| 262 | let args = message as! [Any?] | 262 | let args = message as! [Any?] |
| 263 | let jsonPayloadArg = args[0] as! String | 263 | let jsonPayloadArg = args[0] as! String |
| 264 | - do { | ||
| 265 | - let result = try api.sendWatchSyncPayload(jsonPayload: jsonPayloadArg) | ||
| 266 | - reply(wrapResult(result)) | ||
| 267 | - } catch { | ||
| 268 | - reply(wrapError(error)) | 264 | + api.sendWatchSyncPayload(jsonPayload: jsonPayloadArg) { result in |
| 265 | + switch result { | ||
| 266 | + case .success(let res): | ||
| 267 | + reply(wrapResult(res)) | ||
| 268 | + case .failure(let error): | ||
| 269 | + reply(wrapError(error)) | ||
| 270 | + } | ||
| 269 | } | 271 | } |
| 270 | } | 272 | } |
| 271 | } else { | 273 | } else { |
| @@ -36,8 +36,9 @@ final class WearEngineHostApiImpl: WearEngineHostApi { | @@ -36,8 +36,9 @@ final class WearEngineHostApiImpl: WearEngineHostApi { | ||
| 36 | watchService.sendTextMessage(message) | 36 | watchService.sendTextMessage(message) |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | - func sendWatchSyncPayload(jsonPayload: String) throws -> Bool { | ||
| 40 | - WatchConnectivityService.shared.sendWatchThemeChangedMessage(json: jsonPayload) | 39 | + func sendWatchSyncPayload(jsonPayload: String, completion: @escaping (Result<Bool, any Error>) -> Void) { |
| 40 | + let success = WatchConnectivityService.shared.sendWatchThemeChangedMessage(json: jsonPayload) | ||
| 41 | + completion(.success(success)) | ||
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | func removeBackground(originImagePath: String, completion: @escaping (Result<String?, any Error>) -> Void) { | 44 | func removeBackground(originImagePath: String, completion: @escaping (Result<String?, any Error>) -> Void) { |
| @@ -38,6 +38,7 @@ abstract class WearEngineHostApi { | @@ -38,6 +38,7 @@ abstract class WearEngineHostApi { | ||
| 38 | 38 | ||
| 39 | bool sendTextMessage(String message); | 39 | bool sendTextMessage(String message); |
| 40 | 40 | ||
| 41 | + @async | ||
| 41 | bool sendWatchSyncPayload(String jsonPayload); | 42 | bool sendWatchSyncPayload(String jsonPayload); |
| 42 | 43 | ||
| 43 | /// Opens the system photo picker and returns a local PNG file path after | 44 | /// Opens the system photo picker and returns a local PNG file path after |
-
Please register or login to post a comment