Commit 13d89eb09f7f9d15872ac84a5e12b9587867a8fd

Authored by 权海
1 parent 89cbb899

feat(ui):更新手表检测api

@@ -83,7 +83,8 @@ class FlutterError ( @@ -83,7 +83,8 @@ class FlutterError (
83 data class WearDeviceInfo ( 83 data class WearDeviceInfo (
84 val deviceId: String? = null, 84 val deviceId: String? = null,
85 val deviceName: String? = null, 85 val deviceName: String? = null,
86 - val isConnected: Boolean? = null, 86 + val isPaired: Boolean? = null,
  87 + val isReachable: Boolean? = null,
87 val isWatchAppInstalled: Boolean? = null 88 val isWatchAppInstalled: Boolean? = null
88 ) 89 )
89 { 90 {
@@ -91,16 +92,18 @@ data class WearDeviceInfo ( @@ -91,16 +92,18 @@ data class WearDeviceInfo (
91 fun fromList(pigeonVar_list: List<Any?>): WearDeviceInfo { 92 fun fromList(pigeonVar_list: List<Any?>): WearDeviceInfo {
92 val deviceId = pigeonVar_list[0] as String? 93 val deviceId = pigeonVar_list[0] as String?
93 val deviceName = pigeonVar_list[1] as String? 94 val deviceName = pigeonVar_list[1] as String?
94 - val isConnected = pigeonVar_list[2] as Boolean?  
95 - val isWatchAppInstalled = pigeonVar_list[3] as Boolean?  
96 - return WearDeviceInfo(deviceId, deviceName, isConnected, isWatchAppInstalled) 95 + val isPaired = pigeonVar_list[2] as Boolean?
  96 + val isReachable = pigeonVar_list[3] as Boolean?
  97 + val isWatchAppInstalled = pigeonVar_list[4] as Boolean?
  98 + return WearDeviceInfo(deviceId, deviceName, isPaired, isReachable, isWatchAppInstalled)
97 } 99 }
98 } 100 }
99 fun toList(): List<Any?> { 101 fun toList(): List<Any?> {
100 return listOf( 102 return listOf(
101 deviceId, 103 deviceId,
102 deviceName, 104 deviceName,
103 - isConnected, 105 + isPaired,
  106 + isReachable,
104 isWatchAppInstalled, 107 isWatchAppInstalled,
105 ) 108 )
106 } 109 }
@@ -141,7 +144,7 @@ private open class WearEngineApiPigeonCodec : StandardMessageCodec() { @@ -141,7 +144,7 @@ private open class WearEngineApiPigeonCodec : StandardMessageCodec() {
141 /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ 144 /** Generated interface from Pigeon that represents a handler of messages from Flutter. */
142 interface WearEngineHostApi { 145 interface WearEngineHostApi {
143 fun hasAvailableDevices(): Boolean 146 fun hasAvailableDevices(): Boolean
144 - fun checkConnectedDevice(): WearDeviceInfo? 147 + fun checkConnectedDevice(callback: (Result<WearDeviceInfo?>) -> Unit)
145 fun registerMessageReceiver(): Boolean 148 fun registerMessageReceiver(): Boolean
146 fun sendTextMessage(message: String): Boolean 149 fun sendTextMessage(message: String): Boolean
147 /** 添加表盘 */ 150 /** 添加表盘 */
@@ -183,12 +186,15 @@ interface WearEngineHostApi { @@ -183,12 +186,15 @@ interface WearEngineHostApi {
183 val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.checkConnectedDevice$separatedMessageChannelSuffix", codec) 186 val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.checkConnectedDevice$separatedMessageChannelSuffix", codec)
184 if (api != null) { 187 if (api != null) {
185 channel.setMessageHandler { _, reply -> 188 channel.setMessageHandler { _, reply ->
186 - val wrapped: List<Any?> = try {  
187 - listOf(api.checkConnectedDevice())  
188 - } catch (exception: Throwable) {  
189 - WearEngineApiPigeonUtils.wrapError(exception) 189 + api.checkConnectedDevice{ result: Result<WearDeviceInfo?> ->
  190 + val error = result.exceptionOrNull()
  191 + if (error != null) {
  192 + reply.reply(WearEngineApiPigeonUtils.wrapError(error))
  193 + } else {
  194 + val data = result.getOrNull()
  195 + reply.reply(WearEngineApiPigeonUtils.wrapResult(data))
  196 + }
190 } 197 }
191 - reply.reply(wrapped)  
192 } 198 }
193 } else { 199 } else {
194 channel.setMessageHandler(null) 200 channel.setMessageHandler(null)
@@ -116,7 +116,8 @@ func deepHashWearEngineApi(value: Any?, hasher: inout Hasher) { @@ -116,7 +116,8 @@ func deepHashWearEngineApi(value: Any?, hasher: inout Hasher) {
116 struct WearDeviceInfo: Hashable { 116 struct WearDeviceInfo: Hashable {
117 var deviceId: String? = nil 117 var deviceId: String? = nil
118 var deviceName: String? = nil 118 var deviceName: String? = nil
119 - var isConnected: Bool? = nil 119 + var isPaired: Bool? = nil
  120 + var isReachable: Bool? = nil
120 var isWatchAppInstalled: Bool? = nil 121 var isWatchAppInstalled: Bool? = nil
121 122
122 123
@@ -124,13 +125,15 @@ struct WearDeviceInfo: Hashable { @@ -124,13 +125,15 @@ struct WearDeviceInfo: Hashable {
124 static func fromList(_ pigeonVar_list: [Any?]) -> WearDeviceInfo? { 125 static func fromList(_ pigeonVar_list: [Any?]) -> WearDeviceInfo? {
125 let deviceId: String? = nilOrValue(pigeonVar_list[0]) 126 let deviceId: String? = nilOrValue(pigeonVar_list[0])
126 let deviceName: String? = nilOrValue(pigeonVar_list[1]) 127 let deviceName: String? = nilOrValue(pigeonVar_list[1])
127 - let isConnected: Bool? = nilOrValue(pigeonVar_list[2])  
128 - let isWatchAppInstalled: Bool? = nilOrValue(pigeonVar_list[3]) 128 + let isPaired: Bool? = nilOrValue(pigeonVar_list[2])
  129 + let isReachable: Bool? = nilOrValue(pigeonVar_list[3])
  130 + let isWatchAppInstalled: Bool? = nilOrValue(pigeonVar_list[4])
129 131
130 return WearDeviceInfo( 132 return WearDeviceInfo(
131 deviceId: deviceId, 133 deviceId: deviceId,
132 deviceName: deviceName, 134 deviceName: deviceName,
133 - isConnected: isConnected, 135 + isPaired: isPaired,
  136 + isReachable: isReachable,
134 isWatchAppInstalled: isWatchAppInstalled 137 isWatchAppInstalled: isWatchAppInstalled
135 ) 138 )
136 } 139 }
@@ -138,7 +141,8 @@ struct WearDeviceInfo: Hashable { @@ -138,7 +141,8 @@ struct WearDeviceInfo: Hashable {
138 return [ 141 return [
139 deviceId, 142 deviceId,
140 deviceName, 143 deviceName,
141 - isConnected, 144 + isPaired,
  145 + isReachable,
142 isWatchAppInstalled, 146 isWatchAppInstalled,
143 ] 147 ]
144 } 148 }
@@ -189,7 +193,7 @@ class WearEngineApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable @@ -189,7 +193,7 @@ class WearEngineApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable
189 /// Generated protocol from Pigeon that represents a handler of messages from Flutter. 193 /// Generated protocol from Pigeon that represents a handler of messages from Flutter.
190 protocol WearEngineHostApi { 194 protocol WearEngineHostApi {
191 func hasAvailableDevices() throws -> Bool 195 func hasAvailableDevices() throws -> Bool
192 - func checkConnectedDevice() throws -> WearDeviceInfo? 196 + func checkConnectedDevice(completion: @escaping (Result<WearDeviceInfo?, Error>) -> Void)
193 func registerMessageReceiver() throws -> Bool 197 func registerMessageReceiver() throws -> Bool
194 func sendTextMessage(message: String) throws -> Bool 198 func sendTextMessage(message: String) throws -> Bool
195 /// 添加表盘 199 /// 添加表盘
@@ -224,11 +228,13 @@ class WearEngineHostApiSetup { @@ -224,11 +228,13 @@ class WearEngineHostApiSetup {
224 let checkConnectedDeviceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.checkConnectedDevice\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) 228 let checkConnectedDeviceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.WearEngineHostApi.checkConnectedDevice\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
225 if let api = api { 229 if let api = api {
226 checkConnectedDeviceChannel.setMessageHandler { _, reply in 230 checkConnectedDeviceChannel.setMessageHandler { _, reply in
227 - do {  
228 - let result = try api.checkConnectedDevice()  
229 - reply(wrapResult(result))  
230 - } catch {  
231 - reply(wrapError(error)) 231 + api.checkConnectedDevice { result in
  232 + switch result {
  233 + case .success(let res):
  234 + reply(wrapResult(res))
  235 + case .failure(let error):
  236 + reply(wrapError(error))
  237 + }
232 } 238 }
233 } 239 }
234 } else { 240 } else {
@@ -146,7 +146,9 @@ class CustomWatchThemePreviewController extends GetxController { @@ -146,7 +146,9 @@ class CustomWatchThemePreviewController extends GetxController {
146 } catch (_) { 146 } catch (_) {
147 device = null; 147 device = null;
148 } 148 }
149 - if (device?.isConnected != true || device?.isWatchAppInstalled != true) { 149 + if (device?.isPaired != true ||
  150 + device?.isReachable != true ||
  151 + device?.isWatchAppInstalled != true) {
150 await Get.dialog<void>( 152 await Get.dialog<void>(
151 const WatchThemeNoWatchDialog(), 153 const WatchThemeNoWatchDialog(),
152 barrierColor: const Color(0xB3000000), 154 barrierColor: const Color(0xB3000000),
@@ -168,7 +170,9 @@ class CustomWatchThemePreviewController extends GetxController { @@ -168,7 +170,9 @@ class CustomWatchThemePreviewController extends GetxController {
168 } catch (_) { 170 } catch (_) {
169 device = null; 171 device = null;
170 } 172 }
171 - if (device?.isConnected != true || device?.isWatchAppInstalled != true) { 173 + if (device?.isPaired != true ||
  174 + device?.isReachable != true ||
  175 + device?.isWatchAppInstalled != true) {
172 await Get.dialog<void>( 176 await Get.dialog<void>(
173 const WatchThemeNoWatchDialog(), 177 const WatchThemeNoWatchDialog(),
174 barrierColor: const Color(0xB3000000), 178 barrierColor: const Color(0xB3000000),
@@ -117,7 +117,9 @@ class WatchThemePreviewController extends GetxController { @@ -117,7 +117,9 @@ class WatchThemePreviewController extends GetxController {
117 } catch (_) { 117 } catch (_) {
118 device = null; 118 device = null;
119 } 119 }
120 - if (device?.isConnected != true || device?.isWatchAppInstalled != true) { 120 + if (device?.isPaired != true ||
  121 + device?.isReachable != true ||
  122 + device?.isWatchAppInstalled != true) {
121 await Get.dialog<void>( 123 await Get.dialog<void>(
122 const WatchThemeNoWatchDialog(), 124 const WatchThemeNoWatchDialog(),
123 barrierColor: const Color(0xB3000000), 125 barrierColor: const Color(0xB3000000),
@@ -140,7 +142,9 @@ class WatchThemePreviewController extends GetxController { @@ -140,7 +142,9 @@ class WatchThemePreviewController extends GetxController {
140 } catch (_) { 142 } catch (_) {
141 device = null; 143 device = null;
142 } 144 }
143 - if (device?.isConnected != true || device?.isWatchAppInstalled != true) { 145 + if (device?.isPaired != true ||
  146 + device?.isReachable != true ||
  147 + device?.isWatchAppInstalled != true) {
144 await Get.dialog<void>( 148 await Get.dialog<void>(
145 const WatchThemeNoWatchDialog(), 149 const WatchThemeNoWatchDialog(),
146 barrierColor: const Color(0xB3000000), 150 barrierColor: const Color(0xB3000000),
@@ -34,7 +34,8 @@ class WearDeviceInfo { @@ -34,7 +34,8 @@ class WearDeviceInfo {
34 WearDeviceInfo({ 34 WearDeviceInfo({
35 this.deviceId, 35 this.deviceId,
36 this.deviceName, 36 this.deviceName,
37 - this.isConnected, 37 + this.isPaired,
  38 + this.isReachable,
38 this.isWatchAppInstalled, 39 this.isWatchAppInstalled,
39 }); 40 });
40 41
@@ -42,7 +43,9 @@ class WearDeviceInfo { @@ -42,7 +43,9 @@ class WearDeviceInfo {
42 43
43 String? deviceName; 44 String? deviceName;
44 45
45 - bool? isConnected; 46 + bool? isPaired;
  47 +
  48 + bool? isReachable;
46 49
47 bool? isWatchAppInstalled; 50 bool? isWatchAppInstalled;
48 51
@@ -50,7 +53,8 @@ class WearDeviceInfo { @@ -50,7 +53,8 @@ class WearDeviceInfo {
50 return <Object?>[ 53 return <Object?>[
51 deviceId, 54 deviceId,
52 deviceName, 55 deviceName,
53 - isConnected, 56 + isPaired,
  57 + isReachable,
54 isWatchAppInstalled, 58 isWatchAppInstalled,
55 ]; 59 ];
56 } 60 }
@@ -63,8 +67,9 @@ class WearDeviceInfo { @@ -63,8 +67,9 @@ class WearDeviceInfo {
63 return WearDeviceInfo( 67 return WearDeviceInfo(
64 deviceId: result[0] as String?, 68 deviceId: result[0] as String?,
65 deviceName: result[1] as String?, 69 deviceName: result[1] as String?,
66 - isConnected: result[2] as bool?,  
67 - isWatchAppInstalled: result[3] as bool?, 70 + isPaired: result[2] as bool?,
  71 + isReachable: result[3] as bool?,
  72 + isWatchAppInstalled: result[4] as bool?,
68 ); 73 );
69 } 74 }
70 75
@@ -4,13 +4,15 @@ class WearDeviceInfo { @@ -4,13 +4,15 @@ class WearDeviceInfo {
4 WearDeviceInfo({ 4 WearDeviceInfo({
5 this.deviceId, 5 this.deviceId,
6 this.deviceName, 6 this.deviceName,
7 - this.isConnected, 7 + this.isPaired,
  8 + this.isReachable,
8 this.isWatchAppInstalled, 9 this.isWatchAppInstalled,
9 }); 10 });
10 11
11 String? deviceId; 12 String? deviceId;
12 String? deviceName; 13 String? deviceName;
13 - bool? isConnected; 14 + bool? isPaired;
  15 + bool? isReachable;
14 bool? isWatchAppInstalled; 16 bool? isWatchAppInstalled;
15 } 17 }
16 18
@@ -34,6 +36,7 @@ class WearDeviceInfo { @@ -34,6 +36,7 @@ class WearDeviceInfo {
34 abstract class WearEngineHostApi { 36 abstract class WearEngineHostApi {
35 bool hasAvailableDevices(); 37 bool hasAvailableDevices();
36 38
  39 + @async
37 WearDeviceInfo? checkConnectedDevice(); 40 WearDeviceInfo? checkConnectedDevice();
38 41
39 bool registerMessageReceiver(); 42 bool registerMessageReceiver();