HealthKitApi.swift
8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// // Copyright 2013 The Flutter Authors. All rights reserved.
// Autogenerated from Pigeon (v25.5.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
import Foundation
#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#else
#error("Unsupported platform.")
#endif
private func wrapResult(_ result: Any?) -> [Any?] {
return [result]
}
private func wrapError(_ error: Any) -> [Any?] {
if let pigeonError = error as? PigeonError {
return [
pigeonError.code,
pigeonError.message,
pigeonError.details,
]
}
if let flutterError = error as? FlutterError {
return [
flutterError.code,
flutterError.message,
flutterError.details,
]
}
return [
"\(error)",
"\(type(of: error))",
"Stacktrace: \(Thread.callStackSymbols)",
]
}
private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
}
private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return value as! T?
}
func deepEqualsHealthKitApi(_ lhs: Any?, _ rhs: Any?) -> Bool {
let cleanLhs = nilOrValue(lhs) as Any?
let cleanRhs = nilOrValue(rhs) as Any?
switch (cleanLhs, cleanRhs) {
case (nil, nil):
return true
case (nil, _), (_, nil):
return false
case is (Void, Void):
return true
case let (cleanLhsHashable, cleanRhsHashable) as (AnyHashable, AnyHashable):
return cleanLhsHashable == cleanRhsHashable
case let (cleanLhsArray, cleanRhsArray) as ([Any?], [Any?]):
guard cleanLhsArray.count == cleanRhsArray.count else { return false }
for (index, element) in cleanLhsArray.enumerated() {
if !deepEqualsHealthKitApi(element, cleanRhsArray[index]) {
return false
}
}
return true
case let (cleanLhsDictionary, cleanRhsDictionary) as ([AnyHashable: Any?], [AnyHashable: Any?]):
guard cleanLhsDictionary.count == cleanRhsDictionary.count else { return false }
for (key, cleanLhsValue) in cleanLhsDictionary {
guard cleanRhsDictionary.index(forKey: key) != nil else { return false }
if !deepEqualsHealthKitApi(cleanLhsValue, cleanRhsDictionary[key]!) {
return false
}
}
return true
default:
// Any other type shouldn't be able to be used with pigeon. File an issue if you find this to be untrue.
return false
}
}
func deepHashHealthKitApi(value: Any?, hasher: inout Hasher) {
if let valueList = value as? [AnyHashable] {
for item in valueList { deepHashHealthKitApi(value: item, hasher: &hasher) }
return
}
if let valueDict = value as? [AnyHashable: AnyHashable] {
for key in valueDict.keys {
hasher.combine(key)
deepHashHealthKitApi(value: valueDict[key]!, hasher: &hasher)
}
return
}
if let hashableValue = value as? AnyHashable {
hasher.combine(hashableValue.hashValue)
}
return hasher.combine(String(describing: value))
}
/// Generated class from Pigeon that represents data sent in messages.
struct HealthUploadResult: Hashable {
var commonUploadSuccess: Bool
var sleepUploadSuccess: Bool
var errorMessage: String? = nil
// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> HealthUploadResult? {
let commonUploadSuccess = pigeonVar_list[0] as! Bool
let sleepUploadSuccess = pigeonVar_list[1] as! Bool
let errorMessage: String? = nilOrValue(pigeonVar_list[2])
return HealthUploadResult(
commonUploadSuccess: commonUploadSuccess,
sleepUploadSuccess: sleepUploadSuccess,
errorMessage: errorMessage
)
}
func toList() -> [Any?] {
return [
commonUploadSuccess,
sleepUploadSuccess,
errorMessage,
]
}
static func == (lhs: HealthUploadResult, rhs: HealthUploadResult) -> Bool {
return deepEqualsHealthKitApi(lhs.toList(), rhs.toList()) }
func hash(into hasher: inout Hasher) {
deepHashHealthKitApi(value: toList(), hasher: &hasher)
}
}
private class HealthKitApiPigeonCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 129:
return HealthUploadResult.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
}
}
private class HealthKitApiPigeonCodecWriter: FlutterStandardWriter {
override func writeValue(_ value: Any) {
if let value = value as? HealthUploadResult {
super.writeByte(129)
super.writeValue(value.toList())
} else {
super.writeValue(value)
}
}
}
private class HealthKitApiPigeonCodecReaderWriter: FlutterStandardReaderWriter {
override func reader(with data: Data) -> FlutterStandardReader {
return HealthKitApiPigeonCodecReader(data: data)
}
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
return HealthKitApiPigeonCodecWriter(data: data)
}
}
class HealthKitApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = HealthKitApiPigeonCodec(readerWriter: HealthKitApiPigeonCodecReaderWriter())
}
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol HealthKitHostApi {
func checkHealthAppAuthorization() throws -> Bool
func getHealthServerAuthUrl() throws -> String
/// Opens Huawei Health client authorization UI. Returns whether user granted.
func requestHealthClientAuthorization() throws -> Bool
func cancelHealthAppAuthorization() throws -> Bool
/// Runs native health read and server upload pipeline.
func performHealthUpload() throws -> HealthUploadResult
}
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class HealthKitHostApiSetup {
static var codec: FlutterStandardMessageCodec { HealthKitApiPigeonCodec.shared }
/// Sets up an instance of `HealthKitHostApi` to handle messages through the `binaryMessenger`.
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: HealthKitHostApi?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let checkHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.checkHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
checkHealthAppAuthorizationChannel.setMessageHandler { _, reply in
do {
let result = try api.checkHealthAppAuthorization()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
checkHealthAppAuthorizationChannel.setMessageHandler(nil)
}
let getHealthServerAuthUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.getHealthServerAuthUrl\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getHealthServerAuthUrlChannel.setMessageHandler { _, reply in
do {
let result = try api.getHealthServerAuthUrl()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getHealthServerAuthUrlChannel.setMessageHandler(nil)
}
/// Opens Huawei Health client authorization UI. Returns whether user granted.
let requestHealthClientAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.requestHealthClientAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
requestHealthClientAuthorizationChannel.setMessageHandler { _, reply in
do {
let result = try api.requestHealthClientAuthorization()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
requestHealthClientAuthorizationChannel.setMessageHandler(nil)
}
let cancelHealthAppAuthorizationChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.cancelHealthAppAuthorization\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
cancelHealthAppAuthorizationChannel.setMessageHandler { _, reply in
do {
let result = try api.cancelHealthAppAuthorization()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
cancelHealthAppAuthorizationChannel.setMessageHandler(nil)
}
/// Runs native health read and server upload pipeline.
let performHealthUploadChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.performHealthUpload\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
performHealthUploadChannel.setMessageHandler { _, reply in
do {
let result = try api.performHealthUpload()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
performHealthUploadChannel.setMessageHandler(nil)
}
}
}