| // Copyright 2013 The Flutter Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // Autogenerated from Pigeon (v9.2.4), do not edit directly. |
| // See also: https://pub.dev/packages/pigeon |
| |
| #import "messages.g.h" |
| #import <Flutter/Flutter.h> |
| |
| #if !__has_feature(objc_arc) |
| #error File requires ARC to be enabled. |
| #endif |
| |
| static NSArray *wrapResult(id result, FlutterError *error) { |
| if (error) { |
| return @[ |
| error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] |
| ]; |
| } |
| return @[ result ?: [NSNull null] ]; |
| } |
| static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { |
| id result = array[key]; |
| return (result == [NSNull null]) ? nil : result; |
| } |
| |
| @interface FFSFileSelectorConfig () |
| + (FFSFileSelectorConfig *)fromList:(NSArray *)list; |
| + (nullable FFSFileSelectorConfig *)nullableFromList:(NSArray *)list; |
| - (NSArray *)toList; |
| @end |
| |
| @implementation FFSFileSelectorConfig |
| + (instancetype)makeWithUtis:(NSArray<NSString *> *)utis |
| allowMultiSelection:(NSNumber *)allowMultiSelection { |
| FFSFileSelectorConfig *pigeonResult = [[FFSFileSelectorConfig alloc] init]; |
| pigeonResult.utis = utis; |
| pigeonResult.allowMultiSelection = allowMultiSelection; |
| return pigeonResult; |
| } |
| + (FFSFileSelectorConfig *)fromList:(NSArray *)list { |
| FFSFileSelectorConfig *pigeonResult = [[FFSFileSelectorConfig alloc] init]; |
| pigeonResult.utis = GetNullableObjectAtIndex(list, 0); |
| NSAssert(pigeonResult.utis != nil, @""); |
| pigeonResult.allowMultiSelection = GetNullableObjectAtIndex(list, 1); |
| NSAssert(pigeonResult.allowMultiSelection != nil, @""); |
| return pigeonResult; |
| } |
| + (nullable FFSFileSelectorConfig *)nullableFromList:(NSArray *)list { |
| return (list) ? [FFSFileSelectorConfig fromList:list] : nil; |
| } |
| - (NSArray *)toList { |
| return @[ |
| (self.utis ?: [NSNull null]), |
| (self.allowMultiSelection ?: [NSNull null]), |
| ]; |
| } |
| @end |
| |
| @interface FFSFileSelectorApiCodecReader : FlutterStandardReader |
| @end |
| @implementation FFSFileSelectorApiCodecReader |
| - (nullable id)readValueOfType:(UInt8)type { |
| switch (type) { |
| case 128: |
| return [FFSFileSelectorConfig fromList:[self readValue]]; |
| default: |
| return [super readValueOfType:type]; |
| } |
| } |
| @end |
| |
| @interface FFSFileSelectorApiCodecWriter : FlutterStandardWriter |
| @end |
| @implementation FFSFileSelectorApiCodecWriter |
| - (void)writeValue:(id)value { |
| if ([value isKindOfClass:[FFSFileSelectorConfig class]]) { |
| [self writeByte:128]; |
| [self writeValue:[value toList]]; |
| } else { |
| [super writeValue:value]; |
| } |
| } |
| @end |
| |
| @interface FFSFileSelectorApiCodecReaderWriter : FlutterStandardReaderWriter |
| @end |
| @implementation FFSFileSelectorApiCodecReaderWriter |
| - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { |
| return [[FFSFileSelectorApiCodecWriter alloc] initWithData:data]; |
| } |
| - (FlutterStandardReader *)readerWithData:(NSData *)data { |
| return [[FFSFileSelectorApiCodecReader alloc] initWithData:data]; |
| } |
| @end |
| |
| NSObject<FlutterMessageCodec> *FFSFileSelectorApiGetCodec(void) { |
| static FlutterStandardMessageCodec *sSharedObject = nil; |
| static dispatch_once_t sPred = 0; |
| dispatch_once(&sPred, ^{ |
| FFSFileSelectorApiCodecReaderWriter *readerWriter = |
| [[FFSFileSelectorApiCodecReaderWriter alloc] init]; |
| sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; |
| }); |
| return sSharedObject; |
| } |
| |
| void FFSFileSelectorApiSetup(id<FlutterBinaryMessenger> binaryMessenger, |
| NSObject<FFSFileSelectorApi> *api) { |
| { |
| FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] |
| initWithName:@"dev.flutter.pigeon.FileSelectorApi.openFile" |
| binaryMessenger:binaryMessenger |
| codec:FFSFileSelectorApiGetCodec()]; |
| if (api) { |
| NSCAssert([api respondsToSelector:@selector(openFileSelectorWithConfig:completion:)], |
| @"FFSFileSelectorApi api (%@) doesn't respond to " |
| @"@selector(openFileSelectorWithConfig:completion:)", |
| api); |
| [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { |
| NSArray *args = message; |
| FFSFileSelectorConfig *arg_config = GetNullableObjectAtIndex(args, 0); |
| [api openFileSelectorWithConfig:arg_config |
| completion:^(NSArray<NSString *> *_Nullable output, |
| FlutterError *_Nullable error) { |
| callback(wrapResult(output, error)); |
| }]; |
| }]; |
| } else { |
| [channel setMessageHandler:nil]; |
| } |
| } |
| } |