mirror of
https://github.com/immich-app/immich.git
synced 2026-05-25 00:52:31 -04:00
ef80a8e936
- add ViewIntent Pigeon API and generated bindings - implement Android ViewIntentPlugin + iOS no-op host - route ExternalMediaViewer by ViewIntentAttachment - buffer pending view intents and flush on user ready/resume
229 lines
6.6 KiB
Swift
229 lines
6.6 KiB
Swift
// Autogenerated from Pigeon (v26.0.2), 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 deepEqualsViewIntent(_ 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 !deepEqualsViewIntent(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 !deepEqualsViewIntent(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 deepHashViewIntent(value: Any?, hasher: inout Hasher) {
|
|
if let valueList = value as? [AnyHashable] {
|
|
for item in valueList { deepHashViewIntent(value: item, hasher: &hasher) }
|
|
return
|
|
}
|
|
|
|
if let valueDict = value as? [AnyHashable: AnyHashable] {
|
|
for key in valueDict.keys {
|
|
hasher.combine(key)
|
|
deepHashViewIntent(value: valueDict[key]!, hasher: &hasher)
|
|
}
|
|
return
|
|
}
|
|
|
|
if let hashableValue = value as? AnyHashable {
|
|
hasher.combine(hashableValue.hashValue)
|
|
}
|
|
|
|
return hasher.combine(String(describing: value))
|
|
}
|
|
|
|
|
|
|
|
enum ViewIntentType: Int {
|
|
case image = 0
|
|
case video = 1
|
|
}
|
|
|
|
/// Generated class from Pigeon that represents data sent in messages.
|
|
struct ViewIntentPayload: Hashable {
|
|
var path: String
|
|
var type: ViewIntentType
|
|
var mimeType: String
|
|
var localAssetId: String? = nil
|
|
|
|
|
|
// swift-format-ignore: AlwaysUseLowerCamelCase
|
|
static func fromList(_ pigeonVar_list: [Any?]) -> ViewIntentPayload? {
|
|
let path = pigeonVar_list[0] as! String
|
|
let type = pigeonVar_list[1] as! ViewIntentType
|
|
let mimeType = pigeonVar_list[2] as! String
|
|
let localAssetId: String? = nilOrValue(pigeonVar_list[3])
|
|
|
|
return ViewIntentPayload(
|
|
path: path,
|
|
type: type,
|
|
mimeType: mimeType,
|
|
localAssetId: localAssetId
|
|
)
|
|
}
|
|
func toList() -> [Any?] {
|
|
return [
|
|
path,
|
|
type,
|
|
mimeType,
|
|
localAssetId,
|
|
]
|
|
}
|
|
static func == (lhs: ViewIntentPayload, rhs: ViewIntentPayload) -> Bool {
|
|
return deepEqualsViewIntent(lhs.toList(), rhs.toList()) }
|
|
func hash(into hasher: inout Hasher) {
|
|
deepHashViewIntent(value: toList(), hasher: &hasher)
|
|
}
|
|
}
|
|
|
|
private class ViewIntentPigeonCodecReader: FlutterStandardReader {
|
|
override func readValue(ofType type: UInt8) -> Any? {
|
|
switch type {
|
|
case 129:
|
|
let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?)
|
|
if let enumResultAsInt = enumResultAsInt {
|
|
return ViewIntentType(rawValue: enumResultAsInt)
|
|
}
|
|
return nil
|
|
case 130:
|
|
return ViewIntentPayload.fromList(self.readValue() as! [Any?])
|
|
default:
|
|
return super.readValue(ofType: type)
|
|
}
|
|
}
|
|
}
|
|
|
|
private class ViewIntentPigeonCodecWriter: FlutterStandardWriter {
|
|
override func writeValue(_ value: Any) {
|
|
if let value = value as? ViewIntentType {
|
|
super.writeByte(129)
|
|
super.writeValue(value.rawValue)
|
|
} else if let value = value as? ViewIntentPayload {
|
|
super.writeByte(130)
|
|
super.writeValue(value.toList())
|
|
} else {
|
|
super.writeValue(value)
|
|
}
|
|
}
|
|
}
|
|
|
|
private class ViewIntentPigeonCodecReaderWriter: FlutterStandardReaderWriter {
|
|
override func reader(with data: Data) -> FlutterStandardReader {
|
|
return ViewIntentPigeonCodecReader(data: data)
|
|
}
|
|
|
|
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
|
|
return ViewIntentPigeonCodecWriter(data: data)
|
|
}
|
|
}
|
|
|
|
class ViewIntentPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
|
|
static let shared = ViewIntentPigeonCodec(readerWriter: ViewIntentPigeonCodecReaderWriter())
|
|
}
|
|
|
|
|
|
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
|
|
protocol ViewIntentHostApi {
|
|
func consumeViewIntent(completion: @escaping (Result<ViewIntentPayload?, Error>) -> Void)
|
|
}
|
|
|
|
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
|
|
class ViewIntentHostApiSetup {
|
|
static var codec: FlutterStandardMessageCodec { ViewIntentPigeonCodec.shared }
|
|
/// Sets up an instance of `ViewIntentHostApi` to handle messages through the `binaryMessenger`.
|
|
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: ViewIntentHostApi?, messageChannelSuffix: String = "") {
|
|
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
|
|
let consumeViewIntentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.ViewIntentHostApi.consumeViewIntent\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
|
if let api = api {
|
|
consumeViewIntentChannel.setMessageHandler { _, reply in
|
|
api.consumeViewIntent { result in
|
|
switch result {
|
|
case .success(let res):
|
|
reply(wrapResult(res))
|
|
case .failure(let error):
|
|
reply(wrapError(error))
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
consumeViewIntentChannel.setMessageHandler(nil)
|
|
}
|
|
}
|
|
}
|